class PuppetX::Eos::Ipinterface

The Ipinterface class provides an instance for managing logical IP interfaces configured using eAPI.

Public Class Methods

new(api) click to toggle source
# File lib/puppet_x/eos/modules/ipinterface.rb, line 43
def initialize(api)
  @api = api
end

Public Instance Methods

create(name) click to toggle source

Create a new logical IP interface in the running-config

@param [String] name The name of the interface

@return [Boolean] True if the create succeeds otherwise False

# File lib/puppet_x/eos/modules/ipinterface.rb, line 95
def create(name)
  @api.config(["interface #{name}", 'no switchport']) == [{}, {}]
end
delete(name) click to toggle source

Deletes a logical IP interface from the running-config

@param [String] name The name of the interface

@return [Boolean] True if the create succeeds otherwise False

# File lib/puppet_x/eos/modules/ipinterface.rb, line 105
def delete(name)
  @api.config(["interface #{name}", 'no ip address']) == [{}, {}]
end
getall() click to toggle source

Retrieves all logical IP interfaces from the running-configuration and returns all instances

Example:

{
  "interfaces": {
    "Ethernet1": {
        "interfaceAddress": {
           "secondaryIpsOrderedList": [],
           "broadcastAddress": "255.255.255.255",
           "secondaryIps": {},
           "primaryIp": {
              "maskLen": 32,
              "address": "1.1.1.1"
           },
           "virtualIp": {
              "maskLen": 0,
              "address": "0.0.0.0"
           }
        },
        "name": "Loopback0",
        "urpf": "disable",
        "interfaceStatus": "connected",
        "enabled": true,
        "mtu": 65535,
        "vrf": "default",
        "localProxyArp": false,
        "proxyArp": false,
        "lineProtocolStatus": "up",
        "description": "managed by PE"
    },
    "Ethernet2": { ... },
    "Ethernet3": { ... }
  }
}

@return [Hash]

# File lib/puppet_x/eos/modules/ipinterface.rb, line 85
def getall
  @api.enable('show ip interface')
end
set_address(name, opts = {}) click to toggle source
Configures the IP address and mask length for the interface

@param [String] name The name of the interface to configure @param [Hash] opts The configuration parameters for the interface @option opts [string] :value The value to set the address to @option opts [Boolean] :default The value should be set to default

@return [Boolean] True if the commands succeed otherwise False

# File lib/puppet_x/eos/modules/ipinterface.rb, line 118
def set_address(name, opts = {})
  value = opts[:value]
  default = opts[:default] || false

  cmds = ["interface #{name}"]
  case default
  when true
    cmds << 'default ip address'
  when false
    cmds << (value.nil? ? 'no ip address' : "ip address #{value}")
  end
  @api.config(cmds) == [{}, {}]
end