Class: Arista::EAPI::Switch

Inherits:
Object
  • Object
show all
Defined in:
lib/arista/eapi/switch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject

Returns the value of attribute attributes.



4
5
6
# File 'lib/arista/eapi/switch.rb', line 4

def attributes
  @attributes
end

#hostnameObject

Returns the value of attribute hostname.



4
5
6
# File 'lib/arista/eapi/switch.rb', line 4

def hostname
  @hostname
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/arista/eapi/switch.rb', line 4

def password
  @password
end

#protocolObject

Returns the value of attribute protocol.



4
5
6
# File 'lib/arista/eapi/switch.rb', line 4

def protocol
  @protocol
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/arista/eapi/switch.rb', line 4

def url
  @url
end

#userObject

Returns the value of attribute user.



4
5
6
# File 'lib/arista/eapi/switch.rb', line 4

def user
  @user
end

Instance Method Details

#interfacesObject



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

#versionObject



22
23
24
# File 'lib/arista/eapi/switch.rb', line 22

def version
  run('show version').first
end