cisco_node_utils 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +81 -1
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.md +72 -6
  6. data/CONTRIBUTING.md +32 -7
  7. data/README.md +70 -7
  8. data/Rakefile +17 -0
  9. data/bin/check_metric_limits.rb +109 -0
  10. data/bin/git/hooks/commit-msg/enforce_style +81 -0
  11. data/bin/git/hooks/hook_lib +108 -0
  12. data/bin/git/hooks/hooks-wrapper +38 -0
  13. data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
  14. data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
  15. data/bin/git/hooks/post-flow-release-start/update-version +19 -0
  16. data/bin/git/hooks/post-merge/update-hooks +6 -0
  17. data/bin/git/hooks/post-rewrite/update-hooks +6 -0
  18. data/bin/git/hooks/pre-commit/rubocop +20 -0
  19. data/bin/git/hooks/pre-commit/validate-diffs +31 -0
  20. data/bin/git/hooks/pre-push/check-changelog +24 -0
  21. data/bin/git/hooks/pre-push/rubocop +7 -0
  22. data/bin/git/update-hooks +65 -0
  23. data/cisco_node_utils.gemspec +9 -3
  24. data/docs/README-develop-best-practices.md +404 -0
  25. data/docs/README-develop-node-utils-APIs.md +215 -365
  26. data/docs/README-maintainers.md +33 -3
  27. data/docs/template-router.rb +89 -91
  28. data/docs/template-test_router.rb +52 -55
  29. data/lib/.rubocop.yml +18 -0
  30. data/lib/cisco_node_utils.rb +2 -19
  31. data/lib/cisco_node_utils/README_YAML.md +1 -9
  32. data/lib/cisco_node_utils/bgp.rb +664 -0
  33. data/lib/cisco_node_utils/bgp_af.rb +530 -0
  34. data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
  35. data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
  36. data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
  37. data/lib/cisco_node_utils/command_reference.rb +72 -74
  38. data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
  39. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
  40. data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
  41. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
  42. data/lib/cisco_node_utils/configparser_lib.rb +152 -147
  43. data/lib/cisco_node_utils/dns_domain.rb +79 -0
  44. data/lib/cisco_node_utils/domain_name.rb +71 -0
  45. data/lib/cisco_node_utils/interface.rb +167 -161
  46. data/lib/cisco_node_utils/interface_ospf.rb +78 -81
  47. data/lib/cisco_node_utils/name_server.rb +64 -0
  48. data/lib/cisco_node_utils/node.rb +154 -198
  49. data/lib/cisco_node_utils/node_util.rb +61 -0
  50. data/lib/cisco_node_utils/ntp_config.rb +65 -0
  51. data/lib/cisco_node_utils/ntp_server.rb +76 -0
  52. data/lib/cisco_node_utils/platform.rb +174 -165
  53. data/lib/cisco_node_utils/radius_global.rb +146 -0
  54. data/lib/cisco_node_utils/radius_server.rb +295 -0
  55. data/lib/cisco_node_utils/router_ospf.rb +59 -63
  56. data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
  57. data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
  58. data/lib/cisco_node_utils/snmpgroup.rb +22 -23
  59. data/lib/cisco_node_utils/snmpserver.rb +99 -103
  60. data/lib/cisco_node_utils/snmpuser.rb +294 -274
  61. data/lib/cisco_node_utils/syslog_server.rb +92 -0
  62. data/lib/cisco_node_utils/syslog_settings.rb +69 -0
  63. data/lib/cisco_node_utils/tacacs_server.rb +137 -133
  64. data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
  65. data/lib/cisco_node_utils/version.rb +2 -1
  66. data/lib/cisco_node_utils/vlan.rb +28 -31
  67. data/lib/cisco_node_utils/vrf.rb +80 -0
  68. data/lib/cisco_node_utils/vtp.rb +100 -97
  69. data/lib/cisco_node_utils/yum.rb +15 -17
  70. data/tests/.rubocop.yml +15 -0
  71. data/tests/basetest.rb +81 -36
  72. data/tests/ciscotest.rb +38 -78
  73. data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
  74. data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
  75. data/tests/test_bgp_af.rb +920 -0
  76. data/tests/test_bgp_neighbor.rb +403 -0
  77. data/tests/test_bgp_neighbor_af.rb +589 -0
  78. data/tests/test_command_config.rb +65 -62
  79. data/tests/test_command_reference.rb +31 -45
  80. data/tests/test_dns_domain.rb +113 -0
  81. data/tests/test_domain_name.rb +86 -0
  82. data/tests/test_interface.rb +424 -548
  83. data/tests/test_interface_ospf.rb +248 -432
  84. data/tests/test_interface_svi.rb +56 -79
  85. data/tests/test_interface_switchport.rb +196 -272
  86. data/tests/test_name_server.rb +85 -0
  87. data/tests/test_node.rb +7 -6
  88. data/tests/test_node_ext.rb +133 -186
  89. data/tests/test_ntp_config.rb +49 -0
  90. data/tests/test_ntp_server.rb +74 -0
  91. data/tests/test_platform.rb +58 -37
  92. data/tests/test_radius_global.rb +78 -0
  93. data/tests/test_radius_server.rb +185 -0
  94. data/tests/test_router_bgp.rb +838 -0
  95. data/tests/test_router_ospf.rb +49 -80
  96. data/tests/test_router_ospf_vrf.rb +274 -392
  97. data/tests/test_snmpcommunity.rb +128 -172
  98. data/tests/test_snmpgroup.rb +12 -14
  99. data/tests/test_snmpserver.rb +160 -189
  100. data/tests/test_snmpuser.rb +568 -717
  101. data/tests/test_syslog_server.rb +88 -0
  102. data/tests/test_syslog_settings.rb +54 -0
  103. data/tests/test_tacacs_server.rb +113 -148
  104. data/tests/test_tacacs_server_host.rb +108 -161
  105. data/tests/test_vlan.rb +63 -79
  106. data/tests/test_vrf.rb +92 -0
  107. data/tests/test_vtp.rb +108 -126
  108. data/tests/test_yum.rb +47 -41
  109. metadata +92 -56
  110. data/.rubocop_todo.yml +0 -293
  111. data/docs/.rubocop.yml +0 -13
  112. data/docs/template-feature.rb +0 -45
  113. data/docs/template-test_feature.rb +0 -51
  114. data/tests/test_all_cisco.rb +0 -46
