Class: Rbeapi::Api::MlagInterfaces
- Defined in:
- lib/rbeapi/api/mlag.rb
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#create(name, id) ⇒ Boolean
create adds a new mlag interface to the nodes current running configuration.
-
#default(name) ⇒ Boolean
default configures a mlag interface using the default keyword.
-
#delete(name) ⇒ Boolean
delete removes a mlag interface from the nodes current running configuration.
-
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns the mlag interface configuration as a hash object.
-
#getall ⇒ Hash<String, Hash>
getall scans the nodes current running configuration and returns a hash of all mlag interfaces keyed by the interface name.
-
#set_mlag_id(name, opts = {}) ⇒ Boolean
set_mlag_id configures the mlag id on the interface in the nodes current 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
#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.
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
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
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
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 |
#getall ⇒ Hash<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
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
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 |