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,328 @@
1
+ #
2
+ # Copyright (c) 2014, 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 'rbeapi/api'
33
+
34
+ module Rbeapi
35
+
36
+ module Api
37
+ #
38
+ # The Ipinterface class provides an instance for managing logical
39
+ # IP interfaces configured using eAPI.
40
+ class Ipinterfaces < Entity
41
+
42
+ DEFAULT_ADDRESS = ''
43
+
44
+ ##
45
+ # get returns a resource hash that represents the configuration of the IP
46
+ # interface from the nodes running configuration.
47
+ #
48
+ # @example
49
+ # {
50
+ # address: <string>
51
+ # mtu: <string>
52
+ # helper_addresses: array<strings>
53
+ # }
54
+ #
55
+ # @param [String] :name The full interface identifier of the interface to
56
+ # return the resource configuration hash for. The name must be the
57
+ # full name (Ethernet, not Et)
58
+ #
59
+ # @return [nil, Hash<Symbol, Object>] returns the ip interface
60
+ # configuration as a hash. If the provided interface name is not a
61
+ # configured ip address, nil is returned.
62
+ def get(name)
63
+ config = get_block("interface #{name}")
64
+ return nil unless config
65
+ return nil if /\s{3}switchport$/ =~ config
66
+
67
+ response = {}
68
+ response.merge!(parse_address(config))
69
+ response.merge!(parse_mtu(config))
70
+ response.merge!(parse_helper_addresses(config))
71
+ response
72
+ end
73
+
74
+ ##
75
+ # getall returns a hash object that represents all ip interfaces
76
+ # configured on the node from the current running configuration.
77
+ #
78
+ # @example
79
+ # {
80
+ # <name>: {...}
81
+ # }
82
+ #
83
+ # @see get Ipaddress resource example
84
+ #
85
+ # @return [Hash<Symbol, Object>] returns a hash object that
86
+ # represents all of the configured IP addresses found. If no IP
87
+ # addresses are configured, then an empty hash is returned
88
+ def getall
89
+ interfaces = config.scan(/(?<=^interface\s).+/)
90
+ interfaces.each_with_object({}) do |name, hsh|
91
+ values = get name
92
+ hsh[name] = values if values
93
+ end
94
+ end
95
+
96
+ ##
97
+ # parse_address scans the provided configuration block and extracts
98
+ # the interface address, if configured, and returns it. If there is
99
+ # no IP address configured, then this method will return the
100
+ # DEFAULT_ADDRESS. The return value is intended to be merged into the
101
+ # ipaddress resource hash.
102
+ #
103
+ # @api private
104
+ # @param [String] :config The IP interface configuration block returned
105
+ # from the node's running configuration
106
+ #
107
+ # @return [Hash<Symbol, Object>] resource hash attribute
108
+ def parse_address(config)
109
+ mdata = /(?<=^\s{3}ip\saddress\s)(.+)$/.match(config)
110
+ { address: mdata.nil? ? DEFAULT_ADDRESS : mdata[1] }
111
+ end
112
+ private :parse_address
113
+
114
+ ##
115
+ # parse_mtu scans the provided configuration block and extracts the IP
116
+ # interface MTU value. The MTU value is expected to always be present in
117
+ # the configuration blcok. The return value is intended to be merged
118
+ # into the ipaddress resource hash
119
+ #
120
+ # @api private
121
+ #
122
+ # @param [String] :config The IP interface configuration block returned
123
+ # from the node's running configuration
124
+ #
125
+ # @return [Hash<Symbol, Object>] resource hash attribute
126
+ def parse_mtu(config)
127
+ mdata = /(?<=mtu\s)(\d+)$/.match(config)
128
+ { mtu: mdata.nil? ? '': mdata[1] }
129
+ end
130
+ private :parse_mtu
131
+
132
+ ##
133
+ # parse_helper_addresses scans the provided configuraiton block and
134
+ # extracts any configured IP helper address values. The interface could
135
+ # be configured with one or more helper addresses. If no helper
136
+ # addresses are configured, then an empty array is set in the return
137
+ # hash. The return value is intended to be merged into the ipaddress
138
+ # resource hash
139
+ #
140
+ # @api private
141
+ #
142
+ # @param [String] :config The IP interface configuration block returned
143
+ # from the node's running configuration
144
+ #
145
+ # @return [Hash<Symbol, Object>] resource hash attribute
146
+ def parse_helper_addresses(config)
147
+ helpers = config.scan(/(?<=\s{3}ip\shelper-address\s).+$/)
148
+ { helper_addresses: helpers }
149
+ end
150
+ private :parse_helper_addresses
151
+
152
+ ##
153
+ # create will create a new IP interface on the node. If the ip interface
154
+ # already exists in the configuration, this method will still return
155
+ # successful. This method will cause an existing layer 2 interface
156
+ # (switchport) to be deleted if it exists in the node's configuration.
157
+ #
158
+ # @eos_version 4.13.7M
159
+ #
160
+ # @commands
161
+ # interface <name>
162
+ # no switchport
163
+ #
164
+ # @param [String] :name The full interface name of the port to create the
165
+ # logical interface on. The name must be the full interface
166
+ # identifier
167
+ #
168
+ # @return [Boolean] returns true if the commands complete successfully
169
+ def create(name)
170
+ configure(["interface #{name}", 'no switchport'])
171
+ end
172
+
173
+ ##
174
+ # delete will delete an existing IP interface in the node's current
175
+ # configuration. If the IP interface does not exist on the specified
176
+ # interface, this method will still return success. This command will
177
+ # default the interface back to being a switchport.
178
+ #
179
+ # @eos_version 4.13.7M
180
+ #
181
+ # @commands
182
+ # interface <name>
183
+ # no ip address
184
+ # switchport
185
+ #
186
+ # @param [String] :name The full interface name of the port to delete the
187
+ # logical interface from. The name must be the full interface name
188
+ #
189
+ # @return [Boolean] returns true if the commands complete successfully
190
+ def delete(name)
191
+ configure(["interface #{name}", 'no ip address', 'switchport'])
192
+ end
193
+
194
+ ##
195
+ # set_address configures a logical IP interface with an address. The
196
+ # address value must be in the form of A.B.C.D/E. If no value is
197
+ # provided, then the interface address is negated using the config no
198
+ # keyword. If the default option is set to true, then the ip address
199
+ # value is defaulted using the default keyword. The default keyword has
200
+ # precedence over the value keyword if both options are specified
201
+ #
202
+ # @eos_version 4.13.7M
203
+ #
204
+ # @commands
205
+ # interface <name>
206
+ # ip address <value>
207
+ # no ip address
208
+ # default ip address
209
+ #
210
+ # @param [String] :name The name of the interface to configure the
211
+ # address in the node. The name must be the full interface name.
212
+ #
213
+ # @param [Hash] :opts Optional keyword arguments
214
+ #
215
+ # @option :opts [String] :value The value to configure the address to
216
+ # for the specified interface name. The value must be in the form
217
+ # of A.B.C.D/E
218
+ #
219
+ # @option :opts [Boolean] :default Configure the ip address value using
220
+ # the default keyword
221
+ #
222
+ # @return [Boolean] returns true if the command completed successfully
223
+ def set_address(name, opts = {})
224
+ value = opts[:value]
225
+ default = opts[:default] || false
226
+
227
+ cmds = ["interface #{name}"]
228
+ case default
229
+ when true
230
+ cmds << 'default ip address'
231
+ when false
232
+ cmds << (value.nil? ? 'no ip address' : "ip address #{value}")
233
+ end
234
+ configure cmds
235
+ end
236
+
237
+ ##
238
+ # set_mtu configures the IP mtu value of the ip interface in the nodes
239
+ # configuration. If the value is not provided, then the ip mtu value is
240
+ # configured using the no keyword. If the default keywork option is
241
+ # provided and set to true then the ip mtu value is configured using the
242
+ # default keyword. The default keyword has precedence over the value
243
+ # keyword if both options are specified.
244
+ #
245
+ # @eos_version 4.13.7M
246
+ #
247
+ # @commands
248
+ # interface <name>
249
+ # mtu <value>
250
+ # no mtu
251
+ # default mtu
252
+ #
253
+ # @param [String] :name The name of the interface to configure the
254
+ # address in the node. The name must be the full interface name.
255
+ #
256
+ # @param [Hash] :opts Optional keyword arguments
257
+ #
258
+ # @option :opts [String] :value The value to configure the IP MTU to in
259
+ # the nodes configuration. Valid values are in the range of 68 to 9214
260
+ # bytes. The default is 1500 bytes
261
+ #
262
+ # @option :opts [Boolean] :default Configure the ip mtu value using
263
+ # the default keyword
264
+ #
265
+ # @return [Boolean] returns true if the command completed successfully
266
+ def set_mtu(name, opts = {})
267
+ value = opts[:value]
268
+ default = opts[:default] || false
269
+
270
+ cmds = ["interface #{name}"]
271
+ case default
272
+ when true
273
+ cmds << 'default mtu'
274
+ when false
275
+ cmds << (value.nil? ? 'no mtu' : "mtu #{value}")
276
+ end
277
+ configure cmds
278
+ end
279
+
280
+ ##
281
+ # set_helper_addresses configures the list of helper addresses on the ip
282
+ # interface. An IP interface can have one or more helper addresses
283
+ # configured. If no value is provided, the helper address configuration
284
+ # is set using the no keyword. If the default option is specified and
285
+ # set to true, then the helper address values are defaulted using the
286
+ # default keyword.
287
+ #
288
+ # @eos_version 4.13.7M
289
+ #
290
+ # @commands
291
+ # interface <name>
292
+ # ip helper-address <value>
293
+ # no ip helper-address
294
+ # default ip helper-address
295
+ #
296
+ # @param [String] :name The name of the interface to configure the
297
+ # address in the node. The name must be the full interface name.
298
+ #
299
+ # @param [Hash] :opts Optional keyword arguments
300
+ #
301
+ # @option :opts [Array] :value The list of IP addresses to configure as
302
+ # helper address on the interface. The helper addresses must be valid
303
+ # addresses in the main interface's subnet.
304
+ #
305
+ # @option :opts [Boolean] :default Configure the ip helper address values
306
+ # using the default keyword
307
+ #
308
+ def set_helper_addresses(name, opts = {})
309
+ value = opts[:value]
310
+ default = opts[:default] || false
311
+
312
+ cmds = ["interface #{name}"]
313
+ case default
314
+ when true
315
+ cmds << 'default ip helper-address'
316
+ when false
317
+ if value.nil?
318
+ cmds << 'no ip helper-address'
319
+ else
320
+ cmds << 'no ip helper-address'
321
+ value.each { |addr| cmds << "ip helper-address #{addr}" }
322
+ end
323
+ end
324
+ configure cmds
325
+ end
326
+ end
327
+ end
328
+ end
@@ -0,0 +1,157 @@
1
+ #
2
+ # Copyright (c) 2014, 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 'rbeapi/api'
33
+
34
+ module Rbeapi
35
+
36
+ module Api
37
+
38
+ class Logging < Entity
39
+
40
+ ##
41
+ # get returns the current logging configuration hash extracted from the
42
+ # nodes running configuration.
43
+ #
44
+ # @example
45
+ # {
46
+ # enable: [true, false]
47
+ # hosts: array<strings>
48
+ # }
49
+ #
50
+ # @return [Hash<Symbol, Object>] returns the logging resource as a hash
51
+ # object from the nodes current configuration
52
+ def get
53
+ response = {}
54
+ response.merge!(parse_enable)
55
+ response.merge!(parse_hosts)
56
+ response
57
+ end
58
+
59
+ ##
60
+ # parse_enable scans the nodes current running configuration and extracts
61
+ # the current enabled state of the logging facility. The logging enable
62
+ # command is expected to always be in the node's configuration. This
63
+ # methods return value is intended to be merged into the logging resource
64
+ # hash.
65
+ def parse_enable
66
+ value = /no logging on/ !~ config
67
+ { enable: value }
68
+ end
69
+
70
+ ##
71
+ # parse_hosts scans the nodes current running configuration and extracts
72
+ # the configured logging host destinations if any are configured. If no
73
+ # logging hosts are configured, then the value for hosts will be an empty
74
+ # array. The return value is intended to be merged into the logging
75
+ # resource hash
76
+ def parse_hosts
77
+ hosts = config.scan(/(?<=^logging\shost\s)[^\s]+/)
78
+ { hosts: hosts }
79
+ end
80
+
81
+ ##
82
+ # set_enable configures the global logging instance on the node as either
83
+ # enabled or disabled. If the value is set to true then logging is
84
+ # globally enabled and if set to false, it is globally disabled. If no
85
+ # value is specified, then the no keyword is used to configure the
86
+ # logging enable value. If the default keyword is specified and set to
87
+ # true, then the configuration is defaulted using the default keyword.
88
+ # The default keyword option takes precedence over the value keyword if
89
+ # both options are specified.
90
+ #
91
+ # @eos_version 4.13.7M
92
+ #
93
+ # @commands
94
+ # logging on
95
+ # no logging on
96
+ # default logging on
97
+ #
98
+ # @param [Hash] :opts Optional keyword arguments
99
+ #
100
+ # @option :opts [Boolean] :value Enables logging globally if value is true or
101
+ # disabled logging glboally if value is false
102
+ #
103
+ # @option :opts [Boolean] :default Configure the ip address value using
104
+ # the default keyword
105
+ #
106
+ # @return [Boolean] returns true if the command completed successfully
107
+ def set_enable(opts = {})
108
+ value = opts[:value]
109
+ default = opts[:default] || false
110
+
111
+ case default
112
+ when true
113
+ cmd = 'default logging on'
114
+ when false
115
+ cmd = value ? 'logging on' : 'no logging on'
116
+ end
117
+ configure cmd
118
+ end
119
+
120
+ ##
121
+ # add_host configures a new logging destination host address or hostname
122
+ # to the list of logging destinations. If the host is already configured
123
+ # in the list of destinations, this method will return successfully.
124
+ #
125
+ # @eos_version 4.13.7M
126
+ #
127
+ # @commands
128
+ # logging host <name>
129
+ #
130
+ # @param [String] :name The host name or ip address of the destination
131
+ # node to send logging information to.
132
+ #
133
+ # @return [Boolean] returns true if the command completed successfully
134
+ def add_host(name)
135
+ configure "logging host #{name}"
136
+ end
137
+
138
+ ##
139
+ # remove_host deletes a logging destination host name or address form the
140
+ # list of logging destinations. If the host is not in the list of
141
+ # configured hosts, this method will still return successfully.
142
+ #
143
+ # @eos_version 4.13.7M
144
+ #
145
+ # @commands
146
+ # no logging host <name>
147
+ #
148
+ # @param [String] :name The host name or ip address of the destination
149
+ # host to remove from the nodes current configuration
150
+ #
151
+ # @return [Boolean] returns true if the commands completed successfully
152
+ def remove_host(name)
153
+ configure "no logging host #{name}"
154
+ end
155
+ end
156
+ end
157
+ end