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
@@ -35,7 +35,7 @@ require 'rbeapi/api'
35
35
  # Rbeapi toplevel namespace
36
36
  module Rbeapi
37
37
  ##
38
- # Rbeapi::Api
38
+ # Api is module namespace for working with the EOS command API
39
39
  module Api
40
40
  ##
41
41
  # The Ospf class is a global class that provides an instance for working
@@ -48,13 +48,15 @@ module Rbeapi
48
48
  #
49
49
  # @example
50
50
  # {
51
- # "router_id": <string>
52
- # "areas": {
51
+ # router_id: <string>
52
+ # areas: {
53
53
  # <string>: array<string>
54
54
  # },
55
- # "redistribute"
55
+ # redistribute: {}
56
56
  # }
57
57
  #
58
+ # @param [String] :inst The ospf instance name
59
+ #
58
60
  # @return [Hash] A Ruby hash object that provides the OSPF settings as
59
61
  # key / value pairs.
60
62
  def get(inst)
@@ -90,9 +92,16 @@ module Rbeapi
90
92
  #
91
93
  # @example
92
94
  # {
93
- # <pid>: {...}
94
- # "interfaces": {...}
95
+ # <pid>: {
96
+ # router_id: <string>,
97
+ # areas: {},
98
+ # redistribute: {}
99
+ # },
100
+ # interfaces: {}
95
101
  # }
102
+ #
103
+ # @return [Hash] A Ruby hash object that provides the OSPF settings as
104
+ # key / value pairs.
96
105
  def getall
97
106
  instances = config.scan(/(?<=^router\sospf\s)\d+$/)
98
107
  response = instances.each_with_object({}) do |inst, hsh|
@@ -108,28 +117,91 @@ module Rbeapi
108
117
  @interfaces
109
118
  end
110
119
 
120
+ ##
121
+ # create will create a router ospf with the specified pid
122
+ #
123
+ # @param [String] :pid The router ospf to create
124
+ #
125
+ # @return [Boolean] returns true if the command completed successfully
111
126
  def create(pid)
112
127
  configure "router ospf #{pid}"
113
128
  end
114
129
 
130
+ ##
131
+ # delete will remove the specified router ospf
132
+ #
133
+ # @param [String] :pid The router ospf to remove
134
+ #
135
+ # @return [Boolean] returns true if the command completed successfully
115
136
  def delete(pid)
116
137
  configure "no router ospf #{pid}"
117
138
  end
118
139
 
140
+ ##
141
+ # set_router_id sets router ospf router-id with pid and options
142
+ #
143
+ # @param [String] :pid The router ospf name
144
+ #
145
+ # @param [hash] :opts Optional keyword arguments
146
+ #
147
+ # @option :opts [Boolean] :enable If false then the command is
148
+ # negated. Default is true.
149
+ #
150
+ # @option :opts [Boolean] :default Configure the router-id to default.
151
+ #
152
+ # @return [Boolean] returns true if the command completed successfully
119
153
  def set_router_id(pid, opts = {})
120
154
  cmd = command_builder('router-id', opts)
121
155
  cmds = ["router ospf #{pid}", cmd]
122
156
  configure cmds
123
157
  end
124
158
 
159
+ ##
160
+ # add_network adds network settings for router ospf and network area.
161
+ #
162
+ # @param [String] :pid The pid for router ospf
163
+ #
164
+ # @param [String] :net The network name
165
+ #
166
+ # @param [String] :area The network area name
167
+ #
168
+ # @return [Boolean] returns true if the command completed successfully
125
169
  def add_network(pid, net, area)
126
170
  configure ["router ospf #{pid}", "network #{net} area #{area}"]
127
171
  end
128
172
 
173
+ ##
174
+ # remove_network removes network settings for router ospf and network
175
+ # area.
176
+ #
177
+ # @param [String] :pid The pid for router ospf
178
+ #
179
+ # @param [String] :net The network name
180
+ #
181
+ # @param [String] :area The network area name
182
+ #
183
+ # @return [Boolean] returns true if the command completed successfully
129
184
  def remove_network(pid, net, area)
130
185
  configure ["router ospf #{pid}", "no network #{net} area #{area}"]
131
186
  end
132
187
 
188
+ ##
189
+ # set_redistribute sets router ospf router-id with pid and options
190
+ #
191
+ # @param [String] :pid The router ospf name
192
+ #
193
+ # @param [String] :proto The redistribute value
194
+ #
195
+ # @param [hash] :opts Optional keyword arguments
196
+ #
197
+ # @option :opts [String] :routemap The route-map value
198
+ #
199
+ # @option :opts [Boolean] :enable If false then the command is
200
+ # negated. Default is true.
201
+ #
202
+ # @option :opts [Boolean] :default Configure the router-id to default.
203
+ #
204
+ # @return [Boolean] returns true if the command completed successfully
133
205
  def set_redistribute(pid, proto, opts = {})
