rbeapi 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile +3 -1
- data/Guardfile +3 -3
- data/README.md +92 -17
- data/Rakefile +99 -4
- data/gems/README.rst +4 -0
- data/gems/inifile/.gitignore +2 -0
- data/gems/inifile/README.rst +5 -0
- data/gems/inifile/inifile.spec.tmpl +84 -0
- data/gems/net_http_unix/.gitignore +2 -0
- data/gems/net_http_unix/README.rst +5 -0
- data/gems/net_http_unix/net_http_unix.spec.tmpl +54 -0
- data/gems/netaddr/README.rst +5 -0
- data/gems/netaddr/netaddr.spec.tmpl +50 -0
- data/lib/rbeapi/api/aaa.rb +14 -17
- data/lib/rbeapi/api/acl.rb +276 -0
- data/lib/rbeapi/api/dns.rb +7 -4
- data/lib/rbeapi/api/interfaces.rb +239 -239
- data/lib/rbeapi/api/ipinterfaces.rb +5 -3
- data/lib/rbeapi/api/logging.rb +8 -5
- data/lib/rbeapi/api/mlag.rb +45 -127
- data/lib/rbeapi/api/ntp.rb +1 -4
- data/lib/rbeapi/api/ospf.rb +16 -13
- data/lib/rbeapi/api/prefixlists.rb +4 -4
- data/lib/rbeapi/api/radius.rb +34 -25
- data/lib/rbeapi/api/routemaps.rb +16 -10
- data/lib/rbeapi/api/snmp.rb +26 -13
- data/lib/rbeapi/api/staticroutes.rb +6 -5
- data/lib/rbeapi/api/stp.rb +77 -18
- data/lib/rbeapi/api/switchports.rb +20 -12
- data/lib/rbeapi/api/system.rb +6 -6
- data/lib/rbeapi/api/tacacs.rb +9 -6
- data/lib/rbeapi/api/varp.rb +15 -10
- data/lib/rbeapi/api/vlans.rb +5 -6
- data/lib/rbeapi/api.rb +56 -16
- data/lib/rbeapi/client.rb +85 -50
- data/lib/rbeapi/eapilib.rb +95 -56
- data/lib/rbeapi/netdev/snmp.rb +7 -16
- data/lib/rbeapi/utils.rb +3 -5
- data/lib/rbeapi/version.rb +1 -1
- data/rbeapi.gemspec +4 -2
- data/rbeapi.spec.tmpl +72 -0
- data/spec/support/fixtures.rb +6 -4
- data/spec/support/shared_examples_for_api_modules.rb +3 -18
- data/spec/system/api_acl_spec.rb +128 -0
- data/spec/system/api_ospf_interfaces_spec.rb +17 -14
- data/spec/system/api_ospf_spec.rb +8 -8
- data/spec/system/api_varp_interfaces_spec.rb +22 -13
- data/spec/system/api_varp_spec.rb +1 -4
- data/spec/system/rbeapi/api/interfaces_base_spec.rb +3 -4
- data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +13 -9
- data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +43 -26
- data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +7 -6
- data/spec/system/rbeapi/api/ipinterfaces_spec.rb +34 -21
- data/spec/system/rbeapi/api/mlag_interfaces_spec.rb +15 -38
- data/spec/system/rbeapi/api/mlag_spec.rb +26 -30
- data/spec/system/rbeapi/api/snmp_spec.rb +0 -3
- data/spec/system/rbeapi/api/stp_instances_spec.rb +20 -12
- data/spec/system/rbeapi/api/stp_interfaces_spec.rb +1 -3
- data/spec/system/rbeapi/api/switchports_spec.rb +14 -12
- data/spec/system/rbeapi/api/system_spec.rb +0 -3
- data/spec/system/rbeapi/api/vlans_spec.rb +19 -9
- data/spec/unit/rbeapi/api/acl/default_spec.rb +158 -0
- data/spec/unit/rbeapi/api/acl/fixture_acl_standard.text +22 -0
- data/spec/unit/rbeapi/api/interfaces/base_spec.rb +123 -0
- data/spec/unit/rbeapi/api/interfaces/ethernet_spec.rb +89 -0
- data/spec/unit/rbeapi/api/interfaces/fixture_interfaces.text +219 -0
- data/spec/unit/rbeapi/api/interfaces/portchannel_spec.rb +149 -0
- data/spec/unit/rbeapi/api/interfaces/vxlan_spec.rb +243 -0
- data/spec/unit/rbeapi/api/mlag/default_spec.rb +218 -0
- data/spec/unit/rbeapi/api/mlag/fixture_mlag.text +238 -0
- data/spec/unit/rbeapi/api/vlans/default_spec.rb +135 -0
- data/spec/unit/rbeapi/api/vlans/fixture_vlans.text +5 -0
- metadata +79 -4
- data/lib/rbeapi/api/radius.rb.old +0 -399
data/lib/rbeapi/netdev/snmp.rb
CHANGED
@@ -33,9 +33,7 @@
|
|
33
33
|
require 'rbeapi/api'
|
34
34
|
|
35
35
|
module Rbeapi
|
36
|
-
|
37
36
|
module Netdev
|
38
|
-
|
39
37
|
##
|
40
38
|
# The Netdev class is a straight port of the original PuppetX netdev
|
41
39
|
# code that existed prior to rbeapi. This should be considered a legacy
|
@@ -65,8 +63,6 @@ module Rbeapi
|
|
65
63
|
# parse_snmp_hosts parses the raw text from the `show snmp host`
|
66
64
|
# command and returns an Array of resource hashes.
|
67
65
|
#
|
68
|
-
# rubocop:disable Metrics/MethodLength
|
69
|
-
#
|
70
66
|
# @param [String] text The text of the `show snmp host` output, e.g.
|
71
67
|
# for three hosts:
|
72
68
|
#
|
@@ -237,9 +233,6 @@ module Rbeapi
|
|
237
233
|
# Group : sysops
|
238
234
|
# ```
|
239
235
|
#
|
240
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
241
|
-
# rubocop:disable Metrics/MethodLength
|
242
|
-
#
|
243
236
|
# @param [String] text The text to parse
|
244
237
|
#
|
245
238
|
# @api private
|
@@ -250,12 +243,12 @@ module Rbeapi
|
|
250
243
|
user_s.scan(/^(\w+).*?: (.*)/).each_with_object({}) do |(h, v), m|
|
251
244
|
key = SNMP_USER_PARAM[h.downcase.intern] || h.downcase.intern
|
252
245
|
m[key] = case key
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
246
|
+
when :privacy then /AES/.match(v) ? :aes128 : :des
|
247
|
+
when :version then v.sub('v2c', 'v2').intern
|
248
|
+
when :auth then v.downcase.intern
|
249
|
+
when :roles then v.sub(/ \(.*?\)/, '')
|
250
|
+
else v.downcase
|
251
|
+
end
|
259
252
|
end
|
260
253
|
end
|
261
254
|
end
|
@@ -275,8 +268,6 @@ module Rbeapi
|
|
275
268
|
# snmp_user_set creates or updates an SNMP user account on the target
|
276
269
|
# device.
|
277
270
|
#
|
278
|
-
# rubocop:disable Metrics/MethodLength
|
279
|
-
#
|
280
271
|
# @option opts [String] :name ('johndoe') The username
|
281
272
|
#
|
282
273
|
# @option opts [Array] :roles (['developers']) The group, as an Array,
|
@@ -305,7 +296,7 @@ module Rbeapi
|
|
305
296
|
if opts[:password] && version == 'v3'
|
306
297
|
privacy = opts[:privacy].to_s.scan(/aes|des/).first
|
307
298
|
fail ArgumentError,
|
308
|
-
|
299
|
+
'privacy is required when managing passwords' unless privacy
|
309
300
|
cmd += " auth #{opts[:auth] || 'sha'} #{opts[:password]} "\
|
310
301
|
"priv #{privacy} #{opts[:password]}"
|
311
302
|
end
|
data/lib/rbeapi/utils.rb
CHANGED
@@ -36,7 +36,6 @@ module Rbeapi
|
|
36
36
|
##
|
37
37
|
# Utils module
|
38
38
|
module Utils
|
39
|
-
|
40
39
|
##
|
41
40
|
# Iterates through a hash structure and converts all of the keys
|
42
41
|
# to symbols.
|
@@ -46,9 +45,9 @@ module Rbeapi
|
|
46
45
|
# @return [Hash] An updated hash structure with all keys converted to
|
47
46
|
# symboles
|
48
47
|
def self.transform_keys_to_symbols(value)
|
49
|
-
return value
|
50
|
-
hash = value.
|
51
|
-
hsh[k.to_sym] =
|
48
|
+
return value unless value.is_a?(Hash)
|
49
|
+
hash = value.each_with_object({}) do |(k, v), hsh|
|
50
|
+
hsh[k.to_sym] = transform_keys_to_symbols(v)
|
52
51
|
hsh
|
53
52
|
end
|
54
53
|
hash
|
@@ -67,4 +66,3 @@ module Rbeapi
|
|
67
66
|
end
|
68
67
|
end
|
69
68
|
end
|
70
|
-
|
data/lib/rbeapi/version.rb
CHANGED
data/rbeapi.gemspec
CHANGED
@@ -19,8 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.
|
23
|
-
spec.
|
22
|
+
spec.add_runtime_dependency 'inifile'
|
23
|
+
spec.add_runtime_dependency 'json'
|
24
|
+
spec.add_runtime_dependency 'net_http_unix'
|
25
|
+
spec.add_runtime_dependency 'netaddr'
|
24
26
|
|
25
27
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
28
|
spec.add_development_dependency 'yard'
|
data/rbeapi.spec.tmpl
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# -*- rpm-spec -*-
|
2
|
+
%global gem_name rbeapi
|
3
|
+
|
4
|
+
Name: %{?enterprise:pe-}rubygem-%{gem_name}
|
5
|
+
Version: REPLACEME
|
6
|
+
Release: 1.eos4
|
7
|
+
Summary: Arista eAPI Ruby Library for the EOS command API
|
8
|
+
|
9
|
+
Group: Development/Languages
|
10
|
+
License: New BSD
|
11
|
+
URL: https://github.com/arista-eosplus/rbeapi
|
12
|
+
Source0: %{gem_name}-%{version}.gem
|
13
|
+
|
14
|
+
%if 0%{?enterprise:1} == 1
|
15
|
+
# Use these settings for Puppet Enterprise
|
16
|
+
%global gem /opt/puppet/bin/gem
|
17
|
+
Requires: pe-rubygems
|
18
|
+
Requires: pe-ruby
|
19
|
+
Requires: pe-rubygem(net-http-unix)
|
20
|
+
Requires: pe-rubygem(inifile)
|
21
|
+
Provides: pe-rubygem(%{gem_name}) = %{version}
|
22
|
+
Provides: pe-rubygem-%{gem_name} = %{version}
|
23
|
+
%else
|
24
|
+
# Use these settings for all other installs
|
25
|
+
%global gem gem
|
26
|
+
Requires: ruby(abi) = %{rubyabi}
|
27
|
+
Provides: ruby(%{gem_name}) = %{version}-%{release}
|
28
|
+
%endif
|
29
|
+
|
30
|
+
|
31
|
+
BuildArch: noarch
|
32
|
+
|
33
|
+
%description
|
34
|
+
The Ruby Cliet for eAPI provides a native Ruby implementation for programming
|
35
|
+
Arista EOS network devices using Ruby. The Ruby client provides the ability
|
36
|
+
to build native applications in Ruby that can communicate with EOS either
|
37
|
+
locally via Unix domain sockets (on-box) or remotely over a HTTP/S transport
|
38
|
+
(off-box). It uses a standard INI-style configuration file to specify one or
|
39
|
+
more connection profiles.
|
40
|
+
|
41
|
+
The rbeapi implementation also provides an API layer for building native Ruby
|
42
|
+
objects that allow for configuration and state extraction of EOS nodes. The API
|
43
|
+
layer provides a consistent implementation for working with EOS configuration
|
44
|
+
resources. The implementation of the API layer is highly extensible and can be
|
45
|
+
used as a foundation for building custom data models.
|
46
|
+
|
47
|
+
The library is freely provided to the open source community for building robust
|
48
|
+
applications using Arista EOS eAPI. Support is provided as best effort through
|
49
|
+
Github iusses.
|
50
|
+
|
51
|
+
%prep
|
52
|
+
%setup -q -D -T -n .
|
53
|
+
|
54
|
+
%install
|
55
|
+
mkdir -p %{buildroot}
|
56
|
+
install %{SOURCE0} %{buildroot}/
|
57
|
+
|
58
|
+
%files
|
59
|
+
/%{gem_name}-%{version}.gem
|
60
|
+
|
61
|
+
%post
|
62
|
+
%{gem} install --local /%{gem_name}-%{version}.gem > /dev/null 2>&1
|
63
|
+
|
64
|
+
%preun
|
65
|
+
%{gem} uninstall %{gem_name} --version '= %{version}' > /dev/null 2>&1
|
66
|
+
|
67
|
+
%changelog
|
68
|
+
* Tue May 21 2015 Jere Julian - 0.1.0-2
|
69
|
+
- Ubuntu requires we manually create the buildroot
|
70
|
+
|
71
|
+
* Tue Mar 17 2015 Jere Julian - 0.1.0-1
|
72
|
+
- Initial package
|
data/spec/support/fixtures.rb
CHANGED
@@ -52,8 +52,7 @@ module FixtureHelpers
|
|
52
52
|
# `spec/fixtures/fixture_foo.json` will be loaded and returned. This method
|
53
53
|
# is memoized across the life of the process.
|
54
54
|
#
|
55
|
-
# rubocop:disable Metrics/
|
56
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
55
|
+
# rubocop:disable Metrics/MethodLength,
|
57
56
|
#
|
58
57
|
# @param [Symbol] key The fixture name without the `fixture_` prefix or
|
59
58
|
# `.json` suffix.
|
@@ -73,11 +72,13 @@ module FixtureHelpers
|
|
73
72
|
|
74
73
|
yaml = Pathname.new(File.join(dir, "fixture_#{key}.yaml"))
|
75
74
|
json = Pathname.new(File.join(dir, "fixture_#{key}.json"))
|
75
|
+
text = Pathname.new(File.join(dir, "fixture_#{key}.text"))
|
76
76
|
|
77
77
|
data = if yaml.exist?; then YAML.load(File.read(yaml))
|
78
78
|
elsif json.exist?; then JSON.load(File.read(json))
|
79
|
-
|
80
|
-
|
79
|
+
elsif text.exist?; then File.read(text)
|
80
|
+
else fail "could not load YAML, JSON or TEXT fixture #{key} "\
|
81
|
+
"tried:\n #{yaml}\n #{json} #{text}"
|
81
82
|
end
|
82
83
|
|
83
84
|
Fixtures[key] = data
|
@@ -86,6 +87,7 @@ module FixtureHelpers
|
|
86
87
|
when :ruby then data
|
87
88
|
when :json then JSON.pretty_generate(data)
|
88
89
|
when :yaml then YAML.dump(data)
|
90
|
+
when :text then data
|
89
91
|
else fail ArgumentError, "unknown format #{opts[:format].inspect}"
|
90
92
|
end
|
91
93
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
RSpec.shared_examples 'a configurable entity' do |opts|
|
2
|
-
|
3
2
|
before(:each) do
|
4
3
|
allow(subject.node).to receive(:config)
|
5
4
|
end
|
6
5
|
|
7
6
|
applies_to = opts.fetch(:applies_to, [])
|
8
|
-
if applies_to.include?(opts[:args[0,2]])
|
7
|
+
if applies_to.include?(opts[:args[0, 2]]) || applies_to.empty?
|
9
8
|
context 'with node#config' do
|
10
9
|
[:create, :delete, :default].each do |action|
|
11
10
|
it "calls #{action} using #{opts[:args]}" do
|
@@ -18,13 +17,12 @@ RSpec.shared_examples 'a configurable entity' do |opts|
|
|
18
17
|
end
|
19
18
|
|
20
19
|
RSpec.shared_examples 'a tristate attr' do |opts|
|
21
|
-
|
22
20
|
before(:each) do
|
23
21
|
allow(subject.node).to receive(:config)
|
24
22
|
end
|
25
23
|
|
26
24
|
applies_to = opts.fetch(:applies_to, [])
|
27
|
-
if applies_to.include?(opts[:args[0,2]])
|
25
|
+
if applies_to.include?(opts[:args[0, 2]]) || applies_to.empty?
|
28
26
|
context 'with node#config' do
|
29
27
|
it "configures with #{opts[:name]}" do
|
30
28
|
expect(subject.node).to receive(:config).with(opts[:config])
|
@@ -36,7 +34,7 @@ RSpec.shared_examples 'a tristate attr' do |opts|
|
|
36
34
|
subject.send(opts[:name], *opts[:args])
|
37
35
|
end
|
38
36
|
|
39
|
-
it
|
37
|
+
it 'defaults' do
|
40
38
|
expect(subject.node).to receive(:config).with(opts[:default])
|
41
39
|
subject.send(opts[:name], *opts[:args], default: true)
|
42
40
|
end
|
@@ -45,7 +43,6 @@ RSpec.shared_examples 'a tristate attr' do |opts|
|
|
45
43
|
end
|
46
44
|
|
47
45
|
RSpec.shared_examples 'a settable attr' do |opts|
|
48
|
-
|
49
46
|
before(:each) do
|
50
47
|
allow(subject.node).to receive(:config)
|
51
48
|
end
|
@@ -59,7 +56,6 @@ RSpec.shared_examples 'a settable attr' do |opts|
|
|
59
56
|
end
|
60
57
|
|
61
58
|
RSpec.shared_examples 'a creatable entity' do |args, setup, block|
|
62
|
-
|
63
59
|
before(:each) do
|
64
60
|
subject.node.config(setup)
|
65
61
|
end
|
@@ -74,7 +70,6 @@ RSpec.shared_examples 'a creatable entity' do |args, setup, block|
|
|
74
70
|
end
|
75
71
|
|
76
72
|
RSpec.shared_examples 'a deletable entity' do |args, setup, block|
|
77
|
-
|
78
73
|
before(:each) do
|
79
74
|
subject.node.config(setup)
|
80
75
|
end
|
@@ -89,7 +84,6 @@ RSpec.shared_examples 'a deletable entity' do |args, setup, block|
|
|
89
84
|
end
|
90
85
|
|
91
86
|
RSpec.shared_examples 'a configurable attr' do |opts|
|
92
|
-
|
93
87
|
before(:each) do
|
94
88
|
subject.node.config(opts[:setup])
|
95
89
|
end
|
@@ -104,21 +98,12 @@ RSpec.shared_examples 'a configurable attr' do |opts|
|
|
104
98
|
end
|
105
99
|
|
106
100
|
RSpec.shared_examples 'single entity' do |opts|
|
107
|
-
|
108
101
|
describe 'match entity attributes from node' do
|
109
102
|
let(:entity) { subject.get(opts[:args]) }
|
110
103
|
opts[:entity].each do |key, value|
|
111
104
|
it "has #{key} with #{value}" do
|
112
|
-
binding.pry
|
113
105
|
expect(entity[key]).to eq(value)
|
114
106
|
end
|
115
107
|
end
|
116
108
|
end
|
117
109
|
end
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'rbeapi/client'
|
4
|
+
require 'rbeapi/api/acl'
|
5
|
+
|
6
|
+
describe Rbeapi::Api::Acl do
|
7
|
+
subject { described_class.new(node) }
|
8
|
+
|
9
|
+
let(:config) { Rbeapi::Client::Config.new(filename: get_fixture('dut.conf')) }
|
10
|
+
let(:node) { Rbeapi::Client.connect_to('dut') }
|
11
|
+
|
12
|
+
before do
|
13
|
+
node.config(['no ip access-list standard test1',
|
14
|
+
'ip access-list standard test1',
|
15
|
+
'permit host 1.2.3.4 log',
|
16
|
+
'permit 1.2.3.4 255.255.0.0 log',
|
17
|
+
'deny any',
|
18
|
+
'permit 5.6.7.0/24',
|
19
|
+
'permit 9.10.11.0 255.255.255.0 log',
|
20
|
+
'exit'])
|
21
|
+
node.config(['no ip access-list standard test2',
|
22
|
+
'ip access-list standard test2',
|
23
|
+
'deny 16.0.0.0/8',
|
24
|
+
'exit'])
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:test1_entries) do
|
28
|
+
{ '10' => { seqno: '10', action: 'permit', srcaddr: '1.2.3.4',
|
29
|
+
srcprefixlen: '255.255.255.255', log: 'log' },
|
30
|
+
'20' => { seqno: '20', action: 'permit', srcaddr: '1.2.3.4',
|
31
|
+
srcprefixlen: '255.255.0.0', log: 'log' },
|
32
|
+
'30' => { seqno: '30', action: 'deny', srcaddr: '0.0.0.0',
|
33
|
+
srcprefixlen: '255.255.255.255', log: nil },
|
34
|
+
'40' => { seqno: '40', action: 'permit', srcaddr: '5.6.7.0',
|
35
|
+
srcprefixlen: '24', log: nil },
|
36
|
+
'50' => { seqno: '50', action: 'permit', srcaddr: '9.10.11.0',
|
37
|
+
srcprefixlen: '255.255.255.0', log: 'log' }
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:test2_entries) do
|
42
|
+
{ '10' => { seqno: '10', action: 'deny', srcaddr: '16.0.0.0',
|
43
|
+
srcprefixlen: '8', log: nil }
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#get' do
|
48
|
+
it 'returns the test ACL entries' do
|
49
|
+
expect(subject.get('test1')).to eq(test1_entries)
|
50
|
+
expect(subject.get('test2')).to eq(test2_entries)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#getall' do
|
55
|
+
let(:collection) { subject.getall }
|
56
|
+
|
57
|
+
it 'includes test1 and test2 ACLs' do
|
58
|
+
expect(collection).to include('test1')
|
59
|
+
expect(collection).to include('test2')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'is a kind of hash' do
|
63
|
+
expect(collection).to be_a_kind_of(Hash)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#create' do
|
68
|
+
before { node.config('no ip access-list standard abc') }
|
69
|
+
|
70
|
+
it 'creates a new ACL resource' do
|
71
|
+
expect(subject.get('abc')).to be_nil
|
72
|
+
expect(subject.create('abc')).to be_truthy
|
73
|
+
expect(subject.get('abc')).not_to be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#delete' do
|
78
|
+
it 'deletes the abc ACL resource' do
|
79
|
+
expect(subject.get('abc')).not_to be_nil
|
80
|
+
expect(subject.delete('abc')).to be_truthy
|
81
|
+
expect(subject.get('abc')).to be_nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#default' do
|
86
|
+
before { node.config('ip access-list standard xyz') }
|
87
|
+
|
88
|
+
it 'sets ACL xyz to default value' do
|
89
|
+
expect(subject.get('xyz')).to be_truthy
|
90
|
+
expect(subject.default('xyz')).to be_truthy
|
91
|
+
expect(subject.get('xyz')).to be_nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#update_entry' do
|
96
|
+
let(:update_entry) do
|
97
|
+
{ seqno: '50', action: 'deny', srcaddr: '100.0.0.0',
|
98
|
+
srcprefixlen: '8', log: nil }
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'Change entry 50 to values in update_entry' do
|
102
|
+
expect(subject.get('test1')['50'][:action]).to eq('permit')
|
103
|
+
expect(subject.update_entry('test1', update_entry)).to be_truthy
|
104
|
+
expect(subject.get('test1')['50']).to eq(update_entry)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#add_entry' do
|
109
|
+
let(:new_entry) do
|
110
|
+
{ seqno: '60', action: 'deny', srcaddr: '1.2.3.0',
|
111
|
+
srcprefixlen: '24', log: 'log' }
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'Add entry 60 to the test1 ACL' do
|
115
|
+
expect(subject.get('test1')['60']).to be_nil
|
116
|
+
expect(subject.add_entry('test1', new_entry)).to be_truthy
|
117
|
+
expect(subject.get('test1')['60']).to eq(new_entry)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#remove_entry' do
|
122
|
+
it 'Remove entry 30 from the test1 ACL' do
|
123
|
+
expect(subject.get('test1')['30']).to be_truthy
|
124
|
+
expect(subject.remove_entry('test1', '30')).to be_truthy
|
125
|
+
expect(subject.get('test1')['30']).to be_nil
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -7,13 +7,14 @@ describe Rbeapi::Api::OspfInterfaces do
|
|
7
7
|
subject { described_class.new(node) }
|
8
8
|
|
9
9
|
let(:config) { Rbeapi::Client::Config.new(filename: get_fixture('dut.conf')) }
|
10
|
-
let(:node) { Rbeapi::Client.connect_to('
|
10
|
+
let(:node) { Rbeapi::Client.connect_to('dut') }
|
11
11
|
|
12
12
|
describe '#get' do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
before do
|
14
|
+
node.config(['default interface Ethernet1', 'interface Ethernet1',
|
15
|
+
'no switchport', 'ip address 88.99.99.99/24', 'exit',
|
16
|
+
'default interface Ethernet2'])
|
17
|
+
end
|
17
18
|
|
18
19
|
it 'returns an ospf interface resource instance' do
|
19
20
|
expect(subject.get('Ethernet1')).not_to be_nil
|
@@ -25,10 +26,11 @@ describe Rbeapi::Api::OspfInterfaces do
|
|
25
26
|
end
|
26
27
|
|
27
28
|
describe '#getall' do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
before do
|
30
|
+
node.config(['default interface Ethernet1', 'interface Ethernet1',
|
31
|
+
'no switchport', 'ip address 88.99.99.99/24', 'exit',
|
32
|
+
'default interface Ethernet2'])
|
33
|
+
end
|
32
34
|
|
33
35
|
it 'returns the ospf resource collection' do
|
34
36
|
expect(subject.getall).to be_a_kind_of(Hash)
|
@@ -41,17 +43,18 @@ describe Rbeapi::Api::OspfInterfaces do
|
|
41
43
|
it 'does not include an instance of Ethernet2' do
|
42
44
|
expect(subject.getall).not_to include('Ethernet2')
|
43
45
|
end
|
44
|
-
|
45
46
|
end
|
46
47
|
|
47
48
|
describe '#set_network_type' do
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
before do
|
50
|
+
node.config(['default interface Ethernet1', 'interface Ethernet1',
|
51
|
+
'no switchport', 'ip address 88.99.99.99/24', 'exit'])
|
52
|
+
end
|
51
53
|
|
52
54
|
it 'configures the ospf interface type to point-to-point' do
|
53
55
|
expect(subject.get('Ethernet1')['network_type']).to eq('broadcast')
|
54
|
-
expect(subject.set_network_type('Ethernet1', value: 'point-to-point'))
|
56
|
+
expect(subject.set_network_type('Ethernet1', value: 'point-to-point'))
|
57
|
+
.to be_truthy
|
55
58
|
expect(subject.get('Ethernet1')['network_type']).to eq('point-to-point')
|
56
59
|
end
|
57
60
|
end
|
@@ -7,10 +7,9 @@ describe Rbeapi::Api::Ospf do
|
|
7
7
|
subject { described_class.new(node) }
|
8
8
|
|
9
9
|
let(:config) { Rbeapi::Client::Config.new(filename: get_fixture('dut.conf')) }
|
10
|
-
let(:node) { Rbeapi::Client.connect_to('
|
10
|
+
let(:node) { Rbeapi::Client.connect_to('dut') }
|
11
11
|
|
12
12
|
describe '#get' do
|
13
|
-
|
14
13
|
before { node.config(['no router ospf 1', 'router ospf 1']) }
|
15
14
|
|
16
15
|
let(:entity) do
|
@@ -23,7 +22,6 @@ describe Rbeapi::Api::Ospf do
|
|
23
22
|
end
|
24
23
|
|
25
24
|
describe '#getall' do
|
26
|
-
|
27
25
|
before { node.config(['no router ospf 1', 'router ospf 1']) }
|
28
26
|
|
29
27
|
let(:collection) { subject.getall }
|
@@ -39,7 +37,6 @@ describe Rbeapi::Api::Ospf do
|
|
39
37
|
it 'is a kind of hash' do
|
40
38
|
expect(collection).to be_a_kind_of(Hash)
|
41
39
|
end
|
42
|
-
|
43
40
|
end
|
44
41
|
|
45
42
|
describe '#interfaces' do
|
@@ -83,17 +80,21 @@ describe Rbeapi::Api::Ospf do
|
|
83
80
|
|
84
81
|
it 'adds the network with area to the ospf process' do
|
85
82
|
expect(subject.get('1')['areas']).to be_empty
|
86
|
-
expect(subject.add_network('1', '192.168.10.0/24', '0.0.0.0'))
|
83
|
+
expect(subject.add_network('1', '192.168.10.0/24', '0.0.0.0'))
|
84
|
+
.to be_truthy
|
87
85
|
expect(subject.get('1')['areas']['0.0.0.0']).to include('192.168.10.0/24')
|
88
86
|
end
|
89
87
|
end
|
90
88
|
|
91
89
|
describe '#remove_network' do
|
92
|
-
before
|
90
|
+
before do
|
91
|
+
node.config(['router ospf 1', 'network 192.168.10.10/24 area 0.0.0.0'])
|
92
|
+
end
|
93
93
|
|
94
94
|
it 'removes the network with area to the ospf process' do
|
95
95
|
expect(subject.get('1')['areas']['0.0.0.0']).to include('192.168.10.0/24')
|
96
|
-
expect(subject.remove_network('1', '192.168.10.0/24', '0.0.0.0'))
|
96
|
+
expect(subject.remove_network('1', '192.168.10.0/24', '0.0.0.0'))
|
97
|
+
.to be_truthy
|
97
98
|
expect(subject.get('1')['areas']).to be_empty
|
98
99
|
end
|
99
100
|
end
|
@@ -107,5 +108,4 @@ describe Rbeapi::Api::Ospf do
|
|
107
108
|
expect(subject.get('1')['redistribute']).to include('static')
|
108
109
|
end
|
109
110
|
end
|
110
|
-
|
111
111
|
end
|
@@ -7,12 +7,15 @@ describe Rbeapi::Api::VarpInterfaces do
|
|
7
7
|
subject { described_class.new(node) }
|
8
8
|
|
9
9
|
let(:config) { Rbeapi::Client::Config.new(filename: get_fixture('dut.conf')) }
|
10
|
-
let(:node) { Rbeapi::Client.connect_to('
|
10
|
+
let(:node) { Rbeapi::Client.connect_to('dut') }
|
11
11
|
|
12
12
|
describe '#get' do
|
13
|
-
before
|
14
|
-
|
15
|
-
|
13
|
+
before do
|
14
|
+
node.config(['ip virtual-router mac-address aabb.ccdd.eeff',
|
15
|
+
'default interface vlan 100', 'interface vlan 100',
|
16
|
+
'ip address 99.99.99.99/24',
|
17
|
+
'ip virtual-router address 99.99.99.98', 'exit'])
|
18
|
+
end
|
16
19
|
|
17
20
|
it 'returns an instance for vlan 100' do
|
18
21
|
expect(subject.get('Vlan100')).not_to be_nil
|
@@ -24,9 +27,12 @@ describe Rbeapi::Api::VarpInterfaces do
|
|
24
27
|
end
|
25
28
|
|
26
29
|
describe '#getall' do
|
27
|
-
before
|
28
|
-
|
29
|
-
|
30
|
+
before do
|
31
|
+
node.config(['ip virtual-router mac-address aabb.ccdd.eeff',
|
32
|
+
'default interface vlan 100', 'interface vlan 100',
|
33
|
+
'ip address 99.99.99.99/24',
|
34
|
+
'ip virtual-router address 99.99.99.98', 'exit'])
|
35
|
+
end
|
30
36
|
|
31
37
|
it 'returns a collection that includes vlan 100' do
|
32
38
|
expect(subject.getall).to include('Vlan100')
|
@@ -38,13 +44,16 @@ describe Rbeapi::Api::VarpInterfaces do
|
|
38
44
|
end
|
39
45
|
|
40
46
|
describe '#set_addresses' do
|
41
|
-
before
|
42
|
-
|
43
|
-
|
47
|
+
before do
|
48
|
+
node.config(['ip virtual-router mac-address aabb.ccdd.eeff',
|
49
|
+
'default interface vlan 100', 'interface vlan 100',
|
50
|
+
'ip address 99.99.99.99/24', 'exit'])
|
51
|
+
end
|
44
52
|
|
45
53
|
it 'adds new address to the list of addresses' do
|
46
54
|
expect(subject.get('Vlan100')['addresses']).not_to include('99.99.99.98')
|
47
|
-
expect(subject.set_addresses('Vlan100', value: ['99.99.99.98']))
|
55
|
+
expect(subject.set_addresses('Vlan100', value: ['99.99.99.98']))
|
56
|
+
.to be_truthy
|
48
57
|
expect(subject.get('Vlan100')['addresses']).to include('99.99.99.98')
|
49
58
|
end
|
50
59
|
|
@@ -52,9 +61,9 @@ describe Rbeapi::Api::VarpInterfaces do
|
|
52
61
|
node.config(['interface vlan 100', 'ip address 99.99.99.99/24',
|
53
62
|
'ip virtual-router address 99.99.99.98'])
|
54
63
|
expect(subject.get('Vlan100')['addresses']).to include('99.99.99.98')
|
55
|
-
expect(subject.set_addresses('Vlan100', value: ['99.99.99.97']))
|
64
|
+
expect(subject.set_addresses('Vlan100', value: ['99.99.99.97']))
|
65
|
+
.to be_truthy
|
56
66
|
expect(subject.get('Vlan100')['addresses']).not_to include('99.99.99.98')
|
57
67
|
end
|
58
|
-
|
59
68
|
end
|
60
69
|
end
|
@@ -7,10 +7,9 @@ describe Rbeapi::Api::Varp do
|
|
7
7
|
subject { described_class.new(node) }
|
8
8
|
|
9
9
|
let(:config) { Rbeapi::Client::Config.new(filename: get_fixture('dut.conf')) }
|
10
|
-
let(:node) { Rbeapi::Client.connect_to('
|
10
|
+
let(:node) { Rbeapi::Client.connect_to('dut') }
|
11
11
|
|
12
12
|
describe '#get' do
|
13
|
-
|
14
13
|
it 'returns a varp resource instance' do
|
15
14
|
expect(subject.get).to be_a_kind_of(Hash)
|
16
15
|
end
|
@@ -38,7 +37,5 @@ describe Rbeapi::Api::Varp do
|
|
38
37
|
expect(subject.set_mac_address(value: 'aa:bb:cc:dd:ee:ff')).to be_truthy
|
39
38
|
expect(subject.get['mac_address']).to eq('aa:bb:cc:dd:ee:ff')
|
40
39
|
end
|
41
|
-
|
42
40
|
end
|
43
|
-
|
44
41
|
end
|
@@ -12,7 +12,6 @@ describe Rbeapi::Api::Interfaces do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#get' do
|
15
|
-
|
16
15
|
let(:entity) do
|
17
16
|
{ name: 'Loopback0', type: 'generic', description: '', shutdown: false }
|
18
17
|
end
|
@@ -34,7 +33,7 @@ describe Rbeapi::Api::Interfaces do
|
|
34
33
|
it 'returns a hash collection' do
|
35
34
|
expect(subject.getall).to be_a_kind_of(Hash)
|
36
35
|
end
|
37
|
-
|
36
|
+
end
|
38
37
|
|
39
38
|
describe '#create' do
|
40
39
|
before { node.config('no interface Loopback0') }
|
@@ -70,7 +69,8 @@ describe Rbeapi::Api::Interfaces do
|
|
70
69
|
it 'sets the description value on the interface' do
|
71
70
|
node.config(['interface Loopback0', 'no description'])
|
72
71
|
expect(subject.get('Loopback0')[:description]).to be_empty
|
73
|
-
expect(subject.set_description('Loopback0', value: 'foo bar'))
|
72
|
+
expect(subject.set_description('Loopback0', value: 'foo bar'))
|
73
|
+
.to be_truthy
|
74
74
|
expect(subject.get('Loopback0')[:description]).to eq('foo bar')
|
75
75
|
end
|
76
76
|
end
|
@@ -91,4 +91,3 @@ describe Rbeapi::Api::Interfaces do
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|