Class: PuppetX::Eos::Interface

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

Overview

The Interface class provides a base class instance for working with physical and logical interfaces.

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ PuppetX::Eos::Interface

Initialize instance of Interface

Parameters:



50
51
52
# File 'lib/puppet_x/eos/modules/interface.rb', line 50

def initialize(api)
  @api = api
end

Instance Method Details

#create(name) ⇒ Boolean

Creates a new logical interface on the node.

Parameters:

  • name (String)

    The name of the logical interface. It must be a full valid EOS interface name (ie Ethernet, not Et)

Returns:

  • (Boolean)

    True if the command succeeds or False if the command fails or is not supported (for instance trying to create a physical interface that already exists)



89
90
91
92
# File 'lib/puppet_x/eos/modules/interface.rb', line 89

def create(name)
  return false if name.match(/^[Et|Ma]/)
  @api.config("interface #{name}") == [{}]
end

#default(name) ⇒ Boolean

Configures the interface object back to system wide defaults using the EOS command api

Parameters:

  • name (String)

    The name of the interface

Returns:

  • (Boolean)

    True if it succeeds otherwise False



76
77
78
# File 'lib/puppet_x/eos/modules/interface.rb', line 76

def default(name)
  @api.config("default interface #{name}") == [{}]
end

#delete(name) ⇒ Boolean

Deletes an existing logical interface.

Parameters:

  • name (String)

    The name of the interface. It must be a full valid EOS interface name (ie Vlan, not Vl)

Returns:

  • (Boolean)

    True if the command succeeds or False if the command fails or is not supported (for instance trying to delete a physical interface)



103
104
105
106
# File 'lib/puppet_x/eos/modules/interface.rb', line 103

def delete(name)
  return false if name.match(/^[Et|Ma]/)
  @api.config("no interface #{name}") == [{}]
end

#getallArray<Hash>

Returns the base interface hash representing physical and logical interfaces in EOS using eAPI

Example

[{
  "interfaces": {...},
  "interfaceFlowControls": {...}
}]

Returns:

  • (Array<Hash>)

    returns an Array of Hashes



65
66
67
# File 'lib/puppet_x/eos/modules/interface.rb', line 65

def getall
  @api.enable(['show interfaces', 'show interfaces flowcontrol'])
end

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

Configures the interface description

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 description to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/puppet_x/eos/modules/interface.rb', line 140

def set_description(name, opts = {})
  value = opts[:value]
  default = opts[:default] || false

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

#set_flowcontrol(name, direction, opts = {}) ⇒ Boolean

Configures the interface flowcontrol

Parameters:

  • name (String)

    The name of the interface to configure

  • direction (String)

    One of tx or rx

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

    The configuration parameters for the interface

Options Hash (opts):

  • :value (string)

    The value to set the description to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/puppet_x/eos/modules/interface.rb', line 164

def set_flowcontrol(name, direction, opts = {})
  value = opts[:value]
  default = opts[:default] || false

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

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

Configures the interface shutdown state

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 state to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/puppet_x/eos/modules/interface.rb', line 117

def set_shutdown(name, opts = {})
  value = opts[:value] || false
  default = opts[:default] || false

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