cisco_node_utils 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,6 +1,3 @@
1
- #
2
- # NXAPI implementation of Interface class
3
- #
4
1
  # November 2015, Chris Van Heuveln
5
2
  #
6
3
  # Copyright (c) 2015 Cisco and/or its affiliates.
@@ -17,33 +14,33 @@
17
14
  # See the License for the specific language governing permissions and
18
15
  # limitations under the License.
19
16
 
20
- require File.join(File.dirname(__FILE__), 'node')
17
+ require_relative 'node_util'
21
18
 
19
+ # Add some interface-specific constants to the Cisco namespace
22
20
  module Cisco
23
21
  IF_SWITCHPORT_MODE = {
24
- :disabled => "",
25
- :access => "access",
26
- :trunk => "trunk",
27
- :fex_fabric => "fex-fabric",
28
- :tunnel => "dot1q-tunnel",
22
+ disabled: '',
23
+ access: 'access',
24
+ trunk: 'trunk',
25
+ fex_fabric: 'fex-fabric',
26
+ tunnel: 'dot1q-tunnel',
29
27
  }
30
28
 
31
- class Interface
29
+ # Interface - node utility class for general interface config management
30
+ class Interface < NodeUtil
32
31
  attr_reader :name
33
32
 
34
- @@node = Cisco::Node.instance
35
-
36
33
  def initialize(name, instantiate=true)
37
- raise TypeError unless name.is_a?(String)
38
- raise ArgumentError unless name.length > 0
34
+ fail TypeError unless name.is_a?(String)
35
+ fail ArgumentError unless name.length > 0
39
36
  @name = name.downcase
40
37
 
41
38
  create if instantiate
42
39
  end
43
40
 
44
- def Interface.interfaces
41
+ def self.interfaces
45
42
  hash = {}
46
- intf_list = @@node.config_get("interface", "all_interfaces")
43
+ intf_list = config_get('interface', 'all_interfaces')
47
44
  return hash if intf_list.nil?
48
45
 
49
46
  intf_list.each do |id|
@@ -55,11 +52,11 @@ module Cisco
55
52
 
56
53
  def create
57
54
  feature_vlan_set(true) if @name[/vlan/i]
58
- @@node.config_set("interface", "create", @name)
55
+ config_set('interface', 'create', @name)
59
56
  end
60
57
 
61
58
  def destroy
62
- @@node.config_set("interface", "destroy", @name)
59
+ config_set('interface', 'destroy', @name)
63
60
  end
64
61
 
65
62
  ########################################################
@@ -67,61 +64,65 @@ module Cisco
67
64
  ########################################################
68
65
 
69
66
  def access_vlan
70
- vlan = @@node.config_get("interface", "access_vlan", @name)
67
+ vlan = config_get('interface', 'access_vlan', @name)
71
68
  return default_access_vlan if vlan.nil?
72
69
  vlan.shift.to_i
73
70
  end
74
71
 
75
72
  def access_vlan=(vlan)
76
- @@node.config_set("interface", "access_vlan", @name, vlan)
73
+ config_set('interface', 'access_vlan', @name, vlan)
77
74
  rescue Cisco::CliError => e
78
75
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
79
76
  end
80
77
 
81
78
  def default_access_vlan
82
- @@node.config_get_default("interface", "access_vlan")
79
+ config_get_default('interface', 'access_vlan')
83
80
  end
84
81
 
85
82
  def description
86
- desc = @@node.config_get("interface", "description", @name)
87
- return "" if desc.nil?
83
+ desc = config_get('interface', 'description', @name)
84
+ return '' if desc.nil?
88
85
  desc.shift.strip
89
86
  end
90
87
 
91
88
  def description=(desc)
