rbeapi 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGELOG.md +20 -0
  3. data/Gemfile +1 -1
  4. data/README.md +11 -11
  5. data/Rakefile +19 -0
  6. data/guide/Makefile +177 -0
  7. data/guide/_static/arista_logo_11-trans-w.png +0 -0
  8. data/guide/_static/arista_logo_jpg-11.jpg +0 -0
  9. data/guide/_static/favicon.ico +0 -0
  10. data/guide/conf.py +279 -0
  11. data/guide/cookbook.rst +4 -0
  12. data/guide/developing.rst +4 -0
  13. data/guide/faq.rst +4 -0
  14. data/guide/index.rst +23 -0
  15. data/guide/installation.rst +4 -0
  16. data/guide/license.rst +5 -0
  17. data/guide/overview.rst +20 -0
  18. data/guide/quickstart.rst +4 -0
  19. data/guide/release-notes-0.5.0.rst +60 -0
  20. data/guide/release-notes.rst +6 -0
  21. data/guide/testing.rst +4 -0
  22. data/guide/troubleshooting.rst +1 -0
  23. data/lib/rbeapi/api/aaa.rb +54 -18
  24. data/lib/rbeapi/api/acl.rb +60 -2
  25. data/lib/rbeapi/api/bgp.rb +81 -0
  26. data/lib/rbeapi/api/dns.rb +48 -2
  27. data/lib/rbeapi/api/interfaces.rb +97 -32
  28. data/lib/rbeapi/api/ipinterfaces.rb +13 -2
  29. data/lib/rbeapi/api/logging.rb +11 -2
  30. data/lib/rbeapi/api/mlag.rb +20 -10
  31. data/lib/rbeapi/api/ntp.rb +4 -3
  32. data/lib/rbeapi/api/ospf.rb +102 -10
  33. data/lib/rbeapi/api/prefixlists.rb +47 -4
  34. data/lib/rbeapi/api/radius.rb +9 -9
  35. data/lib/rbeapi/api/routemaps.rb +7 -5
  36. data/lib/rbeapi/api/snmp.rb +13 -4
  37. data/lib/rbeapi/api/staticroutes.rb +1 -1
  38. data/lib/rbeapi/api/stp.rb +39 -14
  39. data/lib/rbeapi/api/switchports.rb +126 -2
  40. data/lib/rbeapi/api/system.rb +24 -3
  41. data/lib/rbeapi/api/tacacs.rb +9 -10
  42. data/lib/rbeapi/api/users.rb +12 -3
  43. data/lib/rbeapi/api/varp.rb +40 -8
  44. data/lib/rbeapi/api/vlans.rb +15 -5
  45. data/lib/rbeapi/client.rb +19 -11
  46. data/lib/rbeapi/eapilib.rb +8 -0
  47. data/lib/rbeapi/utils.rb +10 -0
  48. data/lib/rbeapi/version.rb +1 -1
  49. data/spec/fixtures/eapi.conf.yaml +6 -0
  50. data/spec/fixtures/empty.conf +0 -0
  51. data/spec/fixtures/env_path.conf +5 -0
  52. data/spec/fixtures/test.conf +39 -0
  53. data/spec/fixtures/wildcard.conf +43 -0
  54. data/spec/system/rbeapi/api/aaa_groups_spec.rb +122 -0
  55. data/spec/system/rbeapi/api/aaa_spec.rb +90 -0
  56. data/spec/system/{api_acl_spec.rb → rbeapi/api/acl_spec.rb} +0 -0
  57. data/spec/system/rbeapi/api/bgp_neighbors_spec.rb +354 -0
  58. data/spec/system/rbeapi/api/bgp_spec.rb +275 -0
  59. data/spec/system/rbeapi/api/dns_spec.rb +17 -1
  60. data/spec/system/rbeapi/api/interfaces_base_spec.rb +46 -5
  61. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +14 -0
  62. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +68 -0
  63. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +0 -1
  64. data/spec/system/{api_ospf_interfaces_spec.rb → rbeapi/api/ospf_interfaces_spec.rb} +3 -2
  65. data/spec/system/{api_ospf_spec.rb → rbeapi/api/ospf_spec.rb} +11 -2
  66. data/spec/system/rbeapi/api/routemaps_spec.rb +3 -4
  67. data/spec/system/rbeapi/api/snmp_spec.rb +65 -0
  68. data/spec/system/rbeapi/api/staticroutes_spec.rb +177 -0
  69. data/spec/system/rbeapi/api/stp_instances_spec.rb +20 -0
  70. data/spec/system/rbeapi/api/stp_interfaces_spec.rb +7 -0
  71. data/spec/system/rbeapi/api/switchports_spec.rb +86 -16
  72. data/spec/system/rbeapi/api/users_spec.rb +324 -0
  73. data/spec/system/rbeapi/api/varp_interfaces_spec.rb +34 -0
  74. data/spec/system/rbeapi/api/vrrp_spec.rb +707 -0
  75. data/spec/system/rbeapi/client_spec.rb +367 -0
  76. data/spec/unit/rbeapi/api/aaa/aaa_groups_spec.rb +111 -0
  77. data/spec/unit/rbeapi/api/aaa/aaa_spec.rb +77 -0
  78. data/spec/unit/rbeapi/api/aaa/fixture_aaa.text +3 -0
  79. data/spec/unit/rbeapi/api/switchports/default_spec.rb +249 -0
  80. data/spec/unit/rbeapi/api/switchports/fixture_switchports.text +284 -0
  81. data/spec/unit/rbeapi/api/users/default_spec.rb +1 -1
  82. data/spec/unit/rbeapi/client_spec.rb +211 -0
  83. metadata +65 -10