134
206
  routemap = opts[:routemap]
135
207
  cmds = ["router ospf #{pid}", "redistribute #{proto}"]
@@ -147,8 +219,7 @@ module Rbeapi
147
219
  #
148
220
  # Example
149
221
  # {
150
- # "name": <string>,
151
- # "network_type": <string>
222
+ # network_type: <string>
152
223
  # }
153
224
  #
154
225
  # @param [String] :name The interface name to return the configuration
@@ -174,8 +245,13 @@ module Rbeapi
174
245
  #
175
246
  # Example
176
247
  # {
177
- # <name>: {...},
178
- # <name>: {...}
248
+ # <name>: {
249
+ # network_type: <string>
250
+ # },
251
+ # <name>: {
252
+ # network_type: <string>
253
+ # },
254
+ # ...
179
255
  # }
180
256
  #
181
257
  # @return [nil, Hash<String, String>] A Ruby hash that represents the
@@ -189,6 +265,22 @@ module Rbeapi
189
265
  end
190
266
  end
191
267
 
268
+ ##
269
+ # set_network_type sets network type with options
270
+ #
271
+ # @param [String] :name The name of the interface
272
+ #
273
+ # @param [hash] :opts Optional keyword arguments
274
+ #
275
+ # @option :opts [String] :value The point-to-point value
276
+ #
277
+ # @option :opts [Boolean] :enable If false then the command is
278
+ # negated. Default is true.
279
+ #
280
+ # @option :opts [Boolean] :default Configure the ip ospf network
281
+ # to default.
282
+ #
283
+ # @return [Boolean] returns true if the command completed successfully
192
284
  def set_network_type(name, opts = {})
193
285
  value = opts[:value]
194
286
  return false unless [nil, 'point-to-point'].include?(value)
@@ -35,7 +35,7 @@ require 'rbeapi/api'
35
35
  # Rbeapi toplevel namespace
36
36
  module Rbeapi
37
37
  ##
38
- # Rbeapi::Api
38
+ # Api is module namespace for working with the EOS command API
39
39
  module Api
40
40
  ##
41
41
  # The Prefixlists class provides a configuration instance for working
@@ -48,16 +48,17 @@ module Rbeapi
48
48
  # @example
49
49
  # {
50
50
  # <route>: {
51
- # "next_hop": <string>,
52
- # "name": <string, nil>
51
+ # next_hop: <string>,
52
+ # name: <string, nil>
53
53
  # }
54
54
  # }
55
55
  #
56
+ # @param [String] :name The name of the prefix-list to return
57
+ #
56
58
  # @returns [Hash<String, String> The method will return all of the
57
59
  # configured static routes on the node as a Ruby hash object. If
58
60
  # there are no static routes configured, this method will return
59
61
  # an empty hash
60
-
61
62
  def get(name)
62
63
  config = get_block("ip prefix-list #{name}")
63
64
  return nil unless config
@@ -69,6 +70,21 @@ module Rbeapi
69
70
  end
70
71
  end
71
72
 
73
+ ##
74
+ # Returns the static routes configured on the node
75
+ #
76
+ # @example
77
+ # {
78
+ # <route>: {
79
+ # next_hop: <string>,
80
+ # name: <string, nil>
81
+ # }
82
+ # }
83
+ #
84
+ # @returns [Hash<String, String> The method will return all of the
85
+ # configured static routes on the node as a Ruby hash object. If
86
+ # there are no static routes configured, this method will return
87
+ # an empty hash
72
88
  def getall
73
89
  lists = config.scan(/(?<=^ip\sprefix-list\s).+/)
74
90
  lists.each_with_object({}) do |name, hsh|
@@ -77,10 +93,29 @@ module Rbeapi
77
93
  end
78
94
  end
79
95
 
96
+ ##
97
+ # create will create a new ip prefix-list with designated name.
98
+ #
99
+ # @param [String] :name The name of the ip prefix-list
100
+ #
101
+ # @return [Boolean] returns true if the command completed successfully
80
102
  def create(name)
81
103
  configure "ip prefix-list #{name}"
82
104
  end
83
105
 
106
+ ##
107
+ # add_rule will create an ip prefix-list with the designated name,
108
+ # seqno, action and prefix.
109
+ #
110
+ # @param [String] :name The name of the ip prefix-list
111
+ #
112
+ # @param [String] :seq The seq value
113
+ #
114
+ # @param [String] :action The action value
115
+ #
116
+ # @param [String] :prefix The prefix value
117
+ #
118
+ # @return [Boolean] returns true if the command completed successfully
84
119
  def add_rule(name, action, prefix, seq = nil)
