Class: PuppetX::Eos::Portchannel
- Inherits:
-
Object
- Object
- PuppetX::Eos::Portchannel
- Defined in:
- lib/puppet_x/eos/modules/portchannel.rb
Overview
The Portchannel class provides a base class instance for working with logical link aggregation interfaces.
Instance Method Summary collapse
-
#add_member(name, member) ⇒ Boolean
Adds a new member interface to the channel group.
-
#create(name) ⇒ Boolean
Create a logical port-channel interface.
-
#default(name) ⇒ Boolean
Defaults a logical port-channel interface.
-
#delete(name) ⇒ Boolean
Deletes a logical port-channel interface.
-
#get(name) ⇒ Hash
Retrievess a port channel interface from the running-configuration.
-
#get_members(name) ⇒ Array
Retreives the member interfaces for the specified channel group.
-
#getall ⇒ Array
Retrieves all logical port-channel interfaces from the running config.
-
#initialize(api) ⇒ PuppetX::Eos::Interface
constructor
Initialize innstance of Portchannel.
-
#remove_member(_name, member) ⇒ Boolean
Removes a member interface from the channel group.
-
#set_lacp_fallback(name, opts = {}) ⇒ Boolean
Configures the lacp fallback value.
-
#set_lacp_mode(name, mode) ⇒ Boolean
Configures the lacp mode for the interface.
-
#set_lacp_timeout(name, opts = {}) ⇒ Boolean
Configures the lacp fallback timeout value.
-
#set_members(name, members) ⇒ Object
Configures the member interfaces for the port-channel interface.
Constructor Details
#initialize(api) ⇒ PuppetX::Eos::Interface
Initialize innstance of Portchannel
50 51 52 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 50 def initialize(api) @api = api end |
Instance Method Details
#add_member(name, member) ⇒ Boolean
Adds a new member interface to the channel group
147 148 149 150 151 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 147 def add_member(name, member) id = name.match(/\d+/) @api.config(["interface #{member}", "channel-group #{id} mode on"]) == [{}, {}] end |
#create(name) ⇒ Boolean
Create a logical port-channel interface
116 117 118 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 116 def create(name) @api.config("interface #{name}") == [{}] end |
#default(name) ⇒ Boolean
Defaults a logical port-channel interface
136 137 138 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 136 def default(name) @api.config("default interface #{name}") == [{}] end |
#delete(name) ⇒ Boolean
Deletes a logical port-channel interface
126 127 128 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 126 def delete(name) @api.config("no interface #{name}") == [{}] end |
#get(name) ⇒ Hash
Retrievess a port channel interface from the running-configuration
Example
{
"name": <String>,
"lacp_mode": [active, passive, off],
"members": [Array],
"lacp_fallback": [static, individual],
"lacp_timeout": <0-900>
}
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 69 def get(name) members = get_members name result = @api.enable("show interfaces #{name}") interface = result.first['interfaces'] attr_hash = { name: name } attr_hash[:members] = members attr_hash[:lacp_mode] = get_lacp_mode members attr_hash[:lacp_fallback] = get_lacp_fallback interface attr_hash[:lacp_timeout] = interface['fallbackTimeout'] attr_hash end |
#get_members(name) ⇒ Array
Retreives the member interfaces for the specified channel group
104 105 106 107 108 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 104 def get_members(name) result = @api.enable("show #{name} all-ports", format: 'text') result.first['output'].scan(/Ethernet\d+/) end |
#getall ⇒ Array
Retrieves all logical port-channel interfaces from the running config
86 87 88 89 90 91 92 93 94 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 86 def getall result = @api.enable('show interfaces') interfaces = result.first['interfaces'] resp = [] interfaces.each do |key, value| resp << get(key) if value['hardware'] == 'portChannel' end resp end |
#remove_member(_name, member) ⇒ Boolean
Removes a member interface from the channel group
160 161 162 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 160 def remove_member(_name, member) @api.config(["interface #{member}", 'no channel-group']) == [{}, {}] end |
#set_lacp_fallback(name, opts = {}) ⇒ Boolean
Configures the lacp fallback value
213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 213 def set_lacp_fallback(name, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["interface #{name}"] case default when true cmds << 'default port-channel lacp fallback' when false cmds << (value.nil? ? "no port-channel lacp fallback #{value}" : \ "port-channel lacp fallback #{value}") end @api.config(cmds) == [{}, {}] end |
#set_lacp_mode(name, mode) ⇒ Boolean
Configures the lacp mode for the interface
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 187 def set_lacp_mode(name, mode) id = name.match(/\d+/) members = get_members name commands = [] config = [] members.each do |member| commands << "interface #{member}" << 'no channel-group' config << "interface #{member}" << "channel-group #{id} mode #{mode}" end config.unshift(*commands) result = @api.config(config) config.size == result.size end |
#set_lacp_timeout(name, opts = {}) ⇒ Boolean
Configures the lacp fallback timeout value
237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 237 def set_lacp_timeout(name, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["interface #{name}"] case default when true cmds << 'default port-channel lacp fallback timeout' when false cmds << (value.nil? ? 'no port-channel lacp fallback timeout' : \ "port-channel lacp fallback timeout #{value}") end @api.config(cmds) == [{}, {}] end |
#set_members(name, members) ⇒ Object
Configures the member interfaces for the port-channel interface
170 171 172 173 174 175 176 177 178 |
# File 'lib/puppet_x/eos/modules/portchannel.rb', line 170 def set_members(name, members) current = get_members(name) (current - members).each do |member| remove_member(name, member) end (members - current).each do |member| add_member(name, member) end end |