class PuppetX::Eos::Interface
The Interface
class provides a base class instance for working with physical and logical interfaces.
Public Class Methods
Public Instance Methods
Creates a new logical interface on the node.
@param [String] name The name of the logical interface. It must be
a full valid EOS interface name (ie Ethernet, not Et)
@return [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)
# 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
Configures the interface object back to system wide defaults using the EOS command api
@param [String] name The name of the interface
@return [Boolean] True if it succeeds otherwise False
# File lib/puppet_x/eos/modules/interface.rb, line 76 def default(name) @api.config("default interface #{name}") == [{}] end
Deletes an existing logical interface.
@param [String] name The name of the interface. It must be a full
valid EOS interface name (ie Vlan, not Vl)
@return [Boolean] True if the command succeeds or False if the command
fails or is not supported (for instance trying to delete a physical interface)
# 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
Returns the base interface hash representing physical and logical interfaces in EOS using eAPI
Example
[{ "interfaces": {...}, "interfaceFlowControls": {...} }]
@return [Array<Hash>] returns an Array of Hashes
# File lib/puppet_x/eos/modules/interface.rb, line 65 def getall @api.enable(['show interfaces', 'show interfaces flowcontrol']) end
Configures the interface description
@param [String] name The name of the interface to configure @param [Hash] opts The configuration parameters for the interface @option opts [string] :value The value to set the description to @option opts [Boolean] :default The value should be set to default
@return [Boolean] True if the commands succeed otherwise False
# 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
Configures the interface flowcontrol
@param [String] name The name of the interface to configure @param [String] direction One of tx or rx @param [Hash] opts The configuration parameters for the interface @option opts [string] :value The value to set the description to @option opts [Boolean] :default The value should be set to default
@return [Boolean] True if the commands succeed otherwise False
# 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
Configures the interface shutdown state
@param [String] name The name of the interface to configure @param [Hash] opts The configuration parameters for the interface @option opts [string] :value The value to set the state to @option opts [Boolean] :default The value should be set to default
@return [Boolean] True if the commands succeed otherwise False
# 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