85
120
  cmd = "ip prefix-list #{name}"
86
121
  cmd << " seq #{seq}" if seq
@@ -88,6 +123,14 @@ module Rbeapi
88
123
  configure cmd
89
124
  end
90
125
 
126
+ ##
127
+ # delete will remove the designated prefix-list
128
+ #
129
+ # @param [String] :name The name of the ip prefix-list
130
+ #
131
+ # @param [String] :seq The seq value
132
+ #
133
+ # @return [Boolean] returns true if the command completed successfully
91
134
  def delete(name, seq = nil)
92
135
  cmd = "no ip prefix-list #{name}"
93
136
  cmd << " seq #{seq}" if seq
@@ -35,7 +35,7 @@ require 'rbeapi/api'
35
35
  # Rbeapi toplevel namespace
36
36
  module Rbeapi
37
37
  ##
38
- # Rbeapi::Api
38
+ # Api is module namespace for working with the EOS command API
39
39
  module Api
40
40
  ##
41
41
  # Radius provides instance methods to retrieve and set radius configuration
@@ -61,14 +61,14 @@ module Rbeapi
61
61
  # This method is intended to be used by a provider's instances class
62
62
  # method.
63
63
  #
64
- # The resource hash returned contains the following information:
65
- # * key: (String) the key either in plain text or hashed format
66
- # * key_format: (Fixnum) e.g. 0 or 7
67
- # * timeout: (Fixnum) seconds before the timeout period ends
68
- # * retransmit: (Fixnum), e.g. 3, attempts after first timeout expiry.
69
- # * servers: (Array),
70
- #
71
- # @api public
64
+ # @example
65
+ # {
66
+ # key: <string>,
67
+ # key_format: <fixnum>,
68
+ # timeout: <fixnum>,
69
+ # retransmit: <fixnum>,
70
+ # servers: <array>
71
+ # }
72
72
  #
73
73
  # @return [Array<Hash>] Single element Array of resource hashes
74
74
  def get
@@ -35,7 +35,7 @@ require 'rbeapi/api'
35
35
  # Rbeapi toplevel namespace
36
36
  module Rbeapi
37
37
  ##
38
- # Rbeapi::Api
38
+ # Api is module namespace for working with the EOS command API
39
39
  module Api
40
40
  ##
41
41
  # The Routemaps class manages routemaps. A route map is a list of rules
@@ -81,8 +81,8 @@ module Rbeapi
81
81
  # }
82
82
  # }
83
83
  #
84
- # @param [String] name The routemap name to return a resource for from the
85
- # nodes configuration
84
+ # @param [String] :name The routemap name to return a resource for from
85
+ # the nodes configuration
86
86
  #
87
87
  # @return [nil, Hash<Symbol, Object>] Returns the routemap resource as a
88
88
  # Hash. If the specified name is not found in the nodes current
@@ -174,10 +174,11 @@ module Rbeapi
174
174
  ##
175
175
  # parse entries is a private method to get the routemap rules.
176
176
  #
177
+ # @api private
178
+ #
177
179
  # @return [nil, Hash<Symbol, Object>] returns a hash that represents the
178
180
  # rules for routemaps from the nodes running configuration. If
179
181
  # there are no routemaps configured, this method will return nil.
180
- #
181
182
  def parse_entries(name)