92
- raise TypeError unless desc.is_a?(String)
93
- desc.empty? ?
94
- @@node.config_set("interface", "description", @name, "no", "") :
95
- @@node.config_set("interface", "description", @name, "", desc)
89
+ fail TypeError unless desc.is_a?(String)
90
+ if desc.strip.empty?
91
+ config_set('interface', 'description', @name, 'no', '')
92
+ else
93
+ config_set('interface', 'description', @name, '', desc)
94
+ end
96
95
  rescue Cisco::CliError => e
97
96
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
98
97
  end
99
98
 
100
99
  def default_description
101
- @@node.config_get_default("interface", "description")
100
+ config_get_default('interface', 'description')
102
101
  end
103
102
 
104
103
  def encapsulation_dot1q
105
- val = @@node.config_get("interface", "encapsulation_dot1q", @name)
104
+ val = config_get('interface', 'encapsulation_dot1q', @name)
106
105
  return default_encapsulation_dot1q if val.nil?
107
106
  val.shift.strip.to_i
108
107
  end
109
108
 
110
109
  def encapsulation_dot1q=(val)
111
- val.nil? ?
112
- @@node.config_set("interface", "encapsulation_dot1q", @name, "no", "") :
113
- @@node.config_set("interface", "encapsulation_dot1q", @name, "", val)
110
+ if val.to_s.empty?
111
+ config_set('interface', 'encapsulation_dot1q', @name, 'no', '')
112
+ else
113
+ config_set('interface', 'encapsulation_dot1q', @name, '', val)
114
+ end
114
115
  rescue Cisco::CliError => e
115
116
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
116
117
  end
117
118
 
118
119
  def default_encapsulation_dot1q
119
- @@node.config_get_default("interface", "encapsulation_dot1q")
120
+ config_get_default('interface', 'encapsulation_dot1q')
120
121
  end
121
122
 
122
123
  def fex_feature
123
- fex = @@node.config_get("fex", "feature")
124
- raise "fex_feature not found" if fex.nil?
124
+ fex = config_get('fex', 'feature')
125
+ fail 'fex_feature not found' if fex.nil?
125
126
  fex.shift.to_sym
126
127
  end
127
128
 
@@ -131,32 +132,32 @@ module Cisco
131
132
 
132
133
  case fex_set
133
134
  when :enabled
134
- @@node.config_set("fex", "feature_install", "") if curr == :uninstalled
135
- @@node.config_set("fex", "feature", "")
135
+ config_set('fex', 'feature_install', '') if curr == :uninstalled
136
+ config_set('fex', 'feature', '')
136
137
  when :disabled
137
- @@node.config_set("fex", "feature", "no") if curr == :enabled
138
+ config_set('fex', 'feature', 'no') if curr == :enabled
138
139
  return
139
140
  when :installed
140
- @@node.config_set("fex", "feature_install", "") if curr == :uninstalled
141
+ config_set('fex', 'feature_install', '') if curr == :uninstalled
141
142
  when :uninstalled
142
- @@node.config_set("fex", "feature", "no") if curr == :enabled
143
- @@node.config_set("fex", "feature_install", "no")
143
+ config_set('fex', 'feature', 'no') if curr == :enabled
144
+ config_set('fex', 'feature_install', 'no')
144
145
  end
145
146
  rescue Cisco::CliError => e
146
147
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
147
148
  end
148
149
 
149
150
  def ipv4_addr_mask
150
- @@node.config_get("interface", "ipv4_addr_mask", @name)
151
+ config_get('interface', 'ipv4_addr_mask', @name)
151
152
  end
152
153
 
153
154
  def ipv4_addr_mask_set(addr, mask)
154
155
  check_switchport_disabled
155
- if addr.nil? or addr == default_ipv4_address
156
- @@node.config_set("interface", "ipv4_addr_mask", @name, "no", "")
156
+ if addr.nil? || addr == default_ipv4_address
157
+ config_set('interface', 'ipv4_addr_mask', @name, 'no', '')
157
158
  else
158
- @@node.config_set("interface", "ipv4_addr_mask", @name, "",
159
- "#{addr}/#{mask}")
159
+ config_set('interface', 'ipv4_addr_mask', @name, '',
160
+ "#{addr}/#{mask}")
160
161
  end
