Class: Rbeapi::Api::Alias

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

Overview

The Alias class manages aliass entries on an EOS node.

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

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

create will create a alias entry in the nodes current configuration with the specified address.

Commands

alias <name> <address>

Parameters:

  • name (String)

    The name of the alias.

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

    Optional keyword arguments.

Options Hash (opts):

  • command (String)

    Configures the alias ip address

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Raises:

  • (ArgumentError)

Since:

  • eos_version 4.13.7M



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/rbeapi/api/alias.rb', line 129

def create(name, opts = {})
  raise ArgumentError, 'a command must be provided' unless \
      opts[:command] =~ /.+/
  command = opts.fetch(:command)
  cmd = ["alias #{name} "]
  if command =~ /\\n/
    command.split('\\n').each { |a| cmd << a }
  else
    cmd[0] << command
  end
  configure(cmd)
end

#delete(name) ⇒ Boolean

delete will delete an existing alias entry from the nodes current running configuration. If the delete method is called and the alias entry does not exist, this method will succeed.

Commands

no alias <name>

Parameters:

  • name (String)

    The alias name entry to delete from the node.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



155
156
157
# File 'lib/rbeapi/api/alias.rb', line 155

def delete(name)
  configure("no alias #{name}")
end

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

get returns the current alias configuration hash extracted from the nodes running configuration.

Examples:

{
  alias: array<strings>
}

Returns:

  • (Hash<Symbol, Object>)

    Returns the alias resource as a hash object from the nodes current configuration.



54
55
56
57
58
59
60
61
62
63
# File 'lib/rbeapi/api/alias.rb', line 54

def get(name)
  # Complex regex handles the following cases:
  #  All aliases start with 'alian <name>' followed by
  #    <space><single-line command>
  #    <carriage return><multiple lines of commands>
  pattern = /^alias #{name}((?:(?= )(?:.+?)(?=\n)|\n(?:.+?)(?=\n\!)))/m
  aliases = config.scan(pattern)
  return nil unless aliases[0]
  parse_alias_entry(name, aliases[0])
end

#getallHash<Symbol, Object>

getall returns a collection of alias resource hashes from the nodes running configuration. The alias resource collection hash is keyed by the unique alias name.

Examples:

[
  <alias>: {
    command: <string>
  },
  <alias>: {
    command: <string>
  },
  ...
]

Returns:

  • (Hash<Symbol, Object>)

    Returns a hash that represents the entire alias collection from the nodes running configuration. If there are no aliass configured, this method will return an empty hash.



85
86
87
88
89
90
91
92
93
# File 'lib/rbeapi/api/alias.rb', line 85

def getall
  entries = config.scan(/^alias (\w+)(.+)?/)
  entries.inspect
  response = {}
  entries.each do |aliases|
    response[aliases[0]] = get aliases[0]
  end
  response
end