Class: Cisco::Interface
- Inherits:
-
Object
- Object
- Cisco::Interface
- Defined in:
- lib/cisco_node_utils/interface.rb
Constant Summary collapse
- @@node =
Cisco::Node.instance
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#access_vlan ⇒ Object
PROPERTIES #.
- #access_vlan=(vlan) ⇒ Object
- #check_switchport_disabled ⇒ Object
- #create ⇒ Object
- #default_access_vlan ⇒ Object
- #default_description ⇒ Object
- #default_encapsulation_dot1q ⇒ Object
- #default_ipv4_address ⇒ Object
- #default_ipv4_netmask_length ⇒ Object
- #default_ipv4_proxy_arp ⇒ Object
- #default_ipv4_redirects ⇒ Object
- #default_mtu ⇒ Object
- #default_negotiate_auto ⇒ Object
- #default_shutdown ⇒ Object
- #default_svi_autostate ⇒ Object
- #default_svi_management ⇒ Object
- #default_switchport_autostate_exclude ⇒ Object
- #default_switchport_mode ⇒ Object
- #default_switchport_trunk_allowed_vlan ⇒ Object
- #default_switchport_trunk_native_vlan ⇒ Object
- #default_switchport_vtp ⇒ Object
- #default_vrf ⇒ Object
- #description ⇒ Object
- #description=(desc) ⇒ Object
- #destroy ⇒ Object
- #encapsulation_dot1q ⇒ Object
- #encapsulation_dot1q=(val) ⇒ Object
- #feature_lacp? ⇒ Boolean
- #feature_lacp_set(val) ⇒ Object
- #feature_vlan? ⇒ Boolean
- #feature_vlan_set(val) ⇒ Object
- #fex_feature ⇒ Object
- #fex_feature_set(fex_set) ⇒ Object
-
#initialize(name, instantiate = true) ⇒ Interface
constructor
A new instance of Interface.
- #ipv4_addr_mask ⇒ Object
- #ipv4_addr_mask_set(addr, mask) ⇒ Object
- #ipv4_address ⇒ Object
- #ipv4_netmask_length ⇒ Object
- #ipv4_proxy_arp ⇒ Object
- #ipv4_proxy_arp=(proxy_arp) ⇒ Object
- #ipv4_redirects ⇒ Object
- #ipv4_redirects=(redirects) ⇒ Object
- #ipv4_redirects_lookup_string ⇒ Object
- #mtu ⇒ Object
- #mtu=(mtu) ⇒ Object
- #negotiate_auto ⇒ Object
- #negotiate_auto=(negotiate_auto) ⇒ Object
- #negotiate_auto_lookup_string ⇒ Object
- #shutdown ⇒ Object
- #shutdown=(state) ⇒ Object
-
#svi_autostate ⇒ Object
svi_autostate is exclusive to svi interfaces.
- #svi_autostate=(val) ⇒ Object
- #svi_cmd_allowed?(cmd) ⇒ Boolean
-
#svi_management ⇒ Object
svi_management is exclusive to svi interfaces.
- #svi_management=(val) ⇒ Object
- #switchport ⇒ Object
-
#switchport_autostate_exclude ⇒ Object
switchport_autostate_exclude is exclusive to switchport interfaces.
- #switchport_autostate_exclude=(val) ⇒ Object
- #switchport_enable(val = true) ⇒ Object
- #switchport_enable_and_mode(mode_set) ⇒ Object
- #switchport_mode ⇒ Object
- #switchport_mode=(mode_set) ⇒ Object
- #switchport_mode_lookup_string ⇒ Object
- #switchport_trunk_allowed_vlan ⇒ Object
- #switchport_trunk_allowed_vlan=(val) ⇒ Object
- #switchport_trunk_native_vlan ⇒ Object
- #switchport_trunk_native_vlan=(val) ⇒ Object
- #switchport_vtp ⇒ Object
- #switchport_vtp=(vtp_set) ⇒ Object
- #switchport_vtp_feature? ⇒ Boolean
- #switchport_vtp_mode_capable? ⇒ Boolean
- #system_default_svi_autostate ⇒ Object
- #system_default_switchport ⇒ Object
- #system_default_switchport_shutdown ⇒ Object
- #vrf ⇒ Object
- #vrf=(vrf) ⇒ Object
Constructor Details
#initialize(name, instantiate = true) ⇒ Interface
Returns a new instance of Interface.
36 37 38 39 40 41 42 |
# File 'lib/cisco_node_utils/interface.rb', line 36 def initialize(name, instantiate=true) raise TypeError unless name.is_a?(String) raise ArgumentError unless name.length > 0 @name = name.downcase create if instantiate end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
32 33 34 |
# File 'lib/cisco_node_utils/interface.rb', line 32 def name @name end |
Class Method Details
.interfaces ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cisco_node_utils/interface.rb', line 44 def Interface.interfaces hash = {} intf_list = @@node.config_get("interface", "all_interfaces") return hash if intf_list.nil? intf_list.each do |id| id = id.downcase hash[id] = Interface.new(id, false) end hash end |
Instance Method Details
#access_vlan ⇒ Object
PROPERTIES #
69 70 71 72 73 |
# File 'lib/cisco_node_utils/interface.rb', line 69 def access_vlan vlan = @@node.config_get("interface", "access_vlan", @name) return default_access_vlan if vlan.nil? vlan.shift.to_i end |
#access_vlan=(vlan) ⇒ Object
75 76 77 78 79 |
# File 'lib/cisco_node_utils/interface.rb', line 75 def access_vlan=(vlan) @@node.config_set("interface", "access_vlan", @name, vlan) rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#check_switchport_disabled ⇒ Object
583 584 585 586 |
# File 'lib/cisco_node_utils/interface.rb', line 583 def check_switchport_disabled raise "#{caller[0][/`.*'/][1..-2]} cannot be set unless switchport mode" + " is disabled" unless switchport_mode == :disabled end |
#create ⇒ Object
56 57 58 59 |
# File 'lib/cisco_node_utils/interface.rb', line 56 def create feature_vlan_set(true) if @name[/vlan/i] @@node.config_set("interface", "create", @name) end |
#default_access_vlan ⇒ Object
81 82 83 |
# File 'lib/cisco_node_utils/interface.rb', line 81 def default_access_vlan @@node.config_get_default("interface", "access_vlan") end |
#default_description ⇒ Object
100 101 102 |
# File 'lib/cisco_node_utils/interface.rb', line 100 def default_description @@node.config_get_default("interface", "description") end |
#default_encapsulation_dot1q ⇒ Object
118 119 120 |
# File 'lib/cisco_node_utils/interface.rb', line 118 def default_encapsulation_dot1q @@node.config_get_default("interface", "encapsulation_dot1q") end |
#default_ipv4_address ⇒ Object
172 173 174 |
# File 'lib/cisco_node_utils/interface.rb', line 172 def default_ipv4_address @@node.config_get_default("interface", "ipv4_address") end |
#default_ipv4_netmask_length ⇒ Object
183 184 185 |
# File 'lib/cisco_node_utils/interface.rb', line 183 def default_ipv4_netmask_length @@node.config_get_default("interface", "ipv4_netmask_length") end |
#default_ipv4_proxy_arp ⇒ Object
198 199 200 |
# File 'lib/cisco_node_utils/interface.rb', line 198 def default_ipv4_proxy_arp @@node.config_get_default("interface", "ipv4_proxy_arp") end |
#default_ipv4_redirects ⇒ Object
232 233 234 |
# File 'lib/cisco_node_utils/interface.rb', line 232 def default_ipv4_redirects @@node.config_get_default("interface", ipv4_redirects_lookup_string) end |
#default_mtu ⇒ Object
259 260 261 |
# File 'lib/cisco_node_utils/interface.rb', line 259 def default_mtu @@node.config_get_default("interface", "mtu") end |
#default_negotiate_auto ⇒ Object
300 301 302 |
# File 'lib/cisco_node_utils/interface.rb', line 300 def default_negotiate_auto @@node.config_get_default("interface", negotiate_auto_lookup_string) end |
#default_shutdown ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/cisco_node_utils/interface.rb', line 316 def default_shutdown case @name when /Ethernet/i def_sw = system_default_switchport def_shut = system_default_switchport_shutdown if def_sw and def_shut lookup = "shutdown_ethernet_switchport_shutdown" elsif def_sw and not def_shut lookup = "shutdown_ethernet_switchport_noshutdown" elsif not def_sw and def_shut lookup = "shutdown_ethernet_noswitchport_shutdown" elsif not def_sw and not def_shut lookup = "shutdown_ethernet_noswitchport_noshutdown" else raise "Error: def_sw #{def_sw}, def_shut #{def_shut}" end when /loopback/i lookup = "shutdown_loopback" when /port-channel/i # EtherChannel lookup = "shutdown_ether_channel" when /Vlan/i lookup = "shutdown_vlan" else lookup = "shutdown_unknown" end @@node.config_get_default("interface", lookup) end |
#default_svi_autostate ⇒ Object
546 547 548 |
# File 'lib/cisco_node_utils/interface.rb', line 546 def default_svi_autostate system_default_svi_autostate end |
#default_svi_management ⇒ Object
571 572 573 |
# File 'lib/cisco_node_utils/interface.rb', line 571 def default_svi_management @@node.config_get_default("interface", "svi_management") end |
#default_switchport_autostate_exclude ⇒ Object
374 375 376 |
# File 'lib/cisco_node_utils/interface.rb', line 374 def default_switchport_autostate_exclude @@node.config_get_default("interface", "switchport_autostate_exclude") end |
#default_switchport_mode ⇒ Object
443 444 445 446 447 |
# File 'lib/cisco_node_utils/interface.rb', line 443 def default_switchport_mode return :disabled unless system_default_switchport IF_SWITCHPORT_MODE.key( @@node.config_get_default("interface", switchport_mode_lookup_string)) end |
#default_switchport_trunk_allowed_vlan ⇒ Object
466 467 468 |
# File 'lib/cisco_node_utils/interface.rb', line 466 def default_switchport_trunk_allowed_vlan @@node.config_get_default("interface", "switchport_trunk_allowed_vlan") end |
#default_switchport_trunk_native_vlan ⇒ Object
487 488 489 |
# File 'lib/cisco_node_utils/interface.rb', line 487 def default_switchport_trunk_native_vlan @@node.config_get_default("interface", "switchport_trunk_native_vlan") end |
#default_switchport_vtp ⇒ Object
575 576 577 |
# File 'lib/cisco_node_utils/interface.rb', line 575 def default_switchport_vtp @@node.config_get_default("interface", "vtp") end |
#default_vrf ⇒ Object
603 604 605 |
# File 'lib/cisco_node_utils/interface.rb', line 603 def default_vrf @@node.config_get_default("interface", "vrf") end |
#description ⇒ Object
85 86 87 88 89 |
# File 'lib/cisco_node_utils/interface.rb', line 85 def description desc = @@node.config_get("interface", "description", @name) return "" if desc.nil? desc.shift.strip end |
#description=(desc) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/cisco_node_utils/interface.rb', line 91 def description=(desc) raise TypeError unless desc.is_a?(String) desc.empty? ? @@node.config_set("interface", "description", @name, "no", "") : @@node.config_set("interface", "description", @name, "", desc) rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#destroy ⇒ Object
61 62 63 |
# File 'lib/cisco_node_utils/interface.rb', line 61 def destroy @@node.config_set("interface", "destroy", @name) end |
#encapsulation_dot1q ⇒ Object
104 105 106 107 108 |
# File 'lib/cisco_node_utils/interface.rb', line 104 def encapsulation_dot1q val = @@node.config_get("interface", "encapsulation_dot1q", @name) return default_encapsulation_dot1q if val.nil? val.shift.strip.to_i end |
#encapsulation_dot1q=(val) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/cisco_node_utils/interface.rb', line 110 def encapsulation_dot1q=(val) val.nil? ? @@node.config_set("interface", "encapsulation_dot1q", @name, "no", "") : @@node.config_set("interface", "encapsulation_dot1q", @name, "", val) rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#feature_lacp? ⇒ Boolean
236 237 238 |
# File 'lib/cisco_node_utils/interface.rb', line 236 def feature_lacp? not @@node.config_get("interface", "feature_lacp").nil? end |
#feature_lacp_set(val) ⇒ Object
240 241 242 243 |
# File 'lib/cisco_node_utils/interface.rb', line 240 def feature_lacp_set(val) return if feature_lacp? == val @@node.config_set("interface", "feature_lacp", val ? "" : "no") end |
#feature_vlan? ⇒ Boolean
550 551 552 |
# File 'lib/cisco_node_utils/interface.rb', line 550 def feature_vlan? not @@node.config_get("interface", "feature_vlan").nil? end |
#feature_vlan_set(val) ⇒ Object
554 555 556 557 |
# File 'lib/cisco_node_utils/interface.rb', line 554 def feature_vlan_set(val) return if feature_vlan? == val @@node.config_set("interface", "feature_vlan", val ? "" : "no") end |
#fex_feature ⇒ Object
122 123 124 125 126 |
# File 'lib/cisco_node_utils/interface.rb', line 122 def fex_feature fex = @@node.config_get("fex", "feature") raise "fex_feature not found" if fex.nil? fex.shift.to_sym end |
#fex_feature_set(fex_set) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/cisco_node_utils/interface.rb', line 128 def fex_feature_set(fex_set) curr = fex_feature return if curr == fex_set case fex_set when :enabled @@node.config_set("fex", "feature_install", "") if curr == :uninstalled @@node.config_set("fex", "feature", "") when :disabled @@node.config_set("fex", "feature", "no") if curr == :enabled return when :installed @@node.config_set("fex", "feature_install", "") if curr == :uninstalled when :uninstalled @@node.config_set("fex", "feature", "no") if curr == :enabled @@node.config_set("fex", "feature_install", "no") end rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#ipv4_addr_mask ⇒ Object
149 150 151 |
# File 'lib/cisco_node_utils/interface.rb', line 149 def ipv4_addr_mask @@node.config_get("interface", "ipv4_addr_mask", @name) end |
#ipv4_addr_mask_set(addr, mask) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/cisco_node_utils/interface.rb', line 153 def ipv4_addr_mask_set(addr, mask) check_switchport_disabled if addr.nil? or addr == default_ipv4_address @@node.config_set("interface", "ipv4_addr_mask", @name, "no", "") else @@node.config_set("interface", "ipv4_addr_mask", @name, "", "#{addr}/#{mask}") end rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#ipv4_address ⇒ Object
165 166 167 168 169 170 |
# File 'lib/cisco_node_utils/interface.rb', line 165 def ipv4_address val = ipv4_addr_mask return default_ipv4_address if val.nil? addr, mask = val.shift addr end |
#ipv4_netmask_length ⇒ Object
176 177 178 179 180 181 |
# File 'lib/cisco_node_utils/interface.rb', line 176 def ipv4_netmask_length val = ipv4_addr_mask return default_ipv4_netmask_length if val.nil? addr, mask = val.shift mask.to_i end |
#ipv4_proxy_arp ⇒ Object
187 188 189 190 |
# File 'lib/cisco_node_utils/interface.rb', line 187 def ipv4_proxy_arp state = @@node.config_get("interface", "ipv4_proxy_arp", @name) state.nil? ? false : true end |
#ipv4_proxy_arp=(proxy_arp) ⇒ Object
192 193 194 195 196 |
# File 'lib/cisco_node_utils/interface.rb', line 192 def ipv4_proxy_arp=(proxy_arp) check_switchport_disabled no_cmd = (proxy_arp ? "" : "no") @@node.config_set("interface", "ipv4_proxy_arp", @name, no_cmd) end |
#ipv4_redirects ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/cisco_node_utils/interface.rb', line 211 def ipv4_redirects begin state = @@node.config_get("interface", ipv4_redirects_lookup_string, @name) rescue IndexError state = nil end # We return default state for the platform if the platform doesn't support # the command return default_ipv4_redirects if state.nil? or state.empty? state.shift[/^ip redirects$/] ? true : false end |
#ipv4_redirects=(redirects) ⇒ Object
224 225 226 227 228 229 230 |
# File 'lib/cisco_node_utils/interface.rb', line 224 def ipv4_redirects=(redirects) check_switchport_disabled no_cmd = (redirects ? "" : "no") @@node.config_set("interface", ipv4_redirects_lookup_string, @name, no_cmd) rescue IndexError raise "ipv4 redirects not supported on #{@name}" end |
#ipv4_redirects_lookup_string ⇒ Object
202 203 204 205 206 207 208 209 |
# File 'lib/cisco_node_utils/interface.rb', line 202 def ipv4_redirects_lookup_string case @name when /loopback/i return "ipv4_redirects_loopback" else return "ipv4_redirects_other_interfaces" end end |
#mtu ⇒ Object
245 246 247 248 249 |
# File 'lib/cisco_node_utils/interface.rb', line 245 def mtu mtu = @@node.config_get("interface", "mtu", @name) return default_mtu if mtu.nil? mtu.shift.strip.to_i end |
#mtu=(mtu) ⇒ Object
251 252 253 254 255 256 257 |
# File 'lib/cisco_node_utils/interface.rb', line 251 def mtu=(mtu) mtu.nil? ? @@node.config_set("interface", "mtu", @name, "no", "") : @@node.config_set("interface", "mtu", @name, "", mtu) rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#negotiate_auto ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/cisco_node_utils/interface.rb', line 274 def negotiate_auto lookup = negotiate_auto_lookup_string begin state = @@node.config_get("interface", lookup, @name) rescue IndexError # We return default state even if the config_get is not supported # for this platform / interface type. This is done so that we can set # the manifest to 'default' so there is a 'workaround' for the # unsupported attribute return default_negotiate_auto end state.nil? ? false : true end |
#negotiate_auto=(negotiate_auto) ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/cisco_node_utils/interface.rb', line 288 def negotiate_auto=(negotiate_auto) lookup = negotiate_auto_lookup_string no_cmd = (negotiate_auto ? "" : "no") begin @@node.config_set("interface", lookup, @name, no_cmd) rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" rescue IndexError raise "[#{@name}] negotiate_auto is not supported on this interface" end end |
#negotiate_auto_lookup_string ⇒ Object
263 264 265 266 267 268 269 270 271 272 |
# File 'lib/cisco_node_utils/interface.rb', line 263 def negotiate_auto_lookup_string case @name when /Ethernet/i return "negotiate_auto_ethernet" when /port-channel/i # Ether-channel return "negotiate_auto_portchannel" else return "negotiate_auto_other_interfaces" end end |
#shutdown ⇒ Object
304 305 306 307 |
# File 'lib/cisco_node_utils/interface.rb', line 304 def shutdown state = @@node.config_get("interface", "shutdown", @name) state ? true : false end |
#shutdown=(state) ⇒ Object
309 310 311 312 313 314 |
# File 'lib/cisco_node_utils/interface.rb', line 309 def shutdown=(state) no_cmd = (state ? "" : "no") @@node.config_set("interface", "shutdown", @name, no_cmd) rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#svi_autostate ⇒ Object
svi_autostate is exclusive to svi interfaces
535 536 537 538 |
# File 'lib/cisco_node_utils/interface.rb', line 535 def svi_autostate return nil unless @name[/^vlan/i] not @@node.config_get("interface", "svi_autostate", @name).nil? end |
#svi_autostate=(val) ⇒ Object
540 541 542 543 544 |
# File 'lib/cisco_node_utils/interface.rb', line 540 def svi_autostate=(val) check_switchport_disabled svi_cmd_allowed?('autostate') @@node.config_set("interface", "svi_autostate", @name, val ? "" : "no") end |
#svi_cmd_allowed?(cmd) ⇒ Boolean
529 530 531 532 |
# File 'lib/cisco_node_utils/interface.rb', line 529 def svi_cmd_allowed?(cmd) raise "[#{@name}] Invalid interface type for command [#{cmd}]" unless @name[/vlan/i] end |
#svi_management ⇒ Object
svi_management is exclusive to svi interfaces
560 561 562 563 |
# File 'lib/cisco_node_utils/interface.rb', line 560 def svi_management return nil unless @name[/^vlan/i] not @@node.config_get("interface", "svi_management", @name).nil? end |
#svi_management=(val) ⇒ Object
565 566 567 568 569 |
# File 'lib/cisco_node_utils/interface.rb', line 565 def svi_management=(val) check_switchport_disabled svi_cmd_allowed?('management') @@node.config_set("interface", "svi_management", @name, val ? "" : "no") end |
#switchport ⇒ Object
349 350 351 352 353 |
# File 'lib/cisco_node_utils/interface.rb', line 349 def switchport # This is "switchport", not "switchport mode" sw = @@node.config_get("interface", "switchport", @name) sw.nil? ? false : true end |
#switchport_autostate_exclude ⇒ Object
switchport_autostate_exclude is exclusive to switchport interfaces
360 361 362 363 |
# File 'lib/cisco_node_utils/interface.rb', line 360 def switchport_autostate_exclude not @@node.config_get("interface", "switchport_autostate_exclude", @name).nil? end |
#switchport_autostate_exclude=(val) ⇒ Object
365 366 367 368 369 370 371 372 |
# File 'lib/cisco_node_utils/interface.rb', line 365 def switchport_autostate_exclude=(val) # cannot configure autostate unless feature vlan is enabled raise "switchport mode must be configured before switchport autostate" unless switchport feature_vlan_set(true) @@node.config_set("interface", "switchport_autostate_exclude", @name, val ? "" : "no") end |
#switchport_enable(val = true) ⇒ Object
355 356 357 |
# File 'lib/cisco_node_utils/interface.rb', line 355 def switchport_enable(val=true) @@node.config_set("interface", "switchport", @name, val ? "" : "no") end |
#switchport_enable_and_mode(mode_set) ⇒ Object
401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/cisco_node_utils/interface.rb', line 401 def switchport_enable_and_mode(mode_set) switchport_enable unless switchport if (:fex_fabric == mode_set) fex_feature_set(:enabled) unless (:enabled == fex_feature) end @@node.config_set("interface", switchport_mode_lookup_string, @name, "", IF_SWITCHPORT_MODE[mode_set]) rescue RuntimeError raise "[#{@name}] switchport_mode is not supported on this interface" end |
#switchport_mode ⇒ Object
389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/cisco_node_utils/interface.rb', line 389 def switchport_mode mode = @@node.config_get("interface", switchport_mode_lookup_string, @name) return mode.nil? ? :disabled : IF_SWITCHPORT_MODE.key(mode.shift) rescue IndexError # Assume this is an interface that doesn't support switchport. # Do not raise exception since the providers will prefetch this property # regardless of interface type. return :disabled end |
#switchport_mode=(mode_set) ⇒ Object
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/cisco_node_utils/interface.rb', line 414 def switchport_mode=(mode_set) # no system default switchport # int e1/1 # switchport # switchport mode [access|trunk|fex|...] raise ArgumentError unless IF_SWITCHPORT_MODE.keys.include? mode_set case mode_set when :disabled if switchport # Note: turn off switchport command, not switchport mode @@node.config_set("interface", "switchport", @name, "no") end when :default if :disabled == default_switchport_mode @@node.config_set("interface", switchport_mode_lookup_string, @name, "no", "") else switchport_enable_and_mode(mode_set) end else switchport_enable_and_mode(mode_set) end # case rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#switchport_mode_lookup_string ⇒ Object
378 379 380 381 382 383 384 385 386 387 |
# File 'lib/cisco_node_utils/interface.rb', line 378 def switchport_mode_lookup_string case @name when /Ethernet/i return "switchport_mode_ethernet" when /port-channel/i return "switchport_mode_port_channel" else return "switchport_mode_other_interfaces" end end |
#switchport_trunk_allowed_vlan ⇒ Object
449 450 451 452 453 454 |
# File 'lib/cisco_node_utils/interface.rb', line 449 def switchport_trunk_allowed_vlan val = @@node.config_get( "interface", "switchport_trunk_allowed_vlan", @name) return default_switchport_trunk_allowed_vlan if val.nil? val.shift.strip end |
#switchport_trunk_allowed_vlan=(val) ⇒ Object
456 457 458 459 460 461 462 463 464 |
# File 'lib/cisco_node_utils/interface.rb', line 456 def switchport_trunk_allowed_vlan=(val) val.nil? ? @@node.config_set( "interface", "switchport_trunk_allowed_vlan", @name, "no", "") : @@node.config_set( "interface", "switchport_trunk_allowed_vlan", @name, "", val) rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#switchport_trunk_native_vlan ⇒ Object
470 471 472 473 474 475 |
# File 'lib/cisco_node_utils/interface.rb', line 470 def switchport_trunk_native_vlan val = @@node.config_get( "interface", "switchport_trunk_native_vlan", @name) return default_switchport_trunk_native_vlan if val.nil? val.shift.strip.to_i end |
#switchport_trunk_native_vlan=(val) ⇒ Object
477 478 479 480 481 482 483 484 485 |
# File 'lib/cisco_node_utils/interface.rb', line 477 def switchport_trunk_native_vlan=(val) val.nil? ? @@node.config_set( "interface", "switchport_trunk_native_vlan", @name, "no", "") : @@node.config_set( "interface", "switchport_trunk_native_vlan", @name, "", val) rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#switchport_vtp ⇒ Object
515 516 517 518 519 |
# File 'lib/cisco_node_utils/interface.rb', line 515 def switchport_vtp return false unless switchport_vtp_mode_capable? vtp = @@node.config_get("interface", "vtp", @name) vtp.nil? ? false : true end |
#switchport_vtp=(vtp_set) ⇒ Object
521 522 523 524 525 526 527 |
# File 'lib/cisco_node_utils/interface.rb', line 521 def switchport_vtp=(vtp_set) return false unless switchport_vtp_mode_capable? no_cmd = (vtp_set) ? "" : "no" @@node.config_set("interface", "vtp", @name, no_cmd) rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |
#switchport_vtp_feature? ⇒ Boolean
579 580 581 |
# File 'lib/cisco_node_utils/interface.rb', line 579 def switchport_vtp_feature? @@node.config_get("vtp", "feature") end |
#switchport_vtp_mode_capable? ⇒ Boolean
511 512 513 |
# File 'lib/cisco_node_utils/interface.rb', line 511 def switchport_vtp_mode_capable? not switchport_mode.to_s.match(/(access|trunk)/).nil? end |
#system_default_svi_autostate ⇒ Object
504 505 506 507 508 509 |
# File 'lib/cisco_node_utils/interface.rb', line 504 def system_default_svi_autostate # This command is a user-configurable system default. sys_def = @@node.config_get("interface", "system_default_svi_autostate") sys_def.nil? ? false : true end |
#system_default_switchport ⇒ Object
491 492 493 494 495 |
# File 'lib/cisco_node_utils/interface.rb', line 491 def system_default_switchport # This command is a user-configurable system default. sys_def = @@node.config_get("interface", "system_default_switchport") sys_def.nil? ? false : true end |
#system_default_switchport_shutdown ⇒ Object
497 498 499 500 501 502 |
# File 'lib/cisco_node_utils/interface.rb', line 497 def system_default_switchport_shutdown # This command is a user-configurable system default. sys_def = @@node.config_get("interface", "system_default_switchport_shutdown") sys_def.nil? ? false : true end |
#vrf ⇒ Object
588 589 590 591 592 |
# File 'lib/cisco_node_utils/interface.rb', line 588 def vrf vrf = @@node.config_get("interface", "vrf", @name) return "" if vrf.nil? vrf.shift.strip end |
#vrf=(vrf) ⇒ Object
594 595 596 597 598 599 600 601 |
# File 'lib/cisco_node_utils/interface.rb', line 594 def vrf=(vrf) raise TypeError unless vrf.is_a?(String) vrf.empty? ? @@node.config_set("interface", "vrf", @name, "no", "") : @@node.config_set("interface", "vrf", @name, "", vrf) rescue Cisco::CliError => e raise "[#{@name}] '#{e.command}' : #{e.clierror}" end |