161
162
  rescue Cisco::CliError => e
162
163
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
@@ -165,116 +166,115 @@ module Cisco
165
166
  def ipv4_address
166
167
  val = ipv4_addr_mask
167
168
  return default_ipv4_address if val.nil?
168
- addr, mask = val.shift
169
- addr
169
+ # val is [[addr, mask]] - we just want the addr
170
+ val.shift.first
170
171
  end
171
172
 
172
173
  def default_ipv4_address
173
- @@node.config_get_default("interface", "ipv4_address")
174
+ config_get_default('interface', 'ipv4_address')
174
175
  end
175
176
 
176
177
  def ipv4_netmask_length
177
178
  val = ipv4_addr_mask
178
179
  return default_ipv4_netmask_length if val.nil?
179
- addr, mask = val.shift
180
- mask.to_i
180
+ # val is [[addr, mask]] - we just want the mask
181
+ val.shift.last.to_i
181
182
  end
182
183
 
183
184
  def default_ipv4_netmask_length
184
- @@node.config_get_default("interface", "ipv4_netmask_length")
185
+ config_get_default('interface', 'ipv4_netmask_length')
185
186
  end
186
187
 
187
188
  def ipv4_proxy_arp
188
- state = @@node.config_get("interface", "ipv4_proxy_arp", @name)
189
+ state = config_get('interface', 'ipv4_proxy_arp', @name)
189
190
  state.nil? ? false : true
190
191
  end
191
192
 
192
193
  def ipv4_proxy_arp=(proxy_arp)
193
194
  check_switchport_disabled
194
- no_cmd = (proxy_arp ? "" : "no")
195
- @@node.config_set("interface", "ipv4_proxy_arp", @name, no_cmd)
195
+ no_cmd = (proxy_arp ? '' : 'no')
196
+ config_set('interface', 'ipv4_proxy_arp', @name, no_cmd)
196
197
  end
197
198
 
198
199
  def default_ipv4_proxy_arp
199
- @@node.config_get_default("interface", "ipv4_proxy_arp")
200
+ config_get_default('interface', 'ipv4_proxy_arp')
200
201
  end
201
202
 
202
203
  def ipv4_redirects_lookup_string
203
204
  case @name
204
205
  when /loopback/i
205
- return "ipv4_redirects_loopback"
206
+ return 'ipv4_redirects_loopback'
206
207
  else
207
- return "ipv4_redirects_other_interfaces"
208
+ return 'ipv4_redirects_other_interfaces'
208
209
  end
209
210
  end
210
211
 
211
212
  def ipv4_redirects
212
213
  begin
213
- state = @@node.config_get("interface",
214
- ipv4_redirects_lookup_string, @name)
214
+ state = config_get('interface',
215
+ ipv4_redirects_lookup_string, @name)
215
216
  rescue IndexError
216
217
  state = nil
217
218
  end
218
219
  # We return default state for the platform if the platform doesn't support
219
220
  # the command
220
- return default_ipv4_redirects if state.nil? or state.empty?
221
+ return default_ipv4_redirects if state.nil? || state.empty?
221
222
  state.shift[/^ip redirects$/] ? true : false
222
223
  end
223
224
 
224
225
  def ipv4_redirects=(redirects)
225
226
  check_switchport_disabled
226
- no_cmd = (redirects ? "" : "no")
227
- @@node.config_set("interface", ipv4_redirects_lookup_string, @name, no_cmd)
227
+ no_cmd = (redirects ? '' : 'no')
228
+ config_set('interface', ipv4_redirects_lookup_string, @name, no_cmd)
228
229
  rescue IndexError
229
230
  raise "ipv4 redirects not supported on #{@name}"
230
231
  end
231
232
 
232
233
  def default_ipv4_redirects
