Class: PuppetX::Eos::Switchport
- Inherits:
-
Object
- Object
- PuppetX::Eos::Switchport
- Defined in:
- lib/puppet_x/eos/modules/switchport.rb
Overview
The Switchport class provides a base class instance for working with logical layer-2 interfaces.
Instance Method Summary collapse
-
#create(name) ⇒ Boolean
Creates a new logical switchport interface in EOS.
-
#default(name) ⇒ Boolean
Defaults a logical switchport interface in the running-config.
-
#delete(name) ⇒ Boolean
Deletes a logical switchport interface from the running-config.
-
#get(name) ⇒ Hash
Retrieves the properies for a logical switchport from the running-config using eAPI.
-
#getall ⇒ Array
Retrieves all switchport interfaces from the running-config.
-
#initialize(api) ⇒ PuppetX::Eos::Switchport
constructor
Initialize instance of Switchport.
-
#set_access_vlan(name, opts = {}) ⇒ Boolean
Configures the access port vlan for the specified interface.
-
#set_mode(name, opts = {}) ⇒ Boolean
Configures the switchport mode for the specified interafce.
-
#set_trunk_allowed_vlans(name, opts = {}) ⇒ Boolean
Configures the trunk port allowed vlans for the specified interface.
-
#set_trunk_native_vlan(name, opts = {}) ⇒ Boolean
Configures the trunk port native vlan for the specified interface.
Constructor Details
#initialize(api) ⇒ PuppetX::Eos::Switchport
Initialize instance of Switchport
50 51 52 |
# File 'lib/puppet_x/eos/modules/switchport.rb', line 50 def initialize(api) @api = api end |
Instance Method Details
#create(name) ⇒ Boolean
Creates a new logical switchport interface in EOS
102 103 104 105 |
# File 'lib/puppet_x/eos/modules/switchport.rb', line 102 def create(name) @api.config(["interface #{name}", 'no ip address', 'switchport']) == [{}, {}, {}] end |
#default(name) ⇒ Boolean
Defaults a logical switchport interface in the running-config
123 124 125 126 |
# File 'lib/puppet_x/eos/modules/switchport.rb', line 123 def default(name) @api.config(["interface #{name}", 'default switchport']) == [{}, {}] end |
#delete(name) ⇒ Boolean
Deletes a logical switchport interface from the running-config
113 114 115 |
# File 'lib/puppet_x/eos/modules/switchport.rb', line 113 def delete(name) @api.config(["interface #{name}", 'no switchport']) == [{}, {}] end |
#get(name) ⇒ Hash
Retrieves the properies for a logical switchport from the running-config using eAPI
Example
{
"name": <String>,
"mode": [access, trunk],
"trunk_allowed_vlans": [],
"trunk_native_vlan": <Integer>,
"access_vlan": <Integer>
}
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/puppet_x/eos/modules/switchport.rb', line 71 def get(name) result = @api.enable("show interfaces #{name} switchport", format: 'text') output = result.first['output'] attr_hash = { name: name } attr_hash[:mode] = mode_to_value output attr_hash[:trunk_allowed_vlans] = trunk_vlans_to_value output attr_hash[:trunk_native_vlan] = trunk_native_to_value output attr_hash[:access_vlan] = access_vlan_to_value output attr_hash end |
#getall ⇒ Array
Retrieves all switchport interfaces from the running-config
87 88 89 90 91 92 93 94 |
# File 'lib/puppet_x/eos/modules/switchport.rb', line 87 def getall result = @api.enable('show interfaces') switchports = [] result.first['interfaces'].map do |name, attrs| switchports << get(name) if attrs['forwardingModel'] == 'bridged' end switchports end |
#set_access_vlan(name, opts = {}) ⇒ Boolean
Configures the access port vlan for the specified interface. This value is only valid if the switchport mode is configure in access mode.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/puppet_x/eos/modules/switchport.rb', line 216 def set_access_vlan(name, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["interface #{name}"] case default when true cmds << 'default switchport access vlan' when false cmds << (value.nil? ? 'no switchport access vlan' : \ "switchport access vlan #{value}") end @api.config(cmds) == [{}, {}] end |
#set_mode(name, opts = {}) ⇒ Boolean
Configures the switchport mode for the specified interafce. Valid modes are access (default) or trunk
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/puppet_x/eos/modules/switchport.rb', line 138 def set_mode(name, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["interface #{name}"] case default when true cmds << 'default switchport mode' when false cmds << (value.nil? ? 'no switchport mode' : \ "switchport mode #{value}") end @api.config(cmds) == [{}, {}] end |
#set_trunk_allowed_vlans(name, opts = {}) ⇒ Boolean
Configures the trunk port allowed vlans for the specified interface. This value is only valid if the switchport mode is configure as trunk.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/puppet_x/eos/modules/switchport.rb', line 164 def set_trunk_allowed_vlans(name, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["interface #{name}"] case default when true cmds << 'default switchport trunk allowed vlan' when false cmds << (value.nil? ? 'no switchport trunk allowed vlan' : \ "switchport trunk allowed vlan #{value}") end @api.config(cmds) == [{}, {}] end |
#set_trunk_native_vlan(name, opts = {}) ⇒ Boolean
Configures the trunk port native vlan for the specified interface. This value is only valid if the switchport mode is configure as trunk.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/puppet_x/eos/modules/switchport.rb', line 190 def set_trunk_native_vlan(name, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["interface #{name}"] case default when true cmds << 'default switchport trunk native vlan' when false cmds << (value.nil? ? 'no switchport trunk native vlan' : \ "switchport trunk native vlan #{value}") end @api.config(cmds) == [{}, {}] end |