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
rubocop:disable Style/MethodMissing.
-
#respond_to?(method_name, name = nil) ⇒ Boolean
rubocop:enable Style/MethodMissing.
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
rubocop:disable Style/MethodMissing
136 137 138 139 |
# File 'lib/rbeapi/api/interfaces.rb', line 136 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.
68 69 70 |
# File 'lib/rbeapi/api/interfaces.rb', line 68 def get(name) get_instance(name).get(name) end |
#get_instance(name) ⇒ Object
get_instance returns an interface instance for the given name.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rbeapi/api/interfaces.rb', line 114 def get_instance(name) name = name[0, 2].upcase cls = case name when 'ET' 'Rbeapi::Api::EthernetInterface' when 'PO' 'Rbeapi::Api::PortchannelInterface' when 'VX' 'Rbeapi::Api::VxlanInterface' when 'VL' 'Rbeapi::Api::VlanInterface' else '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.
99 100 101 102 103 104 105 106 |
# File 'lib/rbeapi/api/interfaces.rb', line 99 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
rubocop:enable Style/MethodMissing
142 143 144 145 146 |
# File 'lib/rbeapi/api/interfaces.rb', line 142 def respond_to?(method_name, name = nil) return super unless name instance = get_instance(name) instance.respond_to?(method_name) || super end |