233
- @@node.config_get_default("interface", ipv4_redirects_lookup_string)
234
+ config_get_default('interface', ipv4_redirects_lookup_string)
234
235
  end
235
236
 
236
237
  def feature_lacp?
237
- not @@node.config_get("interface", "feature_lacp").nil?
238
+ !config_get('interface', 'feature_lacp').nil?
238
239
  end
239
240
 
240
241
  def feature_lacp_set(val)
241
242
  return if feature_lacp? == val
242
- @@node.config_set("interface", "feature_lacp", val ? "" : "no")
243
+ config_set('interface', 'feature_lacp', val ? '' : 'no')
243
244
  end
244
245
 
245
246
  def mtu
246
- mtu = @@node.config_get("interface", "mtu", @name)
247
+ mtu = config_get('interface', 'mtu', @name)
247
248
  return default_mtu if mtu.nil?
248
249
  mtu.shift.strip.to_i
249
250
  end
250
251
 
251
- def mtu=(mtu)
252
- mtu.nil? ?
253
- @@node.config_set("interface", "mtu", @name, "no", "") :
254
- @@node.config_set("interface", "mtu", @name, "", mtu)
252
+ def mtu=(val)
253
+ check_switchport_disabled
254
+ config_set('interface', 'mtu', @name, '', val)
255
255
  rescue Cisco::CliError => e
256
256
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
257
257
  end
258
258
 
259
259
  def default_mtu
260
- @@node.config_get_default("interface", "mtu")
260
+ config_get_default('interface', 'mtu')
261
261
  end
262
262
 
263
263
  def negotiate_auto_lookup_string
264
264
  case @name
265
265
  when /Ethernet/i
266
- return "negotiate_auto_ethernet"
266
+ return 'negotiate_auto_ethernet'
267
267
  when /port-channel/i # Ether-channel
268
- return "negotiate_auto_portchannel"
268
+ return 'negotiate_auto_portchannel'
269
269
  else
270
- return "negotiate_auto_other_interfaces"
270
+ return 'negotiate_auto_other_interfaces'
271
271
  end
272
272
  end
273
273
 
274
274
  def negotiate_auto
275
275
  lookup = negotiate_auto_lookup_string
276
276
  begin
277
- state = @@node.config_get("interface", lookup, @name)
277
+ state = config_get('interface', lookup, @name)
278
278
  rescue IndexError
279
279
  # We return default state even if the config_get is not supported
280
280
  # for this platform / interface type. This is done so that we can set
@@ -287,9 +287,9 @@ module Cisco
287
287
 
288
288
  def negotiate_auto=(negotiate_auto)
289
289
  lookup = negotiate_auto_lookup_string
290
- no_cmd = (negotiate_auto ? "" : "no")
290
+ no_cmd = (negotiate_auto ? '' : 'no')
291
291
  begin
292
- @@node.config_set("interface", lookup, @name, no_cmd)
292
+ config_set('interface', lookup, @name, no_cmd)
293
293
  rescue Cisco::CliError => e
294
294
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
295
295
  rescue IndexError
@@ -298,17 +298,17 @@ module Cisco
298
298
  end
299
299
 
300
300
  def default_negotiate_auto
301
- @@node.config_get_default("interface", negotiate_auto_lookup_string)
301
+ config_get_default('interface', negotiate_auto_lookup_string)
302
302
  end
303
303
 
304
304
  def shutdown
305
- state = @@node.config_get("interface", "shutdown", @name)
305
+ state = config_get('interface', 'shutdown', @name)
306
306
  state ? true : false
307
307
  end
308
308
 
309
309
  def shutdown=(state)
310
- no_cmd = (state ? "" : "no")
311
- @@node.config_set("interface", "shutdown", @name, no_cmd)
310
+ no_cmd = (state ? '' : 'no')
311
+ config_set('interface', 'shutdown', @name, no_cmd)
312
312
  rescue Cisco::CliError => e
313
313
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
314
314
  end
