class Rbeapi::Api::Stp

The Stp class provides a base class instance for working with the EOS spanning-tree configuration.

Public Instance Methods

get() click to toggle source

get returns the current stp configuration parsed from the nodes current running configuration.

@example

{
  mode: <string>
  instances: {
    <string>: {
      priority: <string>
    }
  }
  interfaces: {
    <name>: {
      portfast: <boolean>,
      portfast_type: <string>,
      bpduguard: <boolean>
    }
  }
}

@return [Hash] returns a Hash of attributes derived from eAPI.

# File lib/rbeapi/api/stp.rb, line 66
def get
  response = {}
  response.merge!(parse_mode)
  response[:instances] = instances.getall
  response[:interfaces] = interfaces.getall
  response
end
instances() click to toggle source

instances returns a memoized instance of StpInstances for configuring individual stp instances.

@return [StpInstances] an instance of StpInstances class.

# File lib/rbeapi/api/stp.rb, line 93
def instances
  return @instances if @instances
  @instances = StpInstances.new(node)
  @instances
end
interfaces() click to toggle source

interfaces returns a memoized instance of StpInterfaces for configuring individual stp interfaces.

@return [StpInterfaces] an instance of StpInterfaces class.

# File lib/rbeapi/api/stp.rb, line 104
def interfaces
  return @interfaces if @interfaces
  @interfaces = StpInterfaces.new(node)
  @interfaces
end
parse_mode() click to toggle source

parse_mode scans the nodes running configuration and extracts the value of the spanning-tree mode. The spanning tree mode is expected to be always be available in the running config. The return value is intended to be merged into the stp resource hash.

@api private

@return [Hash<Symbol, Object>] Resource hash attribute.

# File lib/rbeapi/api/stp.rb, line 83
def parse_mode
  mdata = /(?<=spanning-tree\smode\s)(\w+)$/.match(config)
  { mode: mdata[1] }
end
set_mode(opts = {}) click to toggle source

set_mode configures the stp mode in the global nodes running configuration. If the enable option is false, then the stp mode is configured with the no keyword argument. If the default option is specified then the mode is configured with the default keyword argument. The default keyword argument takes precedence over the enable option if both are provided.

@since eos_version 4.13.7M

Commands

spanning-tree mode <value>
no spanning-tree mode
default spanning-tree mode

@param opts [Hash] Optional keyword arguments.

@option opts value [String] The value to configure the stp mode to

in the nodes current running configuration.

@option opts enable [Boolean] If false then the command is

negated. Default is true.

@option opts default [Boolean] Configure the stp mode value using

the default keyword.

@return [Boolean] returns true if the command completed successfully.

# File lib/rbeapi/api/stp.rb, line 138
def set_mode(opts = {})
  cmd = command_builder('spanning-tree mode', opts)
  configure cmd
end