@@ -40,6 +40,10 @@ show_version:
40
40
  description:
41
41
  test_config_get_regex: !ruby/regexp '/.*Hardware\n cisco (\w+ \w+ \(\w+ \w+\) \w+).*/'
42
42
 
43
+ system_image:
44
+ # TODO: not sure if this is needed
45
+ config_get_token: "isan_file_name"
46
+ test_config_get_regex: !ruby/regexp '/.*system image file is: (.*)$.*/'
43
47
 
44
48
  vtp:
45
49
  version:
@@ -10,15 +10,6 @@ inventory:
10
10
  inventory:
11
11
  test_config_get_regex: [!ruby/regexp '/.*\nNAME: "(.+)",\s+DESCR: "(.+)"\s+\nPID: (\S+)\s+,\s+VID: (.+) ,\s+SN: (.+)\s+\n/', !ruby/regexp '/.*NAME: "(.+)",\s+DESCR: "(.+)"\s+PID: (\S+)\s+,\s+VID: (.+) ,\s+SN: (.+)\s+\n/']
12
12
 
13
-
14
- show_version:
15
- boot_image:
16
- test_config_get_regex: !ruby/regexp '/.*NXOS image file is: (.*)$.*/'
17
-
18
- system_image:
19
- config_get_token: "kick_file_name"
20
- test_config_get_regex: !ruby/regexp '/.*NXOS image file is: (.*)$.*/'
21
-
22
13
  snmp_user:
23
14
  auth_protocol:
24
15
  config_get_token: "auth"
@@ -29,168 +29,173 @@
29
29
  # y b | y a | trans match)
30
30
 
31
31
  module Cisco
32
- module ConfigParser
33
- class Configuration
34
- attr_accessor :configuration
32
+ module ConfigParser
33
+ # Configuration class - helper for dealing with config CLI
34
+ class Configuration
35
+ attr_accessor :configuration
35
36
 