@@ -319,75 +319,75 @@ module Cisco
319
319
  def_sw = system_default_switchport
320
320
  def_shut = system_default_switchport_shutdown
321
321
 
322
- if def_sw and def_shut
323
- lookup = "shutdown_ethernet_switchport_shutdown"
324
- elsif def_sw and not def_shut
325
- lookup = "shutdown_ethernet_switchport_noshutdown"
326
- elsif not def_sw and def_shut
327
- lookup = "shutdown_ethernet_noswitchport_shutdown"
328
- elsif not def_sw and not def_shut
329
- lookup = "shutdown_ethernet_noswitchport_noshutdown"
322
+ if def_sw && def_shut
323
+ lookup = 'shutdown_ethernet_switchport_shutdown'
324
+ elsif def_sw && !def_shut
325
+ lookup = 'shutdown_ethernet_switchport_noshutdown'
326
+ elsif !def_sw && def_shut
327
+ lookup = 'shutdown_ethernet_noswitchport_shutdown'
328
+ elsif !def_sw && !def_shut
329
+ lookup = 'shutdown_ethernet_noswitchport_noshutdown'
330
330
  else
331
- raise "Error: def_sw #{def_sw}, def_shut #{def_shut}"
331
+ fail "Error: def_sw #{def_sw}, def_shut #{def_shut}"
332
332
  end
333
333
 
334
334
  when /loopback/i
335
- lookup = "shutdown_loopback"
335
+ lookup = 'shutdown_loopback'
336
336
 
337
- when /port-channel/i # EtherChannel
338
- lookup = "shutdown_ether_channel"
337
+ when /port-channel/i # EtherChannel
338
+ lookup = 'shutdown_ether_channel'
339
339
 
340
340
  when /Vlan/i
341
- lookup = "shutdown_vlan"
341
+ lookup = 'shutdown_vlan'
342
342
 
343
343
  else
344
- lookup = "shutdown_unknown"
344
+ lookup = 'shutdown_unknown'
345
345
  end
346
- @@node.config_get_default("interface", lookup)
346
+ config_get_default('interface', lookup)
347
347
  end
348
348
 
349
349
  def switchport
350
350
  # This is "switchport", not "switchport mode"
351
- sw = @@node.config_get("interface", "switchport", @name)
351
+ sw = config_get('interface', 'switchport', @name)
352
352
  sw.nil? ? false : true
353
353
  end
354
354
 
355
355
  def switchport_enable(val=true)
356
- @@node.config_set("interface", "switchport", @name, val ? "" : "no")
356
+ config_set('interface', 'switchport', @name, val ? '' : 'no')
357
357
  end
358
358
 
359
359
  # switchport_autostate_exclude is exclusive to switchport interfaces
360
360
  def switchport_autostate_exclude
361
- not @@node.config_get("interface",
362
- "switchport_autostate_exclude", @name).nil?
361
+ !config_get('interface',
362
+ 'switchport_autostate_exclude', @name).nil?
363
363
  end
364
364
 
365
365
  def switchport_autostate_exclude=(val)
366
366
  # cannot configure autostate unless feature vlan is enabled
367
- raise "switchport mode must be configured before switchport autostate" unless
368
- switchport
367
+ fail('switchport mode must be configured before ' \
368
+ 'switchport autostate') unless switchport
369
369
  feature_vlan_set(true)
370
- @@node.config_set("interface", "switchport_autostate_exclude",
371
- @name, val ? "" : "no")
370
+ config_set('interface', 'switchport_autostate_exclude',
371
+ @name, val ? '' : 'no')
372
372
  end
373
373
 
374
374
  def default_switchport_autostate_exclude
375
- @@node.config_get_default("interface", "switchport_autostate_exclude")
375
+ config_get_default('interface', 'switchport_autostate_exclude')
376
376
  end
377
377
 
378
378
  def switchport_mode_lookup_string
379
379
  case @name
380
380
  when /Ethernet/i
