Class: PuppetX::Eos::Vlan
- Inherits:
-
Object
- Object
- PuppetX::Eos::Vlan
- 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
-
#create(id) ⇒ Boolean
Adds a new VLAN resource in EOS setting the VLAN ID to id.
-
#default(id) ⇒ Boolean
Defaults an existing VLAN resource in EOS as specified by ID.
-
#delete(id) ⇒ Boolean
Deletes an existing VLAN resource in EOS as specified by ID.
-
#getall ⇒ nil, Hash<String, String|Hash|Array>
Returns the vlan data for the provided id with the show vlan <id> command.
-
#initialize(api) ⇒ Vlan
constructor
A new instance of Vlan.
-
#set_name(id, opts = {}) ⇒ Boolean
Configures the VLAN name of the VLAN specified by ID.
-
#set_state(id, opts = {}) ⇒ Boolean
Configures the administrative state of the VLAN specified by ID.
-
#set_trunk_group(id, opts = {}) ⇒ Boolean
Configures the trunk group value for the VLAN specified by ID.
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
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
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
87 88 89 |
# File 'lib/puppet_x/eos/modules/vlan.rb', line 87 def delete(id) @api.config("no vlan #{id}") == [{}] end |
#getall ⇒ nil, 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": {...} }
]
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 _
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.
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
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 |