data/lib/rbeapi/client.rb CHANGED
@@ -90,7 +90,7 @@ module Rbeapi
90
90
  end
91
91
 
92
92
  ##
93
- # Retrieves the node config form the loaded configuration file and
93
+ # Retrieves the node config from the loaded configuration file and
94
94
  # returns a Rbeapi::Node instance for working with the remote node.
95
95
  #
96
96
  # @param [String] :name The named configuration to use for creating the
@@ -99,21 +99,23 @@ module Rbeapi
99
99
  # @return [Rbeapi::Node, nil] Returns an instance of Rbeapi::Node. If
100
100
  # the named configuration is not found then nil is returned
101
101
  def connect_to(name)
102
- config = config_for(name)
103
- return nil unless config
102
+ config_entry = config_for(name)
103
+ return nil unless config_entry
104
+ config = config_entry.dup
104
105
  config['host'] = name if config['host'] == '*'
105
106
  config = Rbeapi::Utils.transform_keys_to_symbols(config)
106
107
  connection = connect config
107
108
  Node.new(connection)
109
+ node = Node.new(connection)
110
+ enablepwd = config.fetch(:enablepwd, nil)
111
+ node.enable_authentication(enablepwd) if enablepwd
112
+ node
108
113
  end
109
114
 
110
115
  ##
111
116
  # Builds a connection object to a remote node using the specified
112
117
  # options and return an instance of Rbeapi::Connection. All
113
- # configuration options can be passed via the :opts param or can be
114
- # overridden using environment variables. Environment variables are
115
- # specified by prepending EAPI to the option name. For instance to
116
- # override the host param use EAPI_HOST.
118
+ # configuration options can be passed via the :opts param.
117
119
  #
118
120
  # @param [Hash] :opts the options to create a message with
119
121
  # @option :opts [String] :host The IP address or hostname of the remote
@@ -122,7 +124,7 @@ module Rbeapi
122
124
  # the eAPI connection with
123
125
  # @option :opts [String] :password The password to use to authenticate
124
126
  # the eAPI connection with
125
- # @option :opts [String] :enable_pwd The enable password (if defined) to
127
+ # @option :opts [String] :enablepwd The enable password (if defined) to
126
128
  # pass to the remote node to enter privilege mode
127
129
  # @option :opts [String] :use_ssl Specifies whether or not to use the
128
130
  # HTTP or HTTPS protocol
@@ -205,7 +207,12 @@ module Rbeapi
205
207
  #
206
208
  # @param [String] :filename The full path to the filename to load
207
209
  def read(filename)
208
- super(filename: filename)
210
+ begin
211
+ super(filename: filename)
212
+ rescue IniFile::Error => exc
213
+ Rbeapi::Utils.syslog_warning("#{exc}: in eapi conf file: #{filename}")
214
+ return
215
+ end
209
216
 
210
217
  # For each section, if the host parameter is omitted then the
211
218
  # connection name is used
@@ -252,13 +259,14 @@ module Rbeapi
252
259
  end
253
260
 
254
261
  ##
255
- # Adds a new connection section to the current configuration
262
+ # Adds a new connection section to the current configuration
256
263
  #
257
264
  # @param [String] :name The name of the connection to add to the
258
265
  # configuration.
259
266
  # @param [Hash] :values The properties for the connection
260
267
  def add_connection(name, values)
261
268
  self["connection:#{name}"] = values
269
+ nil
262
270
  end
263
271
  end
264
272
 
@@ -332,7 +340,7 @@ module Rbeapi
332
340
  def config(commands, opts = {})
333
341
  commands = [*commands] unless commands.respond_to?('each')
334
342
 
335
- commands.insert(0, 'configure')
343
+ commands.insert(0, 'configure terminal')
336
344
 
