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 =
''.freeze
- DEFAULT_LOAD_INTERVAL =
''.freeze
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_load_interval(name, opts = {}) ⇒ Boolean
set_load_interval is a convenience function for configuring the value of interface load-interval.
-
#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.
Commands
interface <name>
no switchport
205 206 207 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 205 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.
Commands
interface <name>
no ip address
switchport
226 227 228 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 226 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.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 66 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.merge!(parse_load_interval(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.
105 106 107 108 109 110 111 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 105 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.
Commands
interface <name>
ip address <value>
no ip address
default ip address
263 264 265 266 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 263 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.
Commands
interface <name>
ip helper-address <value>
no ip helper-address
default ip helper-address
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 333 def set_helper_addresses(name, opts = {}) value = opts[:value] enable = opts.fetch(:enable, true) default = opts[:default] || false if value unless value.is_a?(Array) raise ArgumentError, 'value must be an Array' end end 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_load_interval(name, opts = {}) ⇒ Boolean
set_load_interval is a convenience function for configuring the value of interface load-interval
values to. The name must be the full interface identifier.
load-interval setting for. Valid values are between 5 and 600.
the interface using the default keyword.
370 371 372 373 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 370 def set_load_interval(name, opts = {}) cmds = command_builder('load-interval', opts) 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.
Commands
interface <name>
mtu <value>
no mtu
default mtu
300 301 302 303 |
# File 'lib/rbeapi/api/ipinterfaces.rb', line 300 def set_mtu(name, opts = {}) cmds = command_builder('mtu', opts) configure_interface(name, cmds) end |