Class: Rbeapi::Api::Ipinterfaces
- Defined in:
- lib/rbeapi/api/ipinterfaces.rb
Overview
The Ipinterface class provides an instance for managing logical IP interfaces configured using eAPI.
Constant Summary collapse
- DEFAULT_ADDRESS =
''
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#create(name) ⇒ Boolean
create will create a new IP interface on the node.
-
#delete(name) ⇒ Boolean
delete will delete an existing IP interface in the node’s current configuration.
-
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns a resource hash that represents the configuration of the IP interface from the nodes running configuration.
-
#getall ⇒ Hash<Symbol, Object>
getall returns a hash object that represents all ip interfaces configured on the node from the current running configuration.
-
#set_address(name, opts = {}) ⇒ Boolean
set_address configures a logical IP interface with an address.
-
#set_helper_addresses(name, opts = {}) ⇒ Object
set_helper_addresses configures the list of helper addresses on the ip interface.
-
#set_mtu(name, opts = {}) ⇒ Boolean
set_mtu configures the IP mtu value of the ip interface in the nodes 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) ⇒ Boolean
create will create a new IP interface on the node. If the ip interface already exists in the configuration, this method will still return successful. This method will cause an existing layer 2 interface (switchport) to be deleted if it exists in the node’s configuration.
171 172 173 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 171 def create(name) configure(["interface #{name}", 'no switchport']) end |
#delete(name) ⇒ Boolean
delete will delete an existing IP interface in the node’s current configuration. If the IP interface does not exist on the specified interface, this method will still return success. This command will default the interface back to being a switchport.
192 193 194 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 192 def delete(name) configure(["interface #{name}", 'no ip address', 'switchport']) end |
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns a resource hash that represents the configuration of the IP interface from the nodes running configuration.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 64 def get(name) config = get_block("interface #{name}") return nil unless config return nil if /\s{3}switchport$/ =~ config response = {} response.merge!(parse_address(config)) response.merge!(parse_mtu(config)) response.merge!(parse_helper_addresses(config)) response end |
#getall ⇒ Hash<Symbol, Object>
getall returns a hash object that represents all ip interfaces configured on the node from the current running configuration.
90 91 92 93 94 95 96 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 90 def getall interfaces = config.scan(/(?<=^interface\s).+/) interfaces.each_with_object({}) do |name, hsh| values = get name hsh[name] = values if values end end |
#set_address(name, opts = {}) ⇒ Boolean
set_address configures a logical IP interface with an address. The address value must be in the form of A.B.C.D/E. If the enable keyword is false, then the interface address is negated using the config no keyword. If the default option is set to true, then the ip address # value is defaulted using the default keyword. The default keyword has precedence over the enable keyword if both options are specified
229 230 231 232 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 229 def set_address(name, opts = {}) cmds = command_builder('ip address', opts) configure_interface(name, cmds) end |
#set_helper_addresses(name, opts = {}) ⇒ Object
set_helper_addresses configures the list of helper addresses on the ip interface. An IP interface can have one or more helper addresses configured. If no value is provided, the helper address configuration is set using the no keyword. If the default option is specified and set to true, then the helper address values are defaulted using the default keyword.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 299 def set_helper_addresses(name, opts = {}) value = opts[:value] enable = opts.fetch(:enable, true) default = opts[:default] || false case default when true cmds = 'default ip helper-address' when false cmds = ['no ip helper-address'] value.each { |addr| cmds << "ip helper-address #{addr}" } if enable end configure_interface(name, cmds) end |
#set_mtu(name, opts = {}) ⇒ Boolean
set_mtu configures the IP mtu value of the ip interface in the nodes configuration. If the enable option is false, then the ip mtu value is configured using the no keyword. If the default keyword option is provided and set to true then the ip mtu value is configured using the default keyword. The default keyword has precedence over the enable keyword if both options are specified.
266 267 268 269 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 266 def set_mtu(name, opts = {}) cmds = command_builder('mtu', opts) configure_interface(name, cmds) end |