Class: Rbeapi::Api::StpInterfaces
- Defined in:
- lib/rbeapi/api/stp.rb
Overview
The StpInterfaces class provides a class instance for working with spanning-tree interfaces in EOS
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns the configured stp interfaces from the nodes running configuration as a resource hash.
-
#getall ⇒ Hash<Symbol, Object>
getall returns all of the configured stp interfaces parsed from the nodes current running configuration.
-
#set_bpduguard(name, opts = {}) ⇒ Boolean
Configures the interface bpdu guard value.
-
#set_portfast(name, opts = {}) ⇒ Boolean
Configures the interface portfast value.
-
#set_portfast_type(name, opts = {}) ⇒ Boolean
Configures the interface portfast type value.
Methods inherited from Entity
#command_builder, #configure, #configure_interface, #get_block, #initialize, instance
Constructor Details
This class inherits a constructor from Rbeapi::Api::Entity
Instance Method Details
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns the configured stp interfaces from the nodes running configuration as a resource hash. If the specified interface is not configured as a switchport then this method will return nil
274 275 276 277 278 279 280 281 282 283 |
# File 'lib/rbeapi/api/stp.rb', line 274 def get(name) config = get_block("interface #{name}") return nil unless config return nil if /no switchport$/ =~ config response = {} response.merge!(parse_portfast(config)) response.merge!(parse_portfast_type(config)) response.merge!(parse_bpduguard(config)) response end |
#getall ⇒ Hash<Symbol, Object>
getall returns all of the configured stp interfaces parsed from the nodes current running configuration. The returned hash is keyed by the interface name
299 300 301 302 303 304 305 306 |
# File 'lib/rbeapi/api/stp.rb', line 299 def getall interfaces = config.scan(/(?<=^interface\s)[Et|Po].+/) resp = interfaces.each_with_object({}) do |name, hsh| values = get(name) hsh[name] = values if values end resp end |
#set_bpduguard(name, opts = {}) ⇒ Boolean
Configures the interface bpdu guard value
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/rbeapi/api/stp.rb', line 414 def set_bpduguard(name, opts = {}) enable = opts.fetch(:enable, true) default = opts[:default] || false case default when true cmds = 'default spanning-tree bpduguard' when false if enable cmds = 'spanning-tree bpduguard enable' else cmds = 'spanning-tree bpduguard disable' end end configure_interface(name, cmds) end |
#set_portfast(name, opts = {}) ⇒ Boolean
Configures the interface portfast value
367 368 369 370 |
# File 'lib/rbeapi/api/stp.rb', line 367 def set_portfast(name, opts = {}) cmd = command_builder('spanning-tree portfast', opts) configure_interface(name, cmd) end |
#set_portfast_type(name, opts = {}) ⇒ Boolean
Configures the interface portfast type value
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/rbeapi/api/stp.rb', line 384 def set_portfast_type(name, opts = {}) value = opts[:value] fail ArgumentError, 'value must be set' unless value enable = opts.fetch(:enable, true) default = opts[:default] || false case default when true cmds = "default spanning-tree portfast #{value}" when false if enable cmds = "spanning-tree portfast #{value}" else cmds = "no spanning-tree portfast #{value}" end end configure_interface(name, cmds) end |