381
- return "switchport_mode_ethernet"
381
+ return 'switchport_mode_ethernet'
382
382
  when /port-channel/i
383
- return "switchport_mode_port_channel"
383
+ return 'switchport_mode_port_channel'
384
384
  else
385
- return "switchport_mode_other_interfaces"
385
+ return 'switchport_mode_other_interfaces'
386
386
  end
387
387
  end
388
388
 
389
389
  def switchport_mode
390
- mode = @@node.config_get("interface", switchport_mode_lookup_string, @name)
390
+ mode = config_get('interface', switchport_mode_lookup_string, @name)
391
391
 
392
392
  return mode.nil? ? :disabled : IF_SWITCHPORT_MODE.key(mode.shift)
393
393
 
@@ -404,8 +404,8 @@ module Cisco
404
404
  if (:fex_fabric == mode_set)
405
405
  fex_feature_set(:enabled) unless (:enabled == fex_feature)
406
406
  end
407
- @@node.config_set("interface", switchport_mode_lookup_string, @name, "",
408
- IF_SWITCHPORT_MODE[mode_set])
407
+ config_set('interface', switchport_mode_lookup_string, @name, '',
408
+ IF_SWITCHPORT_MODE[mode_set])
409
409
 
410
410
  rescue RuntimeError
411
411
  raise "[#{@name}] switchport_mode is not supported on this interface"
@@ -416,18 +416,18 @@ module Cisco
416
416
  # int e1/1
417
417
  # switchport
418
418
  # switchport mode [access|trunk|fex|...]
419
- raise ArgumentError unless IF_SWITCHPORT_MODE.keys.include? mode_set
419
+ fail ArgumentError unless IF_SWITCHPORT_MODE.keys.include? mode_set
420
420
  case mode_set
421
421
  when :disabled
422
422
  if switchport
423
423
  # Note: turn off switchport command, not switchport mode
424
- @@node.config_set("interface", "switchport", @name, "no")
424
+ config_set('interface', 'switchport', @name, 'no')
425
425
  end
426
426
 
427
427
  when :default
428
428
  if :disabled == default_switchport_mode
429
- @@node.config_set("interface", switchport_mode_lookup_string,
430
- @name, "no", "")
429
+ config_set('interface', switchport_mode_lookup_string,
430
+ @name, 'no', '')
431
431
  else
432
432
  switchport_enable_and_mode(mode_set)
433
433
  end
@@ -443,104 +443,108 @@ module Cisco
443
443
  def default_switchport_mode
444
444
  return :disabled unless system_default_switchport
445
445
  IF_SWITCHPORT_MODE.key(
446
- @@node.config_get_default("interface", switchport_mode_lookup_string))
446
+ config_get_default('interface', switchport_mode_lookup_string))
447
447
  end
448
448
 
449
449
  def switchport_trunk_allowed_vlan
450
- val = @@node.config_get(
451
- "interface", "switchport_trunk_allowed_vlan", @name)
450
+ val = config_get(
451
+ 'interface', 'switchport_trunk_allowed_vlan', @name)
452
452
  return default_switchport_trunk_allowed_vlan if val.nil?
453
453
  val.shift.strip
454
454
  end
455
455
 
456
456
  def switchport_trunk_allowed_vlan=(val)
457
- val.nil? ?
458
- @@node.config_set(
459
- "interface", "switchport_trunk_allowed_vlan", @name, "no", "") :
460
- @@node.config_set(
461
- "interface", "switchport_trunk_allowed_vlan", @name, "", val)
457
+ if val.nil?
458
+ config_set(
459
+ 'interface', 'switchport_trunk_allowed_vlan', @name, 'no', '')
460
+ else
461
+ config_set(
462
+ 'interface', 'switchport_trunk_allowed_vlan', @name, '', val)
463
+ end
462
464
  rescue Cisco::CliError => e
463
465
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
464
466
  end
465
467
 
466
468
  def default_switchport_trunk_allowed_vlan
