arista-eapi 0.10.3 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/lib/arista/eapi.rb +0 -42
- data/lib/arista/eapi/request.rb +6 -8
- data/lib/arista/eapi/response.rb +1 -2
- data/lib/arista/eapi/switch.rb +25 -4
- data/lib/arista/eapi/version.rb +1 -1
- metadata +5 -5
data/.gitignore
CHANGED
data/lib/arista/eapi.rb
CHANGED
@@ -12,47 +12,5 @@ require 'arista/eapi/version'
|
|
12
12
|
|
13
13
|
module Arista
|
14
14
|
module EAPI
|
15
|
-
JSON_COMMANDS = [
|
16
|
-
'show aliases',
|
17
|
-
'show interfaces',
|
18
|
-
'show interfaces counters',
|
19
|
-
'show interfaces counters discards',
|
20
|
-
'show interfaces status',
|
21
|
-
'show interfaces switchport vlan mapping',
|
22
|
-
'show ip interface',
|
23
|
-
'show ipv6 interface',
|
24
|
-
'show mac address-table',
|
25
|
-
'show mac address-table aging-time',
|
26
|
-
'show management api http-commands',
|
27
|
-
'show management api http-commands certificate',
|
28
|
-
'show monitor server-failure history',
|
29
|
-
'show monitor server-failure servers',
|
30
|
-
'show monitor session',
|
31
|
-
'show privilege',
|
32
|
-
'show sflow',
|
33
|
-
'show sflow interfaces',
|
34
|
-
'show spanning-tree topology status',
|
35
|
-
'show version',
|
36
|
-
'show version license',
|
37
|
-
'show vlan',
|
38
|
-
'show vlan trunk group',
|
39
|
-
]
|
40
|
-
|
41
|
-
|
42
|
-
# Public: Determine the eAPI supported format based on the commands.
|
43
|
-
#
|
44
|
-
# options - List of commands to check format options for.
|
45
|
-
#
|
46
|
-
# Examples
|
47
|
-
#
|
48
|
-
# Arista::EAPI.format_for('show vlan')
|
49
|
-
# #=> 'json'
|
50
|
-
# Arista::EAPI.format_for('show vlan', 'show lldp neighbors')
|
51
|
-
# #=> text
|
52
|
-
#
|
53
|
-
# Returns json if all commands support JSON output, otherwise returns text.
|
54
|
-
def self.format_for(*commands)
|
55
|
-
(commands.flatten - JSON_COMMANDS).size > 0 ? 'text' : 'json'
|
56
|
-
end
|
57
15
|
end
|
58
16
|
end
|
data/lib/arista/eapi/request.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
module Arista
|
2
2
|
module EAPI
|
3
3
|
class Request
|
4
|
-
attr_accessor :switch, :commands
|
4
|
+
attr_accessor :switch, :commands, :options
|
5
|
+
|
6
|
+
def initialize(switch, commands, options = {})
|
7
|
+
options[:format] ||= 'json'
|
5
8
|
|
6
|
-
def initialize(switch, *commands)
|
7
9
|
self.switch = switch
|
8
10
|
self.commands = commands
|
11
|
+
self.options = options
|
9
12
|
end
|
10
13
|
|
11
14
|
def payload
|
@@ -16,7 +19,7 @@ module Arista
|
|
16
19
|
:params => {
|
17
20
|
:version => 1,
|
18
21
|
:cmds => commands,
|
19
|
-
:format =>
|
22
|
+
:format => options[:format]
|
20
23
|
},
|
21
24
|
})
|
22
25
|
end
|
@@ -24,11 +27,6 @@ module Arista
|
|
24
27
|
def execute
|
25
28
|
Arista::EAPI::Response.new(commands, RestClient.post(switch.url, payload))
|
26
29
|
end
|
27
|
-
|
28
|
-
def self.execute!(switch, *commands)
|
29
|
-
req = self.new(switch, *commands)
|
30
|
-
req.execute
|
31
|
-
end
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
data/lib/arista/eapi/response.rb
CHANGED
data/lib/arista/eapi/switch.rb
CHANGED
@@ -15,20 +15,41 @@ module Arista
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def interfaces
|
18
|
-
run('show interfaces')
|
18
|
+
run!('show interfaces')
|
19
19
|
attributes[:interfaces]
|
20
20
|
end
|
21
21
|
|
22
22
|
def version
|
23
|
-
run('show version')
|
23
|
+
run!('show version')
|
24
24
|
end
|
25
25
|
|
26
26
|
def update_attributes!(results)
|
27
27
|
results.each { |result| attributes.merge!(result) if result.is_a?(Hash) }
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
# Public: Runs a single command and returns the first result.
|
31
|
+
#
|
32
|
+
# options - Options to pass to the eAPI call.
|
33
|
+
# :format - The format for the eAPI response. Accepts the strings
|
34
|
+
# "json" or "text". (Defaults to json)
|
35
|
+
#
|
36
|
+
# Examples
|
37
|
+
#
|
38
|
+
# switch.run!('show version')
|
39
|
+
# #=> {: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"}
|
40
|
+
#
|
41
|
+
def run!(command, options={})
|
42
|
+
run([command], options).first
|
43
|
+
end
|
44
|
+
|
45
|
+
# Public: Run the
|
46
|
+
#
|
47
|
+
# options - Options to pass to the eAPI call.
|
48
|
+
# :format - The format for the eAPI response. Accepts the strings
|
49
|
+
# "json" or "text". (Defaults to json)
|
50
|
+
#
|
51
|
+
def run(commands, options={})
|
52
|
+
request = Arista::EAPI::Request.new(self, commands, options)
|
32
53
|
self.update_attributes!(request.execute.results)
|
33
54
|
end
|
34
55
|
end
|
data/lib/arista/eapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arista-eapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 51
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 11
|
9
|
+
- 0
|
10
|
+
version: 0.11.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mark Imbriaco
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-05-
|
18
|
+
date: 2013-05-24 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|