337
345
  if @dry_run
338
346
  puts '[rbeapi dry-run commands]'
@@ -162,6 +162,14 @@ module Rbeapi
162
162
  @read_timeout = opts.fetch(:read_timeout, DEFAULT_HTTP_READ_TIMEOUT)
163
163
  end
164
164
 
165
+ ##
166
+ # Gets values for open_timeout and read_timeout
167
+ #
168
+ # @return [Hash] open_timeout and read_timeout
169
+ def get_timeouts
170
+ { open_timeout: @open_timeout, read_timeout: @read_timeout }
171
+ end
172
+
165
173
  ##
166
174
  # Generates the eAPI JSON request message.
167
175
  #
data/lib/rbeapi/utils.rb CHANGED
@@ -30,6 +30,8 @@
30
30
  # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
31
  #
32
32
 
33
+ require 'syslog'
34
+
33
35
  ##
34
36
  # Rbeapi toplevel namespace
35
37
  module Rbeapi
@@ -64,5 +66,13 @@ module Rbeapi
64
66
  mod.const_get(cls)
65
67
  end
66
68
  end
69
+
70
+ ##
71
+ # Syslogs a warning message.
72
+ #
73
+ # @param [String] :message The message to log.
74
+ def self.syslog_warning(message)
75
+ Syslog.open('rbeapi', Syslog::LOG_PID) { |s| s.warning message }
76
+ end
67
77
  end
68
78
  end
@@ -33,5 +33,5 @@
33
33
  # #
34
34
  # Rbeapi toplevel namespace
35
35
  module Rbeapi
36
- VERSION = '0.4.0'
36
+ VERSION = '0.5.0'
37
37
  end
