Class: Rbeapi::Api::Interfaces
- Defined in:
- lib/rbeapi/api/interfaces.rb
Overview
The Interfaces class manages all physical and logical interfaces on an EOS node.
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns a hash of interface configurations for the given name.
-
#get_instance(name) ⇒ Object
get_instance returns an interface instance for the given name.
-
#getall ⇒ Hash<Symbol, Object>
getall returns a hash of interface configurations.
-
#initialize(node) ⇒ Interfaces
constructor
A new instance of Interfaces.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to?(method_name, name = nil) ⇒ Boolean
Methods inherited from Entity
#command_builder, #configure, #configure_interface, #get_block, instance
Constructor Details
#initialize(node) ⇒ Interfaces
Returns a new instance of Interfaces.
45 46 47 48 |
# File 'lib/rbeapi/api/interfaces.rb', line 45 def initialize(node) super(node) @instances = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
130 131 132 133 |
# File 'lib/rbeapi/api/interfaces.rb', line 130 def method_missing(method_name, *args, &block) instance = get_instance(args[0]) instance.send(method_name.to_sym, *args, &block) end |
Instance Method Details
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns a hash of interface configurations for the given name.
67 68 69 |
# File 'lib/rbeapi/api/interfaces.rb', line 67 def get(name) get_instance(name).get(name) end |
#get_instance(name) ⇒ Object
get_instance returns an interface instance for the given name.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rbeapi/api/interfaces.rb', line 111 def get_instance(name) name = name[0, 2].upcase case name when 'ET' cls = 'Rbeapi::Api::EthernetInterface' when 'PO' cls = 'Rbeapi::Api::PortchannelInterface' when 'VX' cls = 'Rbeapi::Api::VxlanInterface' else cls = 'Rbeapi::Api::BaseInterface' end return @instances[name] if @instances.include?(cls) instance = Rbeapi::Utils.class_from_string(cls).new(@node) @instances[name] = instance instance end |
#getall ⇒ Hash<Symbol, Object>
getall returns a hash of interface configurations.
96 97 98 99 100 101 102 103 |
# File 'lib/rbeapi/api/interfaces.rb', line 96 def getall interfaces = config.scan(/(?<=^interface\s).+$/) interfaces.each_with_object({}) do |name, hsh| data = get(name) hsh[name] = data if data end end |
#respond_to?(method_name, name = nil) ⇒ Boolean
135 136 137 138 139 |
# File 'lib/rbeapi/api/interfaces.rb', line 135 def respond_to?(method_name, name = nil) return super unless name instance = get_instance(name) instance.respond_to?(method_name) || super end |