Class: Rbeapi::Api::StpInstances

Inherits:
Entity
  • Object
show all
Defined in:
lib/rbeapi/api/stp.rb

Overview

The StpInstances class provides a class instance for working with spanning-tree instances in EOS

Constant Summary collapse

DEFAULT_STP_PRIORITY =
'32768'.freeze

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

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

#delete(inst) ⇒ Boolean

Deletes a configured MST instance.

Parameters:

  • inst (String)

    The MST instance to delete.

Returns:

  • (Boolean)

    True if the commands succeed otherwise False.



237
238
239
240
# File 'lib/rbeapi/api/stp.rb', line 237

def delete(inst)
  configure ['spanning-tree mst configuration', "no instance #{inst}",
             'exit']
end

#get(inst) ⇒ nil, Hash<Symbol, Object] Returns the stp instance config as a resource hash. If the instances is not configured this method will return a nil object.

get returns the specified stp instance config parsed from the nodes current running configuration.

Examples:

{
  priority: <string>
}

Parameters:

  • inst (String)

    The named stp instance to return.

Returns:

  • (nil, Hash<Symbol, Object] Returns the stp instance config as a resource hash. If the instances is not configured this method will return a nil object.)

    nil, Hash<Symbol, Object] Returns the stp instance config as a resource hash. If the instances is not configured this method will return a nil object.



165
166
167
168
169
170
# File 'lib/rbeapi/api/stp.rb', line 165

def get(inst)
  return nil unless parse_instances.include?(inst.to_s)
  response = {}
  response.merge!(parse_priority(inst))
  response
end

#getallHash<Symbol, Object>

getall returns all configured stp instances parsed from the nodes running configuration. The return hash is keyed by the instance identifier value.

Examples:

{
  <inst>: {
    priority: <string>
  },
  <inst>: {
    priority: <string>
  },
  ...
}

Returns:

  • (Hash<Symbol, Object>)

    Returns all configured stp instances found in the nodes running configuration.



190
191
192
193
194
195
# File 'lib/rbeapi/api/stp.rb', line 190

def getall
  parse_instances.each_with_object({}) do |inst, hsh|
    values = get(inst)
    hsh[inst] = values if values
  end
end

#set_priority(inst, opts = {}) ⇒ Boolean

Configures the spanning-tree MST priority.

Parameters:

  • inst (String)

    The MST instance to configure.

  • opts (Hash) (defaults to: {})

    The configuration parameters for the priority.

Options Hash (opts):

  • value (string)

    The value to set the priority to.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    The value should be set to default.

Returns:

  • (Boolean)

    True if the commands succeed otherwise False.



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/rbeapi/api/stp.rb', line 257

def set_priority(inst, opts = {})
  value = opts[:value]
  enable = opts.fetch(:enable, true)
  default = opts[:default] || false

  case default
  when true
    cmd = "default spanning-tree mst #{inst} priority"
  when false
    cmd = if enable
            "spanning-tree mst #{inst} priority #{value}"
          else
            "no spanning-tree mst #{inst} priority"
          end
  end
  configure cmd
end