Class: Rbeapi::Api::StpInterfaces
- Defined in:
- lib/rbeapi/api/stp.rb
Overview
The StpInterfaces class provides a class instance for working with spanning-tree insterfaces 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.
-
#parse_bpduguard(config) ⇒ Hash<Symbol, Object>
private
parse_bpduguard scans the supplied interface configuration block and parses the value of stp bpduguard.
- #set_bpduguard(name, opts = {}) ⇒ Object
-
#set_portfast(name, opts = {}) ⇒ Boolean
Configures the interface portfast value.
Methods inherited from Entity
#configure, #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
281 282 283 284 285 286 287 288 289 |
# File 'lib/rbeapi/api/stp.rb', line 281 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_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
305 306 307 308 309 310 311 312 |
# File 'lib/rbeapi/api/stp.rb', line 305 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 |
#parse_bpduguard(config) ⇒ Hash<Symbol, Object>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
parse_bpduguard scans the supplied interface configuration block and parses the value of stp bpduguard. The value of bpduguard is either disabled (false) or enabled (true)
336 337 338 339 |
# File 'lib/rbeapi/api/stp.rb', line 336 def parse_bpduguard(config) val = /spanning-tree bpduguard enable/ =~ config { bpduguard: !val.nil? } end |
#set_bpduguard(name, opts = {}) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/rbeapi/api/stp.rb', line 365 def set_bpduguard(name, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["interface #{name}"] case default when true cmds << 'default spanning-tree bpduguard' when false cmds << (value ? 'spanning-tree bpduguard enable' : 'spanning-tree bpduguard disable') end configure(cmds) end |
#set_portfast(name, opts = {}) ⇒ Boolean
Configures the interface portfast value
350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/rbeapi/api/stp.rb', line 350 def set_portfast(name, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["interface #{name}"] case default when true cmds << 'default spanning-tree portfast' when false cmds << (value ? 'spanning-tree portfast' : 'no spanning-tree portfast') end configure(cmds) end |