36
- # Constructor for Configuration
37
- #
38
- # @raise [ArgumentError] if config_str is not a String
39
- # @param config_str [String] to parse
40
- def initialize(config_str)
41
- raise ArgumentError, "Argument is not a String." unless config_str.kind_of? String
37
+ # Constructor for Configuration
38
+ #
39
+ # @raise [ArgumentError] if config_str is not a String
40
+ # @param config_str [String] to parse
41
+ def initialize(config_str)
42
+ unless config_str.kind_of? String
43
+ fail ArgumentError, 'Argument is not a String.'
44
+ end
42
45
 
43
- @configuration = {}
44
- @ordered_keys = []
45
- @indent = ""
46
- parse(config_str)
47
- end # initialize
46
+ @configuration = {}
47
+ @ordered_keys = []
48
+ @indent = ''
49
+ parse(config_str)
50
+ end # initialize
48
51
 
49
- # build_min_config_hash
50
- #
51
- # Build a config hash of the minimum keys that would be needed to update
52
- # current config to all of the changes in the "must" config. Each hash key
53
- # is a configuration command; some keys have subconfigs which must be
54
- # checked before dismissing top-level keys as present. This method is
55
- # used primarily by the free-form command_config providers.
56
- #
57
- # @param current [Hash] superset of running-config & must config
58
- # @param must [Hash] pending config from recipe, manifest, etc
59
- # @param min_config [Hash] in-progress recursion-built minimum config
60
- # @return min_config [Hash] in-progress recursion-built minimum config
61
- #
62
- def Configuration.build_min_config_hash(current, must, min_config={})
63
- return {} if must.empty? # base case
64
- must.each { |k, v| # check each must{k} is present in current{}
65
- if current.key?(k) # if cmd is in current then compare subconfig
66
- min_config[k] = Configuration.new("")
67
- min_config[k].configuration =
68
- build_min_config_hash(current[k].configuration,
69
- v.configuration, {})
70
- if min_config[k].configuration.empty?
71
- # no differing subconfigs, so empty hash is returned
72
- min_config.delete(k)
52
+ # build_min_config_hash
53
+ #
54
+ # Build a config hash of the minimum keys that would be needed to update
55
+ # current config to all of the changes in the "must" config. Each hash key
56
+ # is a configuration command; some keys have subconfigs which must be
57
+ # checked before dismissing top-level keys as present. This method is
58
+ # used primarily by the free-form command_config providers.
59
+ #
60
+ # @param current [Hash] superset of running-config & must config
61
+ # @param must [Hash] pending config from recipe, manifest, etc
62
+ # @param min_config [Hash] in-progress recursion-built minimum config
63
+ # @return min_config [Hash] in-progress recursion-built minimum config
64
+ #
65
+ def self.build_min_config_hash(current, must, min_config={})
66
+ return {} if must.empty? # base case
67
+ must.each do |k, v| # check each must{k} is present in current{}
68
+ if current.key?(k) # if cmd is in current then compare subconfig
69
+ min_config[k] = Configuration.new('')
70
+ min_config[k].configuration =
71
+ build_min_config_hash(current[k].configuration,
72
+ v.configuration, {})
73
+ if min_config[k].configuration.empty?
74
+ # no differing subconfigs, so empty hash is returned
75
+ min_config.delete(k)
76
+ end
77
+ else # command NOT in current, apply it + all subcommands
78
+ min_config[k] = v
73
79
  end
74
- else # command NOT in current, apply it + all subcommands
75
- min_config[k] = v
76
80
  end
77
- }
78
- min_config
79
- end # build_min_config_hash
81
+ min_config
82
+ end # build_min_config_hash
80
83
 
81
- def Configuration.config_hash_to_str(cmd_hash, str="")
82
- return "" if cmd_hash.empty?
83
- cmd_hash.each { |k, v|
84
- str += k + "\n"
85
- str += config_hash_to_str(v.configuration, "")
86
- }
87
- str
88
- end # config_hash_to_str
84
+ def self.config_hash_to_str(cmd_hash, str='')
85
+ return '' if cmd_hash.empty?
86
+ cmd_hash.each do |k, v|
87
+ str += k + "\n"
88
+ str += config_hash_to_str(v.configuration, '')
89
+ end
90
+ str
91
+ end # config_hash_to_str
89
92
 
