rbeapi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/.gitignore +35 -0
  2. data/Gemfile +25 -0
  3. data/Guardfile +15 -0
  4. data/LICENSE +28 -0
  5. data/README.md +218 -0
  6. data/Rakefile +12 -0
  7. data/lib/rbeapi.rb +32 -0
  8. data/lib/rbeapi/api.rb +135 -0
  9. data/lib/rbeapi/api/aaa.rb +410 -0
  10. data/lib/rbeapi/api/dns.rb +198 -0
  11. data/lib/rbeapi/api/interfaces.rb +1193 -0
  12. data/lib/rbeapi/api/ipinterfaces.rb +328 -0
  13. data/lib/rbeapi/api/logging.rb +157 -0
  14. data/lib/rbeapi/api/mlag.rb +519 -0
  15. data/lib/rbeapi/api/ntp.rb +201 -0
  16. data/lib/rbeapi/api/ospf.rb +214 -0
  17. data/lib/rbeapi/api/prefixlists.rb +98 -0
  18. data/lib/rbeapi/api/radius.rb +317 -0
  19. data/lib/rbeapi/api/radius.rb.old +399 -0
  20. data/lib/rbeapi/api/routemaps.rb +100 -0
  21. data/lib/rbeapi/api/snmp.rb +427 -0
  22. data/lib/rbeapi/api/staticroutes.rb +88 -0
  23. data/lib/rbeapi/api/stp.rb +381 -0
  24. data/lib/rbeapi/api/switchports.rb +272 -0
  25. data/lib/rbeapi/api/system.rb +87 -0
  26. data/lib/rbeapi/api/tacacs.rb +236 -0
  27. data/lib/rbeapi/api/varp.rb +181 -0
  28. data/lib/rbeapi/api/vlans.rb +338 -0
  29. data/lib/rbeapi/client.rb +454 -0
  30. data/lib/rbeapi/eapilib.rb +334 -0
  31. data/lib/rbeapi/netdev/snmp.rb +370 -0
  32. data/lib/rbeapi/utils.rb +70 -0
  33. data/lib/rbeapi/version.rb +37 -0
  34. data/rbeapi.gemspec +32 -0
  35. data/spec/fixtures/dut.conf +5 -0
  36. data/spec/spec_helper.rb +22 -0
  37. data/spec/support/fixtures.rb +114 -0
  38. data/spec/support/shared_examples_for_api_modules.rb +124 -0
  39. data/spec/system/api_ospf_interfaces_spec.rb +58 -0
  40. data/spec/system/api_ospf_spec.rb +111 -0
  41. data/spec/system/api_varp_interfaces_spec.rb +60 -0
  42. data/spec/system/api_varp_spec.rb +44 -0
  43. data/spec/system/rbeapi/api/dns_spec.rb +77 -0
  44. data/spec/system/rbeapi/api/interfaces_base_spec.rb +94 -0
  45. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +135 -0
  46. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +188 -0
  47. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +115 -0
  48. data/spec/system/rbeapi/api/ipinterfaces_spec.rb +97 -0
  49. data/spec/system/rbeapi/api/logging_spec.rb +65 -0
  50. data/spec/system/rbeapi/api/mlag_interfaces_spec.rb +80 -0
  51. data/spec/system/rbeapi/api/mlag_spec.rb +94 -0
  52. data/spec/system/rbeapi/api/ntp_spec.rb +76 -0
  53. data/spec/system/rbeapi/api/snmp_spec.rb +68 -0
  54. data/spec/system/rbeapi/api/stp_instances_spec.rb +61 -0
  55. data/spec/system/rbeapi/api/stp_interfaces_spec.rb +71 -0
  56. data/spec/system/rbeapi/api/stp_spec.rb +57 -0
  57. data/spec/system/rbeapi/api/switchports_spec.rb +135 -0
  58. data/spec/system/rbeapi/api/system_spec.rb +38 -0
  59. data/spec/system/rbeapi/api/vlans_spec.rb +121 -0
  60. metadata +274 -0
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rbeapi/client'
4
+ require 'rbeapi/api/mlag'
5
+
6
+ describe Rbeapi::Api::MlagInterfaces do
7
+ subject { described_class.new(node) }
8
+
9
+ let(:node) do
10
+ Rbeapi::Client.config.read(fixture_file('dut.conf'))
11
+ Rbeapi::Client.connect_to('dut')
12
+ end
13
+
14
+ describe '#get' do
15
+
16
+ let(:entity) do
17
+ { mlag_id: '1' }
18
+ end
19
+
20
+ before { node.config(['interface Port-Channel1', 'mlag 1']) }
21
+
22
+ it 'returns the mlag interface resource' do
23
+ expect(subject.get('Port-Channel1')).to eq(entity)
24
+ end
25
+ end
26
+
27
+ describe '#getall' do
28
+ before { node.config(['interface Port-Channel1', 'mlag 1']) }
29
+
30
+ it 'returns the interface collection' do
31
+ expect(subject.getall).to include('Port-Channel1')
32
+ end
33
+
34
+ it 'returns a hash collection' do
35
+ expect(subject.getall).to be_a_kind_of(Hash)
36
+ end
37
+ end
38
+
39
+ describe '#create' do
40
+ before { node.config(['interface Port-Channel1', 'no mlag']) }
41
+
42
+ it 'creates a new mlag interface resource' do
43
+ expect(subject.get('Port-Channel1')).to be_nil
44
+ expect(subject.create('Port-Channel1', '1')).to be_truthy
45
+ expect(subject.get('Port-Channel1')).not_to be_nil
46
+ end
47
+ end
48
+
49
+ describe '#delete' do
50
+ before { node.config(['interface Port-Channel1', 'mlag 1']) }
51
+
52
+ it 'deletes a switchport resource' do
53
+ expect(subject.get('Port-Channel1')).not_to be_nil
54
+ expect(subject.delete('Port-Channel1')).to be_truthy
55
+ expect(subject.get('Port-Channel1')).to be_nil
56
+ end
57
+ end
58
+
59
+ describe '#default' do
60
+ before { node.config(['interface Port-Channel1', 'mlag 1']) }
61
+
62
+ it 'sets Port-Channel1 to default' do
63
+ expect(subject.get('Port-Channel1')).not_to be_nil
64
+ expect(subject.default('Port-Channel1')).to be_truthy
65
+ expect(subject.get('Port-Channel1')).to be_nil
66
+ end
67
+ end
68
+
69
+ describe '#set_mlag_id' do
70
+ before { node.config(['interface Port-Channel1', 'no mlag']) }
71
+
72
+ it 'sets Port-Channel1 to default' do
73
+ expect(subject.get('Port-Channel1')).to be_nil
74
+ expect(subject.set_mlag_id('Port-Channel1', value: '1')).to be_truthy
75
+ expect(subject.get('Port-Channel1')[:mlag_id]).to eq('1')
76
+ end
77
+ end
78
+
79
+ end
80
+
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rbeapi/client'
4
+ require 'rbeapi/api/mlag'
5
+
6
+ describe Rbeapi::Api::Mlag do
7
+ subject { described_class.new(node) }
8
+
9
+ let(:node) do
10
+ Rbeapi::Client.config.read(fixture_file('dut.conf'))
11
+ Rbeapi::Client.connect_to('dut')
12
+ end
13
+
14
+ describe '#get' do
15
+
16
+ let(:keys) do
17
+ [ :domain_id, :local_interface, :peer_address, :peer_link, :shutdown,
18
+ :interfaces ]
19
+ end
20
+
21
+ before { node.config('default mlag configuration') }
22
+
23
+ it 'contains all required keys' do
24
+ keys.each do |key|
25
+ expect(subject.get).to include(key)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#set_domain_id' do
31
+ before { node.config('default mlag configuration') }
32
+
33
+ it 'configures the mlag domain-id value' do
34
+ expect(subject.get[:domain_id]).to be_empty
35
+ expect(subject.set_domain_id(value: 'foo')).to be_truthy
36
+ expect(subject.get[:domain_id]).to eq('foo')
37
+ end
38
+ end
39
+
40
+ describe '#set_local_interface' do
41
+ before { node.config(['default mlag configuration', 'interface vlan4094']) }
42
+
43
+ it 'configures the mlag local interface value' do
44
+ expect(subject.get[:local_interface]).to be_empty
45
+ expect(subject.set_local_interface(value: 'Vlan4094')).to be_truthy
46
+ expect(subject.get[:local_interface]).to eq('Vlan4094')
47
+ end
48
+ end
49
+
50
+ describe '#set_peer_link' do
51
+ before { node.config(['default mlag configuration',
52
+ 'default interface Ethernet1']) }
53
+
54
+ it 'configures the mlag peer link value' do
55
+ expect(subject.get[:peer_link]).to be_empty
56
+ expect(subject.set_peer_link(value: 'Ethernet1')).to be_truthy
57
+ expect(subject.get[:peer_link]).to eq('Ethernet1')
58
+ end
59
+ end
60
+
61
+ describe '#set_peer_address' do
62
+ before { node.config(['default mlag configuration',
63
+ 'default interface Ethernet1']) }
64
+
65
+ it 'configures the mlag peer address value' do
66
+ expect(subject.get[:peer_address]).to be_empty
67
+ expect(subject.set_peer_address(value: '1.1.1.1')).to be_truthy
68
+ expect(subject.get[:peer_address]).to eq('1.1.1.1')
69
+ end
70
+ end
71
+
72
+ describe '#set_shutdown' do
73
+ it 'configures mlag to be enabled' do
74
+ node.config(['mlag configuration', 'shutdown'])
75
+ expect(subject.get[:shutdown]).to be_truthy
76
+ expect(subject.set_shutdown(value: false)).to be_truthy
77
+ expect(subject.get[:shutdown]).to be_falsy
78
+ end
79
+
80
+ it 'configures mlag to be disabled' do
81
+ node.config(['mlag configuration', 'no shutdown'])
82
+ expect(subject.get[:shutdown]).to be_falsy
83
+ expect(subject.set_shutdown(value: true)).to be_truthy
84
+ expect(subject.get[:shutdown]).to be_truthy
85
+ end
86
+ end
87
+
88
+ describe '#interfaces' do
89
+ it 'is a kind of MlagInterfaces' do
90
+ expect(subject.interfaces).to be_a_kind_of(Rbeapi::Api::MlagInterfaces)
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rbeapi/client'
4
+ require 'rbeapi/api/ntp'
5
+
6
+ describe Rbeapi::Api::Ntp do
7
+ subject { described_class.new(node) }
8
+
9
+ let(:node) do
10
+ Rbeapi::Client.config.read(fixture_file('dut.conf'))
11
+ Rbeapi::Client.connect_to('dut')
12
+ end
13
+
14
+ describe '#get' do
15
+ let(:resource) { subject.get }
16
+
17
+ it 'contains the source_interface key' do
18
+ expect(resource).to include(:source_interface)
19
+ end
20
+
21
+ it 'contains the servers key' do
22
+ expect(resource).to include(:servers)
23
+ end
24
+
25
+ it 'returns servers as an Hash' do
26
+ expect(resource[:servers]).to be_a_kind_of(Hash)
27
+ end
28
+ end
29
+
30
+ describe '#set_source_interface' do
31
+ before { node.config('no ntp source') }
32
+
33
+ it 'sets the ntp source interface value' do
34
+ expect(subject.get[:source_interface]).to be_empty
35
+ expect(subject.set_source_interface(value: 'Loopback0')).to be_truthy
36
+ expect(subject.get[:source_interface]).to eq('Loopback0')
37
+ end
38
+ end
39
+
40
+ describe '#add_server' do
41
+ before { node.config('no ntp server foo') }
42
+
43
+ it 'adds the host to the list of servers' do
44
+ expect(subject.get[:servers]).not_to include('foo')
45
+ expect(subject.add_server('foo')).to be_truthy
46
+ expect(subject.get[:servers]).to include('foo')
47
+ end
48
+ end
49
+
50
+ describe '#remove_server' do
51
+ before { node.config('ntp server foo') }
52
+
53
+ it 'adds the server to the list of ntp servers' do
54
+ expect(subject.get[:servers]).to include('foo')
55
+ expect(subject.remove_server('foo')).to be_truthy
56
+ expect(subject.get[:servers]).not_to include('foo')
57
+ end
58
+ end
59
+
60
+ describe '#set_prefer' do
61
+ it 'configures the ntp server with the prefer keyword' do
62
+ node.config('no ntp server foo')
63
+ expect(subject.get[:servers]).not_to include('foo')
64
+ expect(subject.set_prefer('foo', true)).to be_truthy
65
+ expect(subject.get[:servers]).to include('foo')
66
+ expect(subject.get[:servers]['foo'][:prefer]).to be_truthy
67
+ end
68
+
69
+ it 'unconfigures the prefer value' do
70
+ node.config('ntp server foo prefer')
71
+ expect(subject.get[:servers]['foo'][:prefer]).to be_truthy
72
+ expect(subject.set_prefer('foo', false)).to be_truthy
73
+ expect(subject.get[:servers]['foo'][:prefer]).to be_falsy
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rbeapi/client'
4
+ require 'rbeapi/api/snmp'
5
+
6
+ describe Rbeapi::Api::Snmp do
7
+ subject { described_class.new(node) }
8
+
9
+ let(:node) do
10
+ Rbeapi::Client.config.read(fixture_file('dut.conf'))
11
+ Rbeapi::Client.connect_to('dut')
12
+ end
13
+
14
+ describe '#get' do
15
+
16
+ let(:keys) do
17
+ [:location, :contact, :chassis_id, :source_interface]
18
+ end
19
+
20
+ it 'has the required key in the resource hash' do
21
+ keys.each do |key|
22
+ expect(subject.get).to include(key)
23
+ end
24
+ end
25
+ end
26
+
27
+ describe '#set_location' do
28
+ before { node.config(['no snmp-server location']) }
29
+
30
+ it 'configures the snmp location value' do
31
+ expect(subject.get[:location]).to be_empty
32
+ expect(subject.set_location(value: 'foo')).to be_truthy
33
+ expect(subject.get[:location]).to eq('foo')
34
+ end
35
+ end
36
+
37
+ describe '#set_contact' do
38
+ before { node.config('no snmp-server contact') }
39
+
40
+ it 'configures the snmp contact value' do
41
+ expect(subject.get[:contact]).to be_empty
42
+ expect(subject.set_contact(value: 'foo')).to be_truthy
43
+ expect(subject.get[:contact]).to eq('foo')
44
+ end
45
+ end
46
+
47
+ describe '#set_chassis_id' do
48
+ before { node.config('no snmp-server chassis-id') }
49
+
50
+ it 'configures the snmp chassis-id value' do
51
+ expect(subject.get[:chassis_id]).to be_empty
52
+ expect(subject.set_chassis_id(value: 'foo')).to be_truthy
53
+ expect(subject.get[:chassis_id]).to eq('foo')
54
+ end
55
+ end
56
+
57
+ describe '#set_source_interface' do
58
+ before { node.config('no snmp-server source-interface') }
59
+
60
+ it 'configures the snmp source-interface value' do
61
+ expect(subject.get[:source_interface]).to be_empty
62
+ expect(subject.set_source_interface(value: 'Loopback0')).to be_truthy
63
+ expect(subject.get[:source_interface]).to eq('Loopback0')
64
+ end
65
+ end
66
+ end
67
+
68
+
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rbeapi/client'
4
+ require 'rbeapi/api/stp'
5
+
6
+ describe Rbeapi::Api::StpInstances do
7
+ subject { described_class.new(node) }
8
+
9
+ let(:node) do
10
+ Rbeapi::Client.config.read(fixture_file('dut.conf'))
11
+ Rbeapi::Client.connect_to('dut')
12
+ end
13
+
14
+ describe '#get' do
15
+ before { node.config(['spanning-tree mode mstp',
16
+ 'spanning-tree mst configuration',
17
+ 'instance 1 vlans 1', 'exit']) }
18
+
19
+ it 'returns the stp instance resource as a hash' do
20
+ expect(subject.get('1')).to be_a_kind_of(Hash)
21
+ end
22
+
23
+ it 'returns the instance priority' do
24
+ expect(subject.get('1')).to include(:priority)
25
+ end
26
+ end
27
+
28
+ describe '#getall' do
29
+ before { node.config(['no spanning-tree mode mstp',
30
+ 'spanning-tree mode mstp']) }
31
+
32
+ it 'returns a kind of hash' do
33
+ expect(subject.getall).to be_a_kind_of(Hash)
34
+ end
35
+ end
36
+
37
+ describe '#delete' do
38
+ before { node.config(['spanning-tree mode mstp',
39
+ 'spanning-tree mst configuration',
40
+ 'instance 1 vlans 1', 'exit']) }
41
+
42
+ it 'deletes the mst instance' do
43
+ expect(subject.get('1')).not_to be_nil
44
+ expect(subject.delete('1')).to be_truthy
45
+ expect(subject.get('1')).to be_nil
46
+ end
47
+ end
48
+
49
+ describe '#set_priority' do
50
+ before { node.config(['spanning-tree mode mstp',
51
+ 'default spanning-tree mst configuration',
52
+ 'spanning-tree mst configuration',
53
+ 'instance 1 vlans 1', 'exit']) }
54
+
55
+ it 'set the instance priority' do
56
+ expect(subject.get('1')[:priority]).to eq('32768')
57
+ expect(subject.set_priority('1', value: '4096')).to be_truthy
58
+ expect(subject.get('1')[:priority]).to eq('4096')
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rbeapi/client'
4
+ require 'rbeapi/api/stp'
5
+
6
+ describe Rbeapi::Api::StpInterfaces do
7
+ subject { described_class.new(node) }
8
+
9
+ let(:node) do
10
+ Rbeapi::Client.config.read(fixture_file('dut.conf'))
11
+ Rbeapi::Client.connect_to('dut')
12
+ end
13
+
14
+ describe '#get' do
15
+
16
+ let(:entity) do
17
+ { portfast: false, bpduguard: false }
18
+ end
19
+
20
+ before { node.config('default interface Ethernet1') }
21
+
22
+ it 'returns the stp interface resource' do
23
+ expect(subject.get('Ethernet1')).to eq(entity)
24
+ end
25
+ end
26
+
27
+ describe '#getall' do
28
+
29
+ before { node.config('default interface Ethernet1') }
30
+
31
+ it 'includes interface ethernet1' do
32
+ expect(subject.getall).to include('Ethernet1')
33
+ end
34
+
35
+ it 'returns a kind of hash' do
36
+ expect(subject.get('Ethernet1')).to be_a_kind_of(Hash)
37
+ end
38
+ end
39
+
40
+ describe '#set_portfast' do
41
+ it 'sets the portfast value to true' do
42
+ node.config(['interface Ethernet1', 'no spanning-tree portfast'])
43
+ expect(subject.get('Ethernet1')[:portfast]).to be_falsy
44
+ expect(subject.set_portfast('Ethernet1', value: true)).to be_truthy
45
+ expect(subject.get('Ethernet1')[:portfast]).to be_truthy
46
+ end
47
+
48
+ it 'sets the portfast value to false' do
49
+ node.config(['interface Ethernet1', 'spanning-tree portfast'])
50
+ expect(subject.get('Ethernet1')[:portfast]).to be_truthy
51
+ expect(subject.set_portfast('Ethernet1', value: false)).to be_truthy
52
+ expect(subject.get('Ethernet1')[:portfast]).to be_falsy
53
+ end
54
+ end
55
+
56
+ describe '#set_bpduguard' do
57
+ it 'sets the bpduguard value to true' do
58
+ node.config(['interface Ethernet1', 'no spanning-tree bpduguard'])
59
+ expect(subject.get('Ethernet1')[:bpduguard]).to be_falsy
60
+ expect(subject.set_bpduguard('Ethernet1', value: true)).to be_truthy
61
+ expect(subject.get('Ethernet1')[:bpduguard]).to be_truthy
62
+ end
63
+
64
+ it 'sets the bpduguard value to false' do
65
+ node.config(['interface Ethernet1', 'spanning-tree bpduguard enable'])
66
+ expect(subject.get('Ethernet1')[:bpduguard]).to be_truthy
67
+ expect(subject.set_bpduguard('Ethernet1', value: false)).to be_truthy
68
+ expect(subject.get('Ethernet1')[:bpduguard]).to be_falsy
69
+ end
70
+ end
71
+ end