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) ⇒ Object
- #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) ⇒ Object
30 31 32 33 |
# File 'lib/arista/eapi/switch.rb', line 30 def run(*commands) request = Arista::EAPI::Request.new(self, *commands) self.update_attributes!(request.execute.results) 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').first end |