@@ -0,0 +1,6 @@
1
+ ---
2
+ :username: admin
3
+ :password: admin
4
+ :use_ssl: true
5
+ :port: 199
6
+ :hostname: bogus
File without changes
@@ -0,0 +1,5 @@
1
+ [connection:env_path]
2
+ host: 172.16.131.40
3
+ username: admin
4
+ password: admin
5
+ transport: https
@@ -0,0 +1,39 @@
1
+ [connection:veos01]
2
+ username: eapi
3
+ password: password
4
+ transport: http
5
+ host: veos01
6
+
7
+ [connection:veos02]
8
+ transport: http
9
+ host: veos02
10
+
11
+ [connection:veos03]
12
+ transport: socket
13
+ host: veos03
14
+
15
+ [connection:veos04]
16
+ host: 172.16.10.1
17
+ username: eapi
18
+ password: password
19
+ enablepwd: itsasecret
20
+ port: 1234
21
+ transport: https
22
+
23
+ [connection:veos05]
24
+ host: 172.16.131.40
25
+ username: admin
26
+ password: admin
27
+ enablepwd: password
28
+ transport: https
29
+ port: 1234
30
+ open_timeout: 12
31
+ read_timeout: 12
32
+
33
+ [connection: localhost]
34
+ transport: http_local
35
+ host: localhost
36
+
37
+ [connection:localhost]
38
+ transport: socket
39
+ host: localhost
@@ -0,0 +1,43 @@
1
+ [connection:veos01]
2
+ username: eapi
3
+ password: password
4
+ transport: http
5
+ host: veos01
6
+
7
+ [connection:veos02]
8
+ transport: http
9
+ host: veos02
10
+
11
+ [connection:veos03]
12
+ transport: socket
13
+ host: veos03
14
+
15
+ [connection:veos04]
16
+ host: 172.16.10.1
17
+ username: eapi
18
+ password: password
19
+ enablepwd: itsasecret
20
+ port: 1234
21
+ transport: https
22
+
23
+ [connection:veos05]
24
+ host: 172.16.131.40
25
+ username: admin
26
+ password: admin
27
+ enablepwd: password
28
+ transport: https
29
+ port: 1234
30
+ open_timeout: 12
31
+ read_timeout: 12
32
+
33
+ [connection: localhost]
34
+ transport: http_local
35
+ host: localhost
36
+
37
+ [connection:localhost]
38
+ transport: socket
39
+ host: localhost
40
+
41
+ [connection:*]
42
+ username: foo
43
+ password: bar
@@ -0,0 +1,122 @@
1
+ #
2
+ # Copyright (c) 2015, Arista Networks, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are
7
+ # met:
8
+ #
9
+ # Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # Neither the name of Arista Networks nor the names of its
17
+ # contributors may be used to endorse or promote products derived from
18
+ # this software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
24
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27
+ # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30
+ # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ require 'spec_helper'
33
+
34
+ require 'rbeapi/client'
35
+ require 'rbeapi/api/aaa'
36
+
37
+ describe Rbeapi::Api::AaaGroups do
38
+ subject { described_class.new(node) }
39
+
40
+ let(:node) do
41
+ Rbeapi::Client.config.read(fixture_file('dut.conf'))
42
+ Rbeapi::Client.connect_to('dut')
43
+ end
44
+
45
+ let(:all) do
46
+ {
47
+ 'blah' => {
48
+ type: 'radius',
49
+ servers: []
50
+ },
51
+ 'blahtwo' => {
52
+ type: 'radius',
53
+ servers: []
54
+ }
55
+ }
56
+ end
57
+
58
+ let(:blah) do
59
+ {
60
+ type: 'radius',
61
+ servers: []
62
+ }
63
+ end
64
+
65
+ let(:blahthree) do
66
+ {
67
+ type: 'tacacs+',
68
+ servers: []
69
+ }
70
+ end
71
+
72
+ let(:servers) do
73
+ [{
74
+ name: 'localhost',
75
+ auth_port: '1812',
76
+ acct_port: '1813'
77
+ }]
78
+ end
79
+
80
+ describe '#get' do
81
+ before do
82
+ node.config(['no aaa group server radius blah',
83
+ 'no aaa group server radius blahtwo',
84
+ 'no aaa group server tacacs+ blahthree',
85
+ 'aaa group server radius blah', 'exit',
86
+ 'aaa group server radius blahtwo', 'exit'])
87
+ end
88
+
89
+ it 'returns the resource for given name' do
90
+ expect(subject.get('blah')).to eq(blah)
91
+ end
92
+ end
93
+
94
+ describe '#getall' do
95
+ it 'returns all of the aaa group resources' do
96
+ expect(subject.getall).to eq(all)
97
+ end
98
+ end
99
+
100
+ describe '#create' do
101
+ it 'adds a new aaa group' do
102
+ expect(subject.create('blahthree', 'tacacs+')).to eq(true)
103
+ expect(subject.get('blahthree')).to eq(blahthree)
104
+ end
105
+ end
106
+
107
+ describe '#delete' do
108
+ it 'removes specified aaa group' do
109
+ expect(subject.get('blahthree')).to eq(blahthree)
110
+ expect(subject.delete('blahthree')).to eq(true)
111
+ expect(subject.get('blahthree')).to eq(nil)
112
+ end
113
+ end
114
+
115
+ describe '#set_servers' do
116
+ it 'removes all servers and then adds one' do
117
+ expect(subject.set_servers('blahtwo', [{ name: 'localhost' }]))
118
+ .to eq(true)
119
+ expect(subject.get('blahtwo')[:servers]).to eq(servers)
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,90 @@
1
+ #
2
+ # Copyright (c) 2015, Arista Networks, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are
7
+ # met:
8
+ #
9
+ # Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # Neither the name of Arista Networks nor the names of its
17
+ # contributors may be used to endorse or promote products derived from
18
+ # this software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
24
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27
+ # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30
+ # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ require 'spec_helper'
33
+
34
+ require 'rbeapi/client'
35
+ require 'rbeapi/api/aaa'
36
+
37
+ describe Rbeapi::Api::Aaa do
38
+ subject { described_class.new(node) }
39
+
40
+ let(:node) do
41
+ Rbeapi::Client.config.read(fixture_file('dut.conf'))
42
+ Rbeapi::Client.connect_to('dut')
43
+ end
44
+
45
+ let(:test) do
46
+ {
47
+ groups: {
48
+ 'blah' => {
49
+ type: 'radius',
50
+ servers: []
51
+ },
52
+ 'blahtwo' => {
53
+ type: 'radius',
54
+ servers: []
55
+ }
56
+ }
57
+ }
58
+ end
59
+
60
+ describe '#get' do
61
+ before do
62
+ node.config(['no aaa group server radius blah',
63
+ 'no aaa group server radius blahtwo',
64
+ 'aaa group server radius blah', 'exit',
65
+ 'aaa group server radius blahtwo', 'exit'])
66
+ end
67
+
68
+ it 'returns the resource for given name' do
69
+ expect(subject.get).to eq(test)
70
+ end
71
+
72
+ it 'returns a hash' do
73
+ expect(subject.get).to be_a_kind_of(Hash)
74
+ end
75
+
76
+ it 'has two entries' do
77
+ expect(subject.get[:groups].size).to eq(2)
78
+ end
79
+ end
80
+
81
+ describe '#groups' do
82
+ it 'returns new node instance' do
83
+ expect(subject.groups).to be_a_kind_of(Rbeapi::Api::AaaGroups)
84
+ end
85
+
86
+ it 'returns a hash' do
87
+ expect(subject.groups).to be_a_kind_of(Object)
88
+ end
89
+ end
90
+ end