467
- @@node.config_get_default("interface", "switchport_trunk_allowed_vlan")
469
+ config_get_default('interface', 'switchport_trunk_allowed_vlan')
468
470
  end
469
471
 
470
472
  def switchport_trunk_native_vlan
471
- val = @@node.config_get(
472
- "interface", "switchport_trunk_native_vlan", @name)
473
+ val = config_get(
474
+ 'interface', 'switchport_trunk_native_vlan', @name)
473
475
  return default_switchport_trunk_native_vlan if val.nil?
474
476
  val.shift.strip.to_i
475
477
  end
476
478
 
477
479
  def switchport_trunk_native_vlan=(val)
478
- val.nil? ?
479
- @@node.config_set(
480
- "interface", "switchport_trunk_native_vlan", @name, "no", "") :
481
- @@node.config_set(
482
- "interface", "switchport_trunk_native_vlan", @name, "", val)
480
+ if val.nil?
481
+ config_set(
482
+ 'interface', 'switchport_trunk_native_vlan', @name, 'no', '')
483
+ else
484
+ config_set(
485
+ 'interface', 'switchport_trunk_native_vlan', @name, '', val)
486
+ end
483
487
  rescue Cisco::CliError => e
484
488
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
485
489
  end
486
490
 
487
491
  def default_switchport_trunk_native_vlan
488
- @@node.config_get_default("interface", "switchport_trunk_native_vlan")
492
+ config_get_default('interface', 'switchport_trunk_native_vlan')
489
493
  end
490
494
 
491
495
  def system_default_switchport
492
496
  # This command is a user-configurable system default.
493
- sys_def = @@node.config_get("interface", "system_default_switchport")
497
+ sys_def = config_get('interface', 'system_default_switchport')
494
498
  sys_def.nil? ? false : true
495
499
  end
496
500
 
497
501
  def system_default_switchport_shutdown
498
502
  # This command is a user-configurable system default.
499
- sys_def = @@node.config_get("interface",
500
- "system_default_switchport_shutdown")
503
+ sys_def = config_get('interface',
504
+ 'system_default_switchport_shutdown')
501
505
  sys_def.nil? ? false : true
502
506
  end
503
507
 
504
508
  def system_default_svi_autostate
505
509
  # This command is a user-configurable system default.
506
- sys_def = @@node.config_get("interface",
507
- "system_default_svi_autostate")
510
+ sys_def = config_get('interface',
511
+ 'system_default_svi_autostate')
508
512
  sys_def.nil? ? false : true
509
513
  end
510
514
 
511
515
  def switchport_vtp_mode_capable?
512
- not switchport_mode.to_s.match(/(access|trunk)/).nil?
516
+ !switchport_mode.to_s.match(/(access|trunk)/).nil?
513
517
  end
514
518
 
515
519
  def switchport_vtp
516
520
  return false unless switchport_vtp_mode_capable?
517
- vtp = @@node.config_get("interface", "vtp", @name)
521
+ vtp = config_get('interface', 'vtp', @name)
518
522
  vtp.nil? ? false : true
519
523
  end
520
524
 
521
525
  def switchport_vtp=(vtp_set)
522
526
  return false unless switchport_vtp_mode_capable?
523
- no_cmd = (vtp_set) ? "" : "no"
524
- @@node.config_set("interface", "vtp", @name, no_cmd)
527
+ no_cmd = (vtp_set) ? '' : 'no'
528
+ config_set('interface', 'vtp', @name, no_cmd)
525
529
  rescue Cisco::CliError => e
526
530
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
527
531
  end
528
532
 
529
533
  def svi_cmd_allowed?(cmd)
530
- raise "[#{@name}] Invalid interface type for command [#{cmd}]" unless
534
+ fail "[#{@name}] Invalid interface type for command [#{cmd}]" unless
531
535
  @name[/vlan/i]
532
536
  end
533
537
 
534
538
  # svi_autostate is exclusive to svi interfaces