182
183
  entries = config.scan(/^route-map\s#{name}\s.+$/)
183
184
  return nil if entries.empty?
@@ -196,11 +197,12 @@ module Rbeapi
196
197
  ##
197
198
  # parse rule is a private method to parse a rule.
198
199
  #
200
+ # @api private
201
+ #
199
202
  # @return [Hash<Symbol, Object>] returns a hash that represents the
200
203
  # rules for routemaps from the nodes running configuration. If
201
204
  # there are no routemaps configured, this method will return an empty
202
205
  # hash.
203
- #
204
206
  def parse_rules(rules)
205
207
  rules.split("\n").each_with_object({}) do |rule, rule_hsh|
206
208
  mdata = /\s{3}(\w+)\s/.match(rule)
@@ -35,7 +35,7 @@ require 'rbeapi/api'
35
35
  # Rbeapi toplevel namespace
36
36
  module Rbeapi
37
37
  ##
38
- # Api is module namespace for working with eAPI abstractions
38
+ # Api is module namespace for working with the EOS command API
39
39
  module Api
40
40
  ##
41
41
  # The Snmp class provides a class implementation for working with the
@@ -57,9 +57,9 @@ module Rbeapi
57
57
  #
58
58
  # @example
59
59
  # {
60
- # location: <string>
61
- # contact: <string>
62
- # chassis_id: <string>
60
+ # location: <string>,
61
+ # contact: <string>,
62
+ # chassis_id: <string>,
63
63
  # source_interface: <string>
64
64
  # }
65
65
  #
@@ -403,6 +403,15 @@ module Rbeapi
403
403
  configure cmds
404
404
  end
405
405
 
406
+ ##
407
+ # set_community_access configures snmp-server community with designated
408
+ # name and access values.
409
+ #
410
+ # @param [String] :name The snmp-server community name value
411
+ #
412
+ # @param [String] :access The snmp-server community access value
413
+ #
414
+ # @return [Boolean] returns true if the command completed successfully
406
415
  def set_community_access(name, access)
407
416
  configure "snmp-server community #{name} #{access}"
408
417
  end
@@ -35,7 +35,7 @@ require 'rbeapi/api'
35
35
  # Rbeapi toplevel namespace
36
36
  module Rbeapi
37
37
  ##
38
- # Rbeapi::Api
38
+ # Api is module namespace for working with the EOS command API
39
39
  module Api
40
40
  ##
41
41
  # The Staticroutes class provides a configuration instance for working
@@ -34,7 +34,7 @@
34
34
  # Rbeapi toplevel namespace
35
35
  module Rbeapi
36
36
  ##
37
- # Rbeapi::Api
37
+ # Api is module namespace for working with the EOS command API
38
38
  module Api
39
39
  ##
40
40
  # The Stp class provides a base class instance for working with
@@ -48,13 +48,20 @@ module Rbeapi
48
48
  # @example
49
49
  # {
50
50
  # mode: <string>
51
- # instances: {...}
52
- # interfaces: {...}
51
+ # instances: {
52
+ # <string>: {
53
+ # priority: <string>
54
+ # }
55
+ # }
56
+ # interfaces: {
57
+ # <name>: {
58
+ # portfast: <boolean>,
59
+ # portfast_type: <string>,
60
+ # bpduguard: <boolean>
61
+ # }
62
+ # }
53
63
  # }
54
64
  #
55
- # @see StpInstances instances get example
56
- # @eee StpInterfaces interfaces get example
57
- #
58
65
  # @return [Hash] returns a Hash of attributes derived from eAPI
59
66
  def get
60
67
  response = {}
@@ -150,6 +157,8 @@ module Rbeapi
150
157
  # priority: <string>
151
158
  # }
152
159
  #
160
+ # @param [String] :inst The named stp instance to return
161
+ #
153
162
  # @return [nil, Hash<Symbol, Object] returns the stp instance config as
154
163
  # a resource hash. If the instances is not configured this method
155
164
  # will return a nil object
@@ -167,11 +176,15 @@ module Rbeapi
167
176
  #
168
177
  # @example
169
178
  # {
170
- # <inst>: {...}
179
+ # <inst>: {
180
+ # priority: <string>
181
+ # },
182
+ # <inst>: {
183
+ # priority: <string>
184
+ # },
185
+ # ...
171
186
  # }
172
187
  #
173
- # @see get Instance get example
174
- #
175
188
  # @return [Hash<Symbol, Object>] returns all configured stp instances
176
189
  # found in the nodes running configuration
177
190
  def getall
@@ -265,10 +278,14 @@ module Rbeapi
265
278
  #
266
279
  # @example
267
280
  # {
268
- # portfast: [true, false]
269
- # bpduguard: [true, false]
281
+ # portfast: <boolean>,
282
+ # portfast_type: <string>,
283
+ # bpduguard: <boolean>
270
284
  # }
271
285
  #
286
+ # @param [String] :name The interface name to return a resource for from
287
+ # the nodes configuration
288
+ #
272
289
  # @return [nil, Hash<Symbol, Object>] returns the stp interface as a
273
290
  # resource hash
274
291
  def get(name)
@@ -289,11 +306,19 @@ module Rbeapi
289
306
  #
290
307
  # @example
291
308
  # {
292
- # <interface>: {...}
309
+ # <name>: {
310
+ # portfast: <boolean>,
311
+ # portfast_type: <string>,
312
+ # bpduguard: <boolean>
313
+ # },
314
+ # <name>: {
315
+ # portfast: <boolean>,
316
+ # portfast_type: <string>,
317
+ # bpduguard: <boolean>
318
+ # },
319
+ # ...
293
320
  # }
294
321
  #
295
- # @see get Interface example
296
- #
297
322
  # @return [Hash<Symbol, Object>] returns the stp interfaces config as a
298
323
  # resource hash from the nodes running configuration
299
324
  def getall