90
- # Get base command and prefix
91
- #
92
- # @param command [String]
93
- # @return [String, String] containing prefix (if any) and
94
- # base command.
95
- def base_commands(command)
96
- prefix, base = command.match(/^(no )?(.*)$/).captures
97
- prefix = "" if prefix.nil?
98
- [prefix, base]
99
- end # base_commands
93
+ # Get base command and prefix
94
+ #
95
+ # @param command [String]
96
+ # @return [String, String] containing prefix (if any) and
97
+ # base command.
98
+ def base_commands(command)
99
+ prefix, base = command.match(/^(no )?(.*)$/).captures
100
+ prefix = '' if prefix.nil?
101
+ [prefix, base]
102
+ end # base_commands
100
103
 
101
- # Compare ConfigParser::Configuration objects
102
- #
103
- # @param config [ConfigParser::Configuration] obj to search
104
- # for match.
105
- # @return [String] containing match, empty if no match found.
106
- def compare_with(config)
107
- return nil if config.nil?
108
- existing = ""
109
- @ordered_keys.each { |config_line|
110
- command = config_line.strip
111
- submode = @configuration[command]
112
- raise StopIteration, "Could not find submode." if submode.nil?
104
+ # Compare ConfigParser::Configuration objects
105
+ #
106
+ # @param config [ConfigParser::Configuration] obj to search
107
+ # for match.
108
+ # @return [String] containing match, empty if no match found.
109
+ def compare_with(config)
110
+ return nil if config.nil?
111
+ existing = ''
112
+ @ordered_keys.each do |config_line|
113
+ command = config_line.strip
114
+ submode = @configuration[command]
115
+ fail StopIteration, 'Could not find submode.' if submode.nil?
113
116
 
114
- if special_command?(command)
115
- # match special exit/end command
116
- existing << config_line
117
- break
118
- elsif config.include_command?(command)
119
- # match whole command
120
- existing << config_line
121
- config_submode = config.submode_config(command)
122
- existing << submode.compare_with(config_submode)
123
- next
124
- end # if
117
+ if special_command?(command)
118
+ # match special exit/end command
119
+ existing << config_line
120
+ break
121
+ elsif config.include_command?(command)
122
+ # match whole command
123
+ existing << config_line
124
+ config_submode = config.submode_config(command)
125
+ existing << submode.compare_with(config_submode)
126
+ next
127
+ end # if
125
128
 
126
- prefix, base = base_commands(command)
127
- if prefix != "" and !config.include_command?(base)
128
- existing << config_line
129
- next
129
+ prefix, base = base_commands(command)
130
+ if prefix != '' && !config.include_command?(base)
131
+ existing << config_line
132
+ next
133
+ end
130
134
  end
131
- }
132
- existing
133
- end # compare_with
135
+ existing
136
+ end # compare_with
134
137
 
135
- # @return [Array] containing command with leading/trailing
136
- # whitespace removed.
137
- def mode_configuration
138
- @ordered_keys.collect(&:strip)
139
- end # mode_configuration
138
+ # @return [Array] containing command with leading/trailing
139
+ # whitespace removed.
140
+ def mode_configuration
141
+ @ordered_keys.collect(&:strip)
142
+ end # mode_configuration
140
143
 
141
- # Check command [Array] for test command
142
- #
143
- # @param command [String] test command
144
- # @return [Boolean] true if command found, else false
145
- def include_command?(command)
146
- commands = mode_configuration()
147
- commands.include?(command)
148
- end # include_command?
144
+ # Check command [Array] for test command
145
+ #
146
+ # @param command [String] test command
147
+ # @return [Boolean] true if command found, else false
148
+ def include_command?(command)
149
+ commands = mode_configuration
150
+ commands.include?(command)
151
+ end # include_command?
149
152
 
