class Rbeapi::Api::Interfaces
The Interfaces
class manages all physical and logical interfaces on an EOS node.
Public Class Methods
new(node)
click to toggle source
Calls superclass method
Rbeapi::Api::Entity::new
# File lib/rbeapi/api/interfaces.rb, line 45 def initialize(node) super(node) @instances = {} end
Public Instance Methods
get(name)
click to toggle source
get returns a hash of interface configurations for the given name.
@example
{ name: <string>, type: <string>, description: <string>, encapsulation: <integer>, shutdown: <boolean> }
@param name [String] The interface name to return a resource for from
the nodes configuration.
@return [nil, Hash<Symbol, Object>] Returns the interface resource as a
Hash. If the specified name is not found in the nodes current configuration a nil object is returned.
# File lib/rbeapi/api/interfaces.rb, line 68 def get(name) get_instance(name).get(name) end
get_instance(name)
click to toggle source
get_instance
returns an interface instance for the given name.
@param name [String] The interface name to return an instance for.
@return [Object] Returns the interface instance as an Object.
# 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()
click to toggle source
getall returns a hash of interface configurations.
@example
{ <name>: { name: <string>, type: <string>, description: <string>, encapsulation: <integer>, shutdown: <boolean>, ... }, <name>: { name: <string>, type: <string>, description: <string>, encapsulation: <integer>, shutdown: <boolean>, ... }, ... }
@return [Hash<Symbol, Object>] Returns the interface resources as a
Hash. If none exist in the nodes current configuration an empty hash is returned.
# 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
method_missing(method_name, *args, &block)
click to toggle source
rubocop:disable Style/MethodMissing
# 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
respond_to?(method_name, name = nil)
click to toggle source
rubocop:enable Style/MethodMissing
Calls superclass method
# 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