Class: Rbeapi::Api::StpInterfaces

Inherits:
Entity
  • Object
show all
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

#config, #error, #node

Instance Method Summary collapse

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

Examples:

{
  portfast: [true, false]
  bpduguard: [true, false]
}

Returns:

  • (nil, Hash<Symbol, Object>)

    returns the stp interface as a resource hash


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

#getallHash<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

Examples:

{
  <interface>: {...}
}

Returns:

  • (Hash<Symbol, Object>)

    returns the stp interfaces config as a resource hash from the nodes running configuration

See Also:


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)

Returns:

  • (Hash<Symbol, Object>)

    resource hash attribute


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

Parameters:

  • name (String)

    The name of the interface to configure

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

    The configuration parameters for portfast

Options Hash (opts):

  • :value (Boolean)

    The value to set portfast

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False


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