150
- # Parse each config command line and create a
151
- # hash of ConfigParser::Configuration objects
152
- #
153
- # @param config_str [String] Config command
154
- def parse(config_str)
155
- config_str += "\n"
156
- config_str.gsub!(/^\s*$\n/, '')
157
- # ignore leading ! or # (comments)
158
- config_str.gsub!(/^\s*[!#].*$\n/, '')
159
- if config_str.match(/^ *\t/)
160
- highlight_str = config_str.gsub(/\t/, '[TAB]')
161
- raise "Tab character detected in indentation area:\n" + highlight_str
162
- end
163
- indent_level = config_str.match(/^\s*/)
164
- @indent = indent_level.to_s # capture indentation of level
165
- escaped_indent = Regexp.escape(@indent)
166
- @ordered_keys = config_str.scan(/^#{escaped_indent}\S.*\n/) # find current configuration mode lines
167
- @ordered_keys.each { |config_line|
168
- command = config_line.strip
169
- escaped_cmd = Regexp.escape(config_line)
170
- submode_string = config_str.match(/^(?:#{escaped_cmd})((?:#{escaped_indent}\s.+\n)*)/).captures.join
171
- @configuration[command] = Configuration.new(submode_string)
172
- }
173
- end # parse
153
+ # Parse each config command line and create a
154
+ # hash of ConfigParser::Configuration objects
155
+ #
156
+ # @param config_str [String] Config command
157
+ def parse(config_str)
158
+ config_str += "\n"
159
+ config_str.gsub!(/^\s*$\n/, '')
160
+ # ignore leading ! or # (comments)
161
+ config_str.gsub!(/^\s*[!#].*$\n/, '')
162
+ if config_str.match(/^ *\t/)
163
+ highlight_str = config_str.gsub(/\t/, '[TAB]')
164
+ fail "Tab character detected in indentation area:\n" + highlight_str
165
+ end
166
+ indent_level = config_str.match(/^\s*/)
167
+ @indent = indent_level.to_s # capture indentation of level
168
+ escaped_indent = Regexp.escape(@indent)
169
+ # Find current configuration mode lines
170
+ @ordered_keys = config_str.scan(/^#{escaped_indent}\S.*\n/)
171
+ @ordered_keys.each do |config_line|
172
+ command = config_line.strip
173
+ escaped_cmd = Regexp.escape(config_line)
174
+ submode_string = config_str.match(
175
+ /^(?:#{escaped_cmd})((?:#{escaped_indent}\s.+\n)*)/).captures.join
176
+ @configuration[command] = Configuration.new(submode_string)
177
+ end
178
+ end # parse
174
179
 
175
- # Process 'exit' and 'end' commands
176
- #
177
- # @param command [String] Configuration command.
178
- # @return [Boolean] true when command is
179
- # 'exit' or 'end', else false
180
- def special_command?(command)
181
- (/^(?:exit|end)/ === command)
182
- end # special_command?
180
+ # Process 'exit' and 'end' commands
181
+ #
182
+ # @param command [String] Configuration command.
183
+ # @return [Boolean] true when command is
184
+ # 'exit' or 'end', else false
185
+ def special_command?(command)
186
+ command =~ /^(?:exit|end)/
187
+ end # special_command?
183
188
 
184
- # Fetch ConfigParser::Configuration object containing config_line
185
- #
186
- # @param config_line [String]
187
- # @return [ConfigParser::Configuration] containing config_line
188
- def submode_config(config_line)
189
- command = config_line.strip
190
- @configuration[command]
191
- end # submode_config
189
+ # Fetch ConfigParser::Configuration object containing config_line
190
+ #
191
+ # @param config_line [String]
192
+ # @return [ConfigParser::Configuration] containing config_line
193
+ def submode_config(config_line)
194
+ command = config_line.strip
195
+ @configuration[command]
196
+ end # submode_config
192
197
 
193
- private :base_commands, :parse, :special_command?
194
- end # Configuration
195
- end # ConfigParser
198
+ private :base_commands, :parse, :special_command?
199
+ end # Configuration
200
+ end # ConfigParser
196
201
  end # Cisco
@@ -0,0 +1,79 @@
1
+ #
2
+ # NXAPI implementation of DnsDomain class
3
+ #
4
+ # September 2015, Hunter Haugen
5
+ #
6
+ # Copyright (c) 2015 Cisco and/or its affiliates.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ # "group" is a standard SNMP term but in NXOS "role" is used to serve the
21
+ # purpose of group; thus this provider utility does not create snmp groups
22
+ # and is limited to reporting group (role) existence only.
23
+
24
+ require_relative 'node_util'
25
+
26
+ module Cisco
27
+ # DnsDomain - node utility class for DNS search domain config management
28
+ class DnsDomain < NodeUtil
29
+ attr_reader :name, :vrf
30
+
31
+ def initialize(name, vrf=nil, instantiate=true)
32
+ unless name.is_a? String
33
+ fail TypeError, "Expected a string, got a #{name.class.inspect}"
34
+ end
35
+ @name = name
36
+ @vrf = vrf
37
+ create if instantiate
38
+ end
39
+
40
+ def self.dnsdomains(vrf=nil)
41
+ if vrf.nil?
42
+ domains = config_get('dnsclient', 'domain_list')
43
+ else
44
+ domains = config_get('dnsclient', 'domain_list_vrf', vrf: vrf)
45
+ end
46
+ return {} if domains.nil?
47
+
48
+ hash = {}
49
+ domains.each do |name|
50
+ hash[name] = DnsDomain.new(name, vrf, false)
51
+ end
52
+ hash
53
+ end
54
+
55
+ def ==(other)
56
+ (name == other.name) && (vrf == other.vrf)
57
+ end
58
+
59
+ def create
60
+ if @vrf.nil?
61
+ config_set('dnsclient', 'domain_list',
62
+ state: '', name: @name)
63
+ else
64
+ config_set('dnsclient', 'domain_list_vrf',
65
+ state: '', name: @name, vrf: @vrf)
66
+ end
67
+ end
68
+
69
+ def destroy
70
+ if @vrf.nil?
71
+ config_set('dnsclient', 'domain_list',
72
+ state: 'no', name: @name)
73
+ else
74
+ config_set('dnsclient', 'domain_list_vrf',
75
+ state: 'no', name: @name, vrf: @vrf)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,71 @@
1
+ # Domain Name provider class
2
+ #
3
+ # October 2015, Bryan Jen
4
+ #
5
+ # Copyright (c) 2014-2015 Cisco and/or its affiliates.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative 'node_util'
20
+
21
+ module Cisco
22
+ # DomainName- node utility class for domain name configuration
23
+ class DomainName < NodeUtil
24
+ attr_reader :name, :vrf
25
+
26
+ def initialize(name, vrf=nil, instantiate=true)
27
+ @name = name
28
+ @vrf = vrf
29
+ create if instantiate
30
+ end
31
+
32
+ def self.domainnames(vrf=nil)
33
+ hash = {}
34
+ if vrf.nil?
35
+ domains = config_get('dnsclient', 'domain_name')
36
+ else
37
+ domains = config_get('dnsclient', 'domain_name_vrf', vrf: vrf)
38
+ end
39
+ return hash if domains.nil?
40
+
41
+ domains.each do |name|
42
+ hash[name] = DomainName.new(name, vrf, false)
43
+ end
44
+ hash
45
+ end
46
+
47
+ def ==(other)
48
+ (name == other.name) && (vrf == other.vrf)
49
+ end
50
+
51
+ def create
52
+ if @vrf.nil?
53
+ config_set('dnsclient', 'domain_name',
54
+ state: '', name: @name)
55
+ else
56
+ config_set('dnsclient', 'domain_name_vrf',
57
+ state: '', name: @name, vrf: @vrf)
58
+ end
59
+ end
60
+
61
+ def destroy
62
+ if @vrf.nil?
63
+ config_set('dnsclient', 'domain_name',
64
+ state: 'no', name: @name)
65
+ else
66
+ config_set('dnsclient', 'domain_name_vrf',
67
+ state: 'no', name: @name, vrf: @vrf)
68
+ end
69
+ end
70
+ end
71
+ end