Class: Arista::EAPI::Switch
- Inherits:
-
Object
- Object
- Arista::EAPI::Switch
- Defined in:
- lib/arista/eapi/switch.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#password ⇒ Object
Returns the value of attribute password.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(hostname, user, password, protocol = 'https') ⇒ Switch
constructor
A new instance of Switch.
- #interfaces ⇒ Object
-
#run(commands, options = {}) ⇒ Object
Public: Run the .
-
#run!(command, options = {}) ⇒ Object
Public: Runs a single command and returns the first result.
- #update_attributes!(results) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(hostname, user, password, protocol = 'https') ⇒ Switch
Returns a new instance of Switch.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/arista/eapi/switch.rb', line 6 def initialize(hostname, user, password, protocol = 'https') self.attributes = {} self.hostname = hostname self.user = user self.password = password self.protocol = protocol userpass = [ CGI.escape(user), CGI.escape(password) ].join(':') self.url = "#{protocol}://#{userpass}@#{hostname}/command-api" end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/arista/eapi/switch.rb', line 4 def attributes @attributes end |
#hostname ⇒ Object
Returns the value of attribute hostname.
4 5 6 |
# File 'lib/arista/eapi/switch.rb', line 4 def hostname @hostname end |
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/arista/eapi/switch.rb', line 4 def password @password end |
#protocol ⇒ Object
Returns the value of attribute protocol.
4 5 6 |
# File 'lib/arista/eapi/switch.rb', line 4 def protocol @protocol end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/arista/eapi/switch.rb', line 4 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
4 5 6 |
# File 'lib/arista/eapi/switch.rb', line 4 def user @user end |
Instance Method Details
#interfaces ⇒ Object
17 18 19 20 |
# File 'lib/arista/eapi/switch.rb', line 17 def interfaces run!('show interfaces') attributes[:interfaces] end |
#run(commands, options = {}) ⇒ Object
Public: Run the
options - Options to pass to the eAPI call.
:format - The format for the eAPI response. Accepts the strings
"json" or "text". (Defaults to json)
51 52 53 54 |
# File 'lib/arista/eapi/switch.rb', line 51 def run(commands, ={}) request = Arista::EAPI::Request.new(self, commands, ) self.update_attributes!(request.execute.results) end |
#run!(command, options = {}) ⇒ Object
Public: Runs a single command and returns the first result.
options - Options to pass to the eAPI call.
:format - The format for the eAPI response. Accepts the strings
"json" or "text". (Defaults to json)
Examples
switch.run!('show version')
#=> {:model_name=>"DCS-7048T-A-R", :internal_version=>"4.12.0-1244071.EOS4120", :system_mac_address=>"00:1c:73:16:c2:c8", :serial_number=>"redacted", :mem_total=>4009152, :bootup_timestamp=>1368735672.690161, :mem_free=>1848284, :version=>"4.12.0", :architecture=>"i386", :internal_build_id=>"c25ec8ea-cb8f-40a8-af0b-d11eaa94d57c", :hardware_revision=>"01.04"}
41 42 43 |
# File 'lib/arista/eapi/switch.rb', line 41 def run!(command, ={}) run([command], ).first end |
#update_attributes!(results) ⇒ Object
26 27 28 |
# File 'lib/arista/eapi/switch.rb', line 26 def update_attributes!(results) results.each { |result| attributes.merge!(result) if result.is_a?(Hash) } end |
#version ⇒ Object
22 23 24 |
# File 'lib/arista/eapi/switch.rb', line 22 def version run!('show version') end |