Class: Rbeapi::Api::Alias
Overview
The Alias class manages aliass entries on an EOS node.
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#create(name, opts = {}) ⇒ Boolean
create will create a alias entry in the nodes current configuration with the specified address.
-
#delete(name) ⇒ Boolean
delete will delete an existing alias entry from the nodes current running configuration.
-
#get(name) ⇒ Hash<Symbol, Object>
get returns the current alias configuration hash extracted from the nodes running configuration.
-
#getall ⇒ Hash<Symbol, Object>
getall returns a collection of alias resource hashes from the nodes running configuration.
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>
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>
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.
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 |
#getall ⇒ Hash<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.
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 |