Class: Rbeapi::Api::Interfaces

Inherits:
Entity
  • Object
show all
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

#config, #error, #node

Instance Method Summary collapse

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



82
83
84
85
# File 'lib/rbeapi/api/interfaces.rb', line 82

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) ⇒ Object



50
51
52
# File 'lib/rbeapi/api/interfaces.rb', line 50

def get(name)
  get_instance(name).get(name)
end

#get_instance(name) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rbeapi/api/interfaces.rb', line 63

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

#getallObject



54
55
56
57
58
59
60
61
# File 'lib/rbeapi/api/interfaces.rb', line 54

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

Returns:

  • (Boolean)


87
88
89
90
91
# File 'lib/rbeapi/api/interfaces.rb', line 87

def respond_to?(method_name, name = nil)
  return super unless name
  instance = get_instance(name)
  instance.respond_to?(method_name) || super
end