535
539
  def svi_autostate
536
540
  return nil unless @name[/^vlan/i]
537
- not @@node.config_get("interface", "svi_autostate", @name).nil?
541
+ !config_get('interface', 'svi_autostate', @name).nil?
538
542
  end
539
543
 
540
544
  def svi_autostate=(val)
541
545
  check_switchport_disabled
542
546
  svi_cmd_allowed?('autostate')
543
- @@node.config_set("interface", "svi_autostate", @name, val ? "" : "no")
547
+ config_set('interface', 'svi_autostate', @name, val ? '' : 'no')
544
548
  end
545
549
 
546
550
  def default_svi_autostate
@@ -548,60 +552,62 @@ module Cisco
548
552
  end
549
553
 
550
554
  def feature_vlan?
551
- not @@node.config_get("interface", "feature_vlan").nil?
555
+ !config_get('interface', 'feature_vlan').nil?
552
556
  end
553
557
 
554
558
  def feature_vlan_set(val)
555
559
  return if feature_vlan? == val
556
- @@node.config_set("interface", "feature_vlan", val ? "" : "no")
560
+ config_set('interface', 'feature_vlan', val ? '' : 'no')
557
561
  end
558
562
 
559
563
  # svi_management is exclusive to svi interfaces
560
564
  def svi_management
561
565
  return nil unless @name[/^vlan/i]
562
- not @@node.config_get("interface", "svi_management", @name).nil?
566
+ !config_get('interface', 'svi_management', @name).nil?
563
567
  end
564
568
 
565
569
  def svi_management=(val)
566
570
  check_switchport_disabled
567
571
  svi_cmd_allowed?('management')
568
- @@node.config_set("interface", "svi_management", @name, val ? "" : "no")
572
+ config_set('interface', 'svi_management', @name, val ? '' : 'no')
569
573
  end
570
574
 
571
575
  def default_svi_management
572
- @@node.config_get_default("interface", "svi_management")
576
+ config_get_default('interface', 'svi_management')
573
577
  end
574
578
 
575
579
  def default_switchport_vtp
576
- @@node.config_get_default("interface", "vtp")
580
+ config_get_default('interface', 'vtp')
577
581
  end
578
582
 
579
583
  def switchport_vtp_feature?
580
- @@node.config_get("vtp", "feature")
584
+ config_get('vtp', 'feature')
581
585
  end
582
586
 
583
587
  def check_switchport_disabled
584
- raise "#{caller[0][/`.*'/][1..-2]} cannot be set unless switchport mode" +
585
- " is disabled" unless switchport_mode == :disabled
588
+ fail "#{caller[0][/`.*'/][1..-2]} cannot be set unless switchport mode" \
589
+ ' is disabled' unless switchport_mode == :disabled
586
590
  end
587
591
 
588
592
  def vrf
589
- vrf = @@node.config_get("interface", "vrf", @name)
590
- return "" if vrf.nil?
593
+ vrf = config_get('interface', 'vrf', @name)
594
+ return '' if vrf.nil?
591
595
  vrf.shift.strip
592
596
  end
593
597
 
594
598
  def vrf=(vrf)
595
- raise TypeError unless vrf.is_a?(String)
596
- vrf.empty? ?
597
- @@node.config_set("interface", "vrf", @name, "no", "") :
598
- @@node.config_set("interface", "vrf", @name, "", vrf)
599
+ fail TypeError unless vrf.is_a?(String)
600
+ if vrf.empty?
601
+ config_set('interface', 'vrf', @name, 'no', '')
602
+ else
603
+ config_set('interface', 'vrf', @name, '', vrf)
604
+ end
599
605
  rescue Cisco::CliError => e
600
606
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
601
607
  end
602
608
 
603
609
  def default_vrf
604
- @@node.config_get_default("interface", "vrf")
610
+ config_get_default('interface', 'vrf')
605
611
  end
606
612
  end # Class
607
613
  end # Module