Class: Rbeapi::Api::MlagInterfaces

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

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

#create(name, id) ⇒ Boolean

create adds a new mlag interface to the nodes current running configuration. If the specified interface already exists, then this method will return successfully with the updated mlag id.

Parameters:

  • :name (String)

    The name of of the interface to create. The name must be the full interface name. The value of name is expected to be a Port-Channel interface.

  • :id (String, Integer)

    The value of the mlag id to configure for the specified interface. Valid mlag ids are in the range of 1 to 2000.

Returns:

  • (Boolean)

    returns true if the command completed successfully

See Also:



441
442
443
# File 'lib/rbeapi/api/mlag.rb', line 441

def create(name, id)
  set_mlag_id(name, value: id)
end

#default(name) ⇒ Boolean

default configures a mlag interface using the default keyword. If the specified interface does not exist as a mlag interface this method will return successfully

Parameters:

  • :name (String)

    The name of of the interface to create. The name must be the full interface name.

Returns:

  • (Boolean)

    returns true if the command completed successfully

See Also:



471
472
473
# File 'lib/rbeapi/api/mlag.rb', line 471

def default(name)
  set_mlag_id(name, default: true)
end

#delete(name) ⇒ Boolean

delete removes a mlag interface from the nodes current running configuration. If the specified interface does not exist as a mlag interface this method will return successfully

Parameters:

  • :name (String)

    The name of of the interface to remove. The name must be the full interface name.

Returns:

  • (Boolean)

    returns true if the command completed successfully

See Also:



456
457
458
# File 'lib/rbeapi/api/mlag.rb', line 456

def delete(name)
  set_mlag_id(name)
end

#get(name) ⇒ nil, Hash<Symbol, Object>

get returns the mlag interface configuration as a hash object. If the specified interface name is not configured as an mlag interface this method will return nil

Examples:

{
  mlag_id: <string>
}

Parameters:

  • :name (String)

    The full interface name of the interface to return the mlag interface hash for.

Returns:

  • (nil, Hash<Symbol, Object>)

    returns the interface configuration as a resource hash. If the interface is not configured as an mlag interface nil is returned.



400
401
402
403
404
405
406
# File 'lib/rbeapi/api/mlag.rb', line 400

def get(name)
  config = get_block("^interface #{name}")
  return nil unless config
  mdata = /(?<=\s{3}mlag\s)(.+)$/.match(config)
  return nil unless mdata
  { mlag_id: mdata[1] }
end

#getallHash<String, Hash>

getall scans the nodes current running configuration and returns a hash of all mlag interfaces keyed by the interface name. If no interfaces are configured, an empty hash object is returned

Returns:

  • (Hash<String, Hash>)

    returns the nodes mlag interface configurations as a hash

See Also:



417
418
419
420
421
422
423
# File 'lib/rbeapi/api/mlag.rb', line 417

def getall
  names = config.scan(/(?<=^interface\s)Po.+/)
  names.each_with_object({}) do |name, response|
    data = get name
    response[name] = data if data
  end
end

#set_mlag_id(name, opts = {}) ⇒ Boolean

set_mlag_id configures the mlag id on the interface in the nodes current running configuration. If the value is not specified, then the interface mlag id is configured using the no keyword. If the default keyword is provided and set to true, the interface mlag id is configured using the default keyword. The default keyword takes precedence over the value keyword if both options are specified

Parameters:

  • :name (String)

    The full interface identifier of the interface to confgure th mlag id for.

  • :opts (Hash)

    Optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully



504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/rbeapi/api/mlag.rb', line 504

def set_mlag_id(name, opts = {})
  value = opts[:value]
  default = opts[:default] || false

  cmds = ["interface #{name}"]
  case default
  when true
    cmds << 'default mlag'
  when false
    cmds << (value ? "mlag #{value}"  : 'no mlag')
  end
  configure(cmds)
end