class Rbeapi::Api::StpInterfaces
The StpInterfaces
class provides a class instance for working with spanning-tree interfaces in EOS.
Public Instance Methods
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.
@example
{ portfast: <boolean>, portfast_type: <string>, bpduguard: <boolean> }
@param name [String] The interface name to return a resource for from
the nodes configuration.
@return [nil, Hash<Symbol, Object>] Returns the stp interface as a
resource hash.
# File lib/rbeapi/api/stp.rb, line 298 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 returns all of the configured stp interfaces parsed from the nodes current running configuration. The returned hash is keyed by the interface name.
@example
{ <name>: { portfast: <boolean>, portfast_type: <string>, bpduguard: <boolean> }, <name>: { portfast: <boolean>, portfast_type: <string>, bpduguard: <boolean> }, ... }
@return [Hash<Symbol, Object>] Returns the stp interfaces config as a
resource hash from the nodes running configuration.
# File lib/rbeapi/api/stp.rb, line 331 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
Configures the interface bpdu guard value
@param name [String] The name of the interface to configure.
@param opts [Hash] The configuration parameters for bpduguard.
@option opts value [Boolean] The value to set bpduguard.
@option opts enable [Boolean] If false then the bpduguard is
disabled. If true then the bpduguard is enabled. Default is true.
@option opts default [Boolean] The value should be set to default.
@return [Boolean] True if the commands succeed otherwise False.
# File lib/rbeapi/api/stp.rb, line 458 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 cmds = if enable 'spanning-tree bpduguard enable' else 'spanning-tree bpduguard disable' end end configure_interface(name, cmds) end
Configures the interface portfast value.
@param name [String] The name of the interface to configure.
@param opts [Hash] The configuration parameters for portfast.
@option opts value [Boolean] The value to set portfast.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] The value should be set to default.
@return [Boolean] True if the commands succeed otherwise False.
# File lib/rbeapi/api/stp.rb, line 403 def set_portfast(name, opts = {}) cmd = command_builder('spanning-tree portfast', opts) configure_interface(name, cmd) end
Configures the interface portfast type value
@param name [String] The name of the interface to configure.
@param opts [Hash] The configuration parameters for portfast type.
@option opts value [String] The value to set portfast type to.
The value must be set for calls to this method.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] The value should be set to default.
@return [Boolean] True if the commands succeed otherwise False.
# File lib/rbeapi/api/stp.rb, line 424 def set_portfast_type(name, opts = {}) value = opts[:value] raise 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 cmds = if enable "spanning-tree portfast #{value}" else "no spanning-tree portfast #{value}" end end configure_interface(name, cmds) end
Private Instance Methods
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).
@api private
@return [Hash<Symbol, Object>] Resource hash attribute.
# File lib/rbeapi/api/stp.rb, line 382 def parse_bpduguard(config) val = /spanning-tree bpduguard enable/ =~ config { bpduguard: !val.nil? } end
parse_portfast
scans the supplied interface configuration block and parses the value stp portfast. The value of portfast is either enabled (true) or disabled (false).
@api private
@return [Hash<Symbol, Object>] Resource hash attribute.
# File lib/rbeapi/api/stp.rb, line 348 def parse_portfast(config) val = /no spanning-tree portfast/ =~ config { portfast: val.nil? } end
parse_portfast_type
scans the supplied interface configuration block and parses the value stp portfast type. The value of portfast type is either not set which implies normal (default), edge, or network.
@api private
@return [Hash<Symbol, Object>] Resource hash attribute.
# File lib/rbeapi/api/stp.rb, line 362 def parse_portfast_type(config) value = if /spanning-tree portfast network/ =~ config 'network' elsif /no spanning-tree portfast/ =~ config 'normal' else 'edge' end { portfast_type: value } end