Class: Rbeapi::Api::Stp
Overview
The Stp class provides a base class instance for working with the EOS spanning-tree configuration
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#get ⇒ Hash
get returns the current stp configuration parsed from the nodes current running configuration.
-
#instances ⇒ StpInstances
instances returns a memoized instance of StpInstances for configuring individual stp instances.
-
#interfaces ⇒ StpInterfaces
interfaces rereturns a memoized instance of StpInterfaces for configuring individual stp interfaces.
-
#parse_mode ⇒ Hash<Symbol, Object>
private
parse_mode scans the nodes running configuration and extracts the value of the spanning-tree mode.
-
#set_mode(opts = {}) ⇒ Boolean
set_mode configures the stp mode in the global nodes running configuration.
Methods inherited from Entity
#configure, #get_block, #initialize, instance
Constructor Details
This class inherits a constructor from Rbeapi::Api::Entity
Instance Method Details
#get ⇒ Hash
get returns the current stp configuration parsed from the nodes current running configuration.
60 61 62 63 64 65 66 |
# File 'lib/rbeapi/api/stp.rb', line 60 def get response = {} response.merge!(parse_mode) response[:instances] = instances.getall response[:interfaces] = interfaces.getall response end |
#instances ⇒ StpInstances
instances returns a memoized instance of StpInstances for configuring individual stp instances.
88 89 90 91 92 |
# File 'lib/rbeapi/api/stp.rb', line 88 def instances return @instances if @instances @instances = StpInstances.new(node) @instances end |
#interfaces ⇒ StpInterfaces
interfaces rereturns a memoized instance of StpInterfaces for configuring individual stp interfaces
99 100 101 102 103 |
# File 'lib/rbeapi/api/stp.rb', line 99 def interfaces return @interfaces if @interfaces @interfaces = StpInterfaces.new(node) @interfaces end |
#parse_mode ⇒ 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_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 avaliable in the running config. The return value is intended to be merged into the stp resource hash
78 79 80 81 |
# File 'lib/rbeapi/api/stp.rb', line 78 def parse_mode mdata = /(?<=spanning-tree\smode\s)(\w+)$/.match(config) { mode: mdata[1] } end |
#set_mode(opts = {}) ⇒ Boolean
set_mode configures the stp mode in the global nodes running configuration. If the value option is not specified, 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 value option if both are provided
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/rbeapi/api/stp.rb', line 130 def set_mode(opts = {}) value = opts[:value] default = opts[:default] || false case default when true cmd = 'default spanning-tree mode' when false cmd = (value ? "spanning-tree mode #{value}" : \ 'no spanning-tree mode') end configure cmd end |