Class: PuppetX::Eos::Vlan

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

Overview

The Vlan class provides an interface for working wit VLAN resources in EOS. All configuration is sent and received using eAPI. In order to use this class, eAPI must be enablined in EOS. This class can be instatiated either using the Eos::Eapi::Switch.load_class method or used directly.

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ Vlan

Returns a new instance of Vlan.



47
48
49
# File 'lib/puppet_x/eos/modules/vlan.rb', line 47

def initialize(api)
  @api = api
end

Instance Method Details

#create(id) ⇒ Boolean

Adds a new VLAN resource in EOS setting the VLAN ID to id. The VLAN ID must be in the valid range of 1 through 4094

Parameters:

  • id (String)

    The VLAN identifier (e.g. 1)

Returns:

  • (Boolean)

    returns true if the command completed successfully



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

def create(id)
  @api.config("vlan #{id}") == [{}]
end

#default(id) ⇒ Boolean

Defaults an existing VLAN resource in EOS as specified by ID. If the supplied VLAN ID does not exist no error is raised. Note: setting a vlan to default is equivalent to negating it

Parameters:

  • id (String)

    The VLAN identifier (e.g. 1)

Returns:

  • (Boolean)

    returns true if the command completed successfully



99
100
101
# File 'lib/puppet_x/eos/modules/vlan.rb', line 99

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

#delete(id) ⇒ Boolean

Deletes an existing VLAN resource in EOS as specified by ID. If the supplied VLAN ID does not exist no error is raised

Parameters:

  • id (String)

    The VLAN identifier (e.g. 1)

Returns:

  • (Boolean)

    always returns true



87
88
89
# File 'lib/puppet_x/eos/modules/vlan.rb', line 87

def delete(id)
  @api.config("no vlan #{id}") == [{}]
end

#getallnil, Hash<String, String|Hash|Array>

Returns the vlan data for the provided id with the show vlan <id> command. If the id doesn’t exist then nil is returned

Example:

[
  { "sourceDetail": <string>, "vlans": {...} },
  { "trunkGroups": {...} }
]

Returns:

  • (nil, Hash<String, String|Hash|Array>)

    Hash describing the vlan configuration specified by id. If the id is not found then nil is returned



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

def getall
  @api.enable(['show vlan', 'show vlan trunk group'])
end

#set_name(id, opts = {}) ⇒ Boolean

Configures the VLAN name of the VLAN specified by ID. set_name maps to the EOS name WORD command. Spaces in the name will be converted to _

Parameters:

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

    The configuration parameters for the VLAN

Options Hash (opts):

  • :id (String)

    The VLAN ID to change

  • :value (string)

    The value to set the name to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    returns true if the command completed successfully



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/puppet_x/eos/modules/vlan.rb', line 114

def set_name(id, opts = {})
  value = opts[:value]
  default = opts[:default] || false

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

#set_state(id, opts = {}) ⇒ Boolean

Configures the administrative state of the VLAN specified by ID. The set_state function accepts ‘active’ or ‘suspend’ to configure the VLAN state.

Parameters:

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

    The configuration parameters for the VLAN

Options Hash (opts):

  • :id (String)

    The VLAN ID to change

  • :value (string)

    The value to set the state to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    returns true if the command completed successfully



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

def set_state(id, opts = {})
  value = opts[:value]
  default = opts[:default] || false

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

#set_trunk_group(id, opts = {}) ⇒ Boolean

Configures the trunk group value for the VLAN specified by ID. The trunk group setting is typically used to associate VLANs with MLAG configurations

Parameters:

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

    The configuration parameters for the VLAN

Options Hash (opts):

  • :id (String)

    The VLAN ID to change

  • :value (string)

    The value to set the trunk group to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    returns true if the command completed successfully



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

def set_trunk_group(id, opts = {})
  value = opts[:value]
  default = opts[:default] || false

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