Class: PuppetX::Eos::Ipinterface

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/eos/modules/ipinterface.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ Ipinterface

Returns a new instance of Ipinterface.



43
44
45
# File 'lib/puppet_x/eos/modules/ipinterface.rb', line 43

def initialize(api)
  @api = api
end

Instance Method Details

#create(name) ⇒ Boolean

Create a new logical IP interface in the running-config

Parameters:

  • name (String)

    The name of the interface

Returns:

  • (Boolean)

    True if the create succeeds otherwise False



95
96
97
# File 'lib/puppet_x/eos/modules/ipinterface.rb', line 95

def create(name)
  @api.config(["interface #{name}", 'no switchport']) == [{}, {}]
end

#delete(name) ⇒ Boolean

Deletes a logical IP interface from the running-config

Parameters:

  • name (String)

    The name of the interface

Returns:

  • (Boolean)

    True if the create succeeds otherwise False



105
106
107
# File 'lib/puppet_x/eos/modules/ipinterface.rb', line 105

def delete(name)
  @api.config(["interface #{name}", 'no ip address']) == [{}, {}]
end

#getallHash

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": { ... }
  }
}

Returns:

  • (Hash)


85
86
87
# File 'lib/puppet_x/eos/modules/ipinterface.rb', line 85

def getall
  @api.enable('show ip interface')
end

#set_address(name, opts = {}) ⇒ Boolean

Configures the IP address and mask length for the interface

Parameters:

  • name (String)

    The name of the interface to configure

  • opts (Hash) (defaults to: {})

    The configuration parameters for the interface

Options Hash (opts):

  • :value (string)

    The value to set the address to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



118
119
120
121
122
123
124
125
126
127
128
129
130
# 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