Class: PuppetX::Eos::Interface
- Inherits:
-
Object
- Object
- PuppetX::Eos::Interface
- Defined in:
- lib/puppet_x/eos/modules/interface.rb
Overview
The Interface class provides a base class instance for working with physical and logical interfaces.
Instance Method Summary collapse
-
#create(name) ⇒ Boolean
Creates a new logical interface on the node.
-
#default(name) ⇒ Boolean
Configures the interface object back to system wide defaults using the EOS command api.
-
#delete(name) ⇒ Boolean
Deletes an existing logical interface.
-
#getall ⇒ Array<Hash>
Returns the base interface hash representing physical and logical interfaces in EOS using eAPI.
-
#initialize(api) ⇒ PuppetX::Eos::Interface
constructor
Initialize instance of Interface.
-
#set_description(name, opts = {}) ⇒ Boolean
Configures the interface description.
-
#set_flowcontrol(name, direction, opts = {}) ⇒ Boolean
Configures the interface flowcontrol.
-
#set_shutdown(name, opts = {}) ⇒ Boolean
Configures the interface shutdown state.
Constructor Details
#initialize(api) ⇒ PuppetX::Eos::Interface
Initialize instance of Interface
50 51 52 |
# File 'lib/puppet_x/eos/modules/interface.rb', line 50 def initialize(api) @api = api end |
Instance Method Details
#create(name) ⇒ Boolean
Creates a new logical interface on the node.
89 90 91 92 |
# 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 |
#default(name) ⇒ Boolean
Configures the interface object back to system wide defaults using the EOS command api
76 77 78 |
# File 'lib/puppet_x/eos/modules/interface.rb', line 76 def default(name) @api.config("default interface #{name}") == [{}] end |
#delete(name) ⇒ Boolean
Deletes an existing logical interface.
103 104 105 106 |
# 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 |
#getall ⇒ Array<Hash>
Returns the base interface hash representing physical and logical interfaces in EOS using eAPI
Example
[{
"interfaces": {...},
"interfaceFlowControls": {...}
}]
65 66 67 |
# File 'lib/puppet_x/eos/modules/interface.rb', line 65 def getall @api.enable(['show interfaces', 'show interfaces flowcontrol']) end |
#set_description(name, opts = {}) ⇒ Boolean
Configures the interface description
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# 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 |
#set_flowcontrol(name, direction, opts = {}) ⇒ Boolean
Configures the interface flowcontrol
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# 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 |
#set_shutdown(name, opts = {}) ⇒ Boolean
Configures the interface shutdown state
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# 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 |