Class: Rbeapi::Api::Iphosts
Overview
The Iphosts class manages hosts entries on an EOS node.
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#create(name, opts = {}) ⇒ Boolean
create will create a ip host entry in the nodes current configuration with the specified address.
-
#delete(name) ⇒ Boolean
delete will delete an existing ip host entry from the nodes current running configuration.
-
#get(name) ⇒ Hash<Symbol, Object>
get returns the current ip host configuration hash extracted from the nodes running configuration.
-
#getall ⇒ Hash<Symbol, Object>
getall returns a collection of ip host 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 ip host entry in the nodes current configuration with the specified address.
Commands
ip host <name> <address>
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rbeapi/api/iphosts.rb', line 122 def create(name, opts = {}) ipaddress = opts.fetch(:ipaddress, NIL) # rubocop:disable Style/GuardClause, Style/ClassCheck if ipaddress.kind_of?(Array) if ipaddress.all? { |x| x =~ /(\w+\.\d+\.\d+\.\d+)/ } ips = opts[:ipaddress].join(' ') cmd = "ip host #{name} #{ips}" configure(cmd) else fail ArgumentError, 'option ipaddress must be a valid IP' end else fail ArgumentError, 'no argument given' end # rubocop:enable Style/GuardClause, Style/ClassCheck end |
#delete(name) ⇒ Boolean
delete will delete an existing ip host entry from the nodes current running configuration. If the delete method is called and the host entry does not exist, this method will succeed.
Commands
no ip host <name>
152 153 154 |
# File 'lib/rbeapi/api/iphosts.rb', line 152 def delete(name) configure("no ip host #{name}") end |
#get(name) ⇒ Hash<Symbol, Object>
get returns the current ip host configuration hash extracted from the nodes running configuration.
54 55 56 57 58 |
# File 'lib/rbeapi/api/iphosts.rb', line 54 def get(name) iphost = config.scan(/^ip host #{name} ((?:\d+\.\d+\.\d+\.\d+[ ]?)*)/) return nil unless iphost && iphost[0] parse_host_entry(name, iphost[0]) end |
#getall ⇒ Hash<Symbol, Object>
getall returns a collection of ip host resource hashes from the nodes running configuration. The ip host resource collection hash is keyed by the unique host name.
80 81 82 83 84 85 86 87 |
# File 'lib/rbeapi/api/iphosts.rb', line 80 def getall entries = config.scan(/^ip host ([^\s]+) (\d+\.\d+\.\d+\.\d+)/) response = {} entries.each do |host| response[host[0]] = get host[0] end response end |