rbeapi 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
- # Api is module namesapce for working with the EOS command API
38
+ # Api is module namespace for working with the EOS command API
39
39
  module Api
40
40
  ##
41
41
  # The Switchport class provides a base class instance for working with
@@ -55,7 +55,7 @@ module Rbeapi
55
55
  # "access_vlan": <Integer>
56
56
  # }
57
57
  #
58
- # @param [String] name The full name of the interface to get. The
58
+ # @param [String] :name The full name of the interface to get. The
59
59
  # interface name must be the full interface (ie Ethernet, not Et)
60
60
  #
61
61
  # @return [Hash] a hash that includes the switchport properties
@@ -69,24 +69,67 @@ module Rbeapi
69
69
  response.merge!(parse_access_vlan(config))
70
70
  response.merge!(parse_trunk_native_vlan(config))
71
71
  response.merge!(parse_trunk_allowed_vlans(config))
72
+ response.merge!(parse_trunk_groups(config))
72
73
  response
73
74
  end
74
75
 
76
+ ##
77
+ # parse_mode parses switchport mode from the provided config
78
+ #
79
+ # @api private
80
+ #
81
+ # @param [String] :config The configuration block returned
82
+ # from the node's running configuration
83
+ #
84
+ # @return [Hash<Symbol, Object>] resource hash attribute
75
85
  def parse_mode(config)
76
86
  mdata = /(?<=\s{3}switchport\smode\s)(.+)$/.match(config)
77
87
  { mode: mdata[1] }
78
88
  end
89
+ private :parse_mode
79
90
 
91
+ ##
92
+ # parse_access_vlan parses access vlan from the provided
93
+ # config
94
+ #
95
+ # @api private
96
+ #
97
+ # @param [String] :config The configuration block returned
98
+ # from the node's running configuration
99
+ #
100
+ # @return [Hash<Symbol, Object>] resource hash attribute
80
101
  def parse_access_vlan(config)
81
102
  mdata = /(?<=access\svlan\s)(.+)$/.match(config)
82
103
  { access_vlan: mdata[1] }
83
104
  end
105
+ private :parse_access_vlan
84
106
 
107
+ ##
108
+ # parse_trunk_native_vlan parses trunk native vlan from
109
+ # the provided config
110
+ #
111
+ # @api private
112
+ #
113
+ # @param [String] :config The configuration block returned
114
+ # from the node's running configuration
115
+ #
116
+ # @return [Hash<Symbol, Object>] resource hash attribute
85
117
  def parse_trunk_native_vlan(config)
86
118
  mdata = /(?<=trunk\snative\svlan\s)(.+)$/.match(config)
87
119
  { trunk_native_vlan: mdata[1] }
88
120
  end
121
+ private :parse_trunk_native_vlan
89
122
 
123
+ ##
124
+ # parse_trunk_allowed_vlans parses trunk allowed vlan from
125
+ # the provided config
126
+ #
127
+ # @api private
128
+ #
129
+ # @param [String] :config The configuration block returned
130
+ # from the node's running configuration
131
+ #
132
+ # @return [Hash<Symbol, Object>] resource hash attribute
90
133
  def parse_trunk_allowed_vlans(config)
91
134
  mdata = /(?<=trunk\sallowed\svlan\s)(.+)$/.match(config)
92
135
  return { trunk_allowed_vlans: [] } unless mdata[1] != 'none'
@@ -101,10 +144,47 @@ module Rbeapi
101
144
  end
102
145
  { trunk_allowed_vlans: values }
103
146
  end
147
+ private :parse_trunk_allowed_vlans
148
+
149
+ ##
150
+ # parse_trunk_groups parses trunk group values from the
151
+ # provided config
152
+ #
153
+ # @api private
154
+ #
155
+ # @param [String] :config The configuration block returned
156
+ # from the node's running configuration
157
+ #
158
+ # @return [Hash<Symbol, Object>] resource hash attribute
159
+ def parse_trunk_groups(config)
160
+ mdata = config.scan(/(?<=trunk\sgroup\s)(.+)$/)
161
+ mdata = mdata.flatten if mdata.length > 0
162
+ { trunk_groups: mdata }
163
+ end
164
+ private :parse_trunk_groups
104
165
 
105
166
  ##
106
167
  # Retrieves all switchport interfaces from the running-config
107
168
  #
169
+ # @example
170
+ # {
171
+ # <name>: {
172
+ # mode: <string>,
173
+ # access_vlan: <string>,
174
+ # trunk_native_vlan: <string>,
175
+ # trunk_allowed_vlans: <array>,
176
+ # trunk_groups: <array>
177
+ # },
178
+ # <name>: {
179
+ # mode: <string>,
180
+ # access_vlan: <string>,
181
+ # trunk_native_vlan: <string>,
182
+ # trunk_allowed_vlans: <array>,
183
+ # trunk_groups: <array>
184
+ # },
185
+ # ...
186
+ # }
187
+ #
108
188
  # @return [Array] an array of switchport hashes
109
189
  def getall
110
190
  interfaces = config.scan(/(?<=^interface\s)([Et|Po].+)$/)
@@ -248,6 +328,50 @@ module Rbeapi
248
328
  cmd = command_builder('switchport access vlan', opts)
249
329
  configure_interface(name, cmd)
250
330
  end
331
+
332
+ ##
333
+ # Configures the trunk group vlans for the specified interface.
334
+ # Trunk groups not currently set are added and trunk groups
335
+ # currently configured but not in the passed in value array are removed.
336
+ #
337
+ # @param [String] name The name of the interface to configure
338
+ # @param [Hash] opts The configuration parameters for the interface
339
+ # @option opts [string] :value Set of values to configure the trunk group
340
+ # @option opts [Boolean] :enable If false then the command is
341
+ # negated. Default is true.
342
+ # @option opts [Boolean] :default The value should be set to default
343
+ # Default takes precedence over enable.
344
+ #
345
+ # @return [Boolean] True if the commands succeed otherwise False
346
+ def set_trunk_groups(name, opts = {})
347
+ default = opts.fetch(:default, false)
348
+ if default
349
+ return configure_interface(name, 'default switchport trunk group')
350
+ end
351
+
352
+ enable = opts.fetch(:enable, true)
353
+ unless enable
354
+ return configure_interface(name, 'no switchport trunk group')
355
+ end
356
+
357
+ value = opts.fetch(:value, [])
358
+ fail ArgumentError, 'value must be an Array' unless value.is_a?(Array)
359
+
360
+ value = Set.new value
361
+ current_value = Set.new get(name)[:trunk_groups]
362
+
363
+ cmds = []
364
+ # Add trunk groups that are not currently in the list
365
+ value.difference(current_value).each do |group|
366
+ cmds << "switchport trunk group #{group}"
367
+ end
368
+
369
+ # Remove trunk groups that are not in the new list
370
+ current_value.difference(value).each do |group|
371
+ cmds << "no switchport trunk group #{group}"
372
+ end
373
+ configure_interface(name, cmds) if cmds.length > 0
374
+ end
251
375
  end
252
376
  end
253
377
  end
@@ -35,18 +35,19 @@ 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 System class configures the node system services such as
42
42
  # hostname and domain name
43
43
  class System < Entity
44
44
  ##
45
- # Returns the system settings
45
+ # Returns the system settings for hostname and iprouting
46
46
  #
47
47
  # @example
48
48
  # {
49
- # hostname: <string>
49
+ # hostname: <string>,
50
+ # iprouting: <boolean>
50
51
  # }
51
52
  #
52
53
  # @return [Hash] A Ruby hash object that provides the system settings as
@@ -58,15 +59,35 @@ module Rbeapi
58
59
  response
59
60
  end
60
61
 
62
+ ##
63
+ # parse_hostname parses hostname values from the provided config
64
+ #
65
+ # @api private
66
+ #
67
+ # @param [String] :config The configuration block returned
68
+ # from the node's running configuration
69
+ #
70
+ # @return [Hash<Symbol, Object>] resource hash attribute
61
71
  def parse_hostname(config)
62
72
  mdata = /(?<=^hostname\s)(.+)$/.match(config)
63
73
  { hostname: mdata.nil? ? '' : mdata[1] }
64
74
  end
75
+ private :parse_hostname
65
76
 
77
+ ##
78
+ # parse_iprouting parses ip routing from the provided config
79
+ #
80
+ # @api private
81
+ #
82
+ # @param [String] :config The configuration block returned
83
+ # from the node's running configuration
84
+ #
85
+ # @return [Hash<Symbol, Object>] resource hash attribute
66
86
  def parse_iprouting(config)
67
87
  mdata = /no\sip\srouting/.match(config)
68
88
  { iprouting: mdata.nil? ? true : false }
69
89
  end
90
+ private :parse_iprouting
70
91
 
71
92
  ##
72
93
  # Configures the system hostname value in the running-config
@@ -35,7 +35,7 @@ require 'rbeapi/api'
35
35
  # Rbeapi toplevel namespace
36
36
  module Rbeapi
37
37
  ##
38
- # Api is module namesapce for working with the EOS command API
38
+ # Api is module namespace for working with the EOS command API
39
39
  module Api
40
40
  ##
41
41
  # Tacacs provides instance methods to retrieve and set tacacs configuration
@@ -63,15 +63,14 @@ module Rbeapi
63
63
  # This method is intended to be used by a provider's instances class
64
64
  # method.
65
65
  #
66
- # The resource hash returned contains the following information:
67
- # * name: ('settings')
68
- # * enable: (true | false) if tacacs functionality is enabled. This is
69
- # always true for EOS.
70
- # * key: (String) the key either in plain text or hashed format
71
- # * key_format: (Integer) e.g. 0 or 7
72
- # * timeout: (Integer) seconds before the timeout period ends
73
- #
74
- # @api public
66
+ # @example
67
+ # {
68
+ # name: <string>,
69
+ # enable: <boolean>,
70
+ # key: <string>,
71
+ # key_format: <integer>,
72
+ # timeout: <integer>
73
+ # }
75
74
  #
76
75
  # @return [Array<Hash>] Single element Array of resource hashes
77
76
  def get
@@ -35,7 +35,7 @@ require 'rbeapi/api'
35
35
  # Rbeapi toplevel namespace
36
36
  module Rbeapi
37
37
  ##
38
- # Api is module namesapce for working with the EOS command API
38
+ # Api is module namespace for working with the EOS command API
39
39
  module Api
40
40
  ##
41
41
  # The Users class provides configuration of local user resources for
@@ -76,7 +76,7 @@ module Rbeapi
76
76
  # sshkey: <string>
77
77
  # }
78
78
  #
79
- # @param [String] name The user name to return a resource for from the
79
+ # @param [String] :name The user name to return a resource for from the
80
80
  # nodes configuration
81
81
  #
82
82
  # @return [nil, Hash<Symbol, Object>] Returns the user resource as a
@@ -94,7 +94,7 @@ module Rbeapi
94
94
  (username\s+#{name}\s+
95
95
  sshkey\s+(?<sshkey>.*)$)?/x)
96
96
  user = config.scan(user_re)
97
- return nil unless user
97
+ return nil unless user && user[0]
98
98
  parse_user_entry(user[0])
99
99
  end
100
100
 
@@ -114,6 +114,15 @@ module Rbeapi
114
114
  # secret: <string>,
115
115
  # sshkey: <string>
116
116
  # },
117
+ # <username>: {
118
+ # name: <string>,
119
+ # privilege: <integer>,
120
+ # role: <string>,
121
+ # nopassword: <boolean>,
122
+ # encryption: <'cleartext', 'md5', 'sha512'>
123
+ # secret: <string>,
124
+ # sshkey: <string>
125
+ # },
117
126
  # ...
118
127
  # ]
119
128
  #
@@ -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 Varp class provides an instance for working with the global
@@ -44,10 +44,18 @@ module Rbeapi
44
44
  ##
45
45
  # Returns the global VARP configuration from the node
46
46
  #
47
- # Example
47
+ # @example
48
48
  # {
49
- # "mac_address": <string>,
50
- # "interfaces": {...}
49
+ # mac_address: <string>,
50
+ # interfaces: {
51
+ # <name>: {
52
+ # addresses: <array>
53
+ # },
54
+ # <name>: {
55
+ # addresses: <array>
56
+ # },
57
+ # ...
58
+ # }
51
59
  # }
52
60
  #
53
61
  # @return [Hash] A Ruby hash object that provides the Varp settings as
@@ -59,6 +67,15 @@ module Rbeapi
59
67
  response
60
68
  end
61
69
 
70
+ ##
71
+ # parse_mac_address parses mac-address values from the provided config
72
+ #
73
+ # @api private
74
+ #
75
+ # @param [String] :config The configuration block returned
76
+ # from the node's running configuration
77
+ #
78
+ # @return [Hash<Symbol, Object>] resource hash attribute
62
79
  def parse_mac_address(config)
63
80
  # ip virtual-router mac-address value will always
64
81
  # be stored in aa:bb:cc:dd:ee:ff format
@@ -97,7 +114,7 @@ module Rbeapi
97
114
  ##
98
115
  # Returns a single VARP interface configuration
99
116
  #
100
- # Example
117
+ # @example
101
118
  # {
102
119
  # "addresses": array<string>
103
120
  # }
@@ -119,10 +136,15 @@ module Rbeapi
119
136
  # Returns the collection of MLAG interfaces as a hash index by the
120
137
  # interface name
121
138
  #
122
- # Example
139
+ # @example
123
140
  # {
124
- # "name": {...},
125
- # "name": {...}
141
+ # <name>: {
142
+ # addresses: <array>
143
+ # },
144
+ # <name>: {
145
+ # addresses: <array>
146
+ # },
147
+ # ...
126
148
  # }
127
149
  #
128
150
  # @return [nil, Hash<String, String>] A Ruby hash that represents the
@@ -138,6 +160,16 @@ module Rbeapi
138
160
  end
139
161
  end
140
162
 
163
+ ##
164
+ # parse_addresses parses ip virtual-router address from the provided
165
+ # config
166
+ #
167
+ # @api private
168
+ #
169
+ # @param [String] :config The configuration block returned
170
+ # from the node's running configuration
171
+ #
172
+ # @return [Hash<Symbol, Object>] resource hash attribute
141
173
  def parse_addresses(config)
142
174
  addrs = config.scan(/(?<=\s{3}ip\svirtual-router\saddress\s).+$/)
143
175
  { addresses: addrs }
@@ -35,7 +35,7 @@ require 'rbeapi/api'
35
35
  # Rbeapi toplevel namespace
36
36
  module Rbeapi
37
37
  ##
38
- # Api is module namesapce for working with the EOS command API
38
+ # Api is module namespace for working with the EOS command API
39
39
  module Api
40
40
  ##
41
41
  # The Vlan class provides a class implementation for working with the
@@ -50,12 +50,12 @@ module Rbeapi
50
50
  #
51
51
  # @example
52
52
  # {
53
- # name: <string>
54
- # state: <string>
53
+ # name: <string>,
54
+ # state: <string>,
55
55
  # trunk_groups: array[<string]
56
56
  # }
57
57
  #
58
- # @param [String] id The vlan id to return a resource for from the
58
+ # @param [String] :id The vlan id to return a resource for from the
59
59
  # nodes configuration
60
60
  #
61
61
  # @return [nil, Hash<Symbol, Object>] Returns the vlan resource as a
@@ -78,7 +78,17 @@ module Rbeapi
78
78
  #
79
79
  # @example
80
80
  # {
81
- # <vlanid>: {...}
81
+ # <vlanid>: {
82
+ # name: <string>,
83
+ # state: <string>,
84
+ # trunk_groups: array[<string]
85
+ # },
86
+ # <vlanid>: {
87
+ # name: <string>,
88
+ # state: <string>,
89
+ # trunk_groups: array[<string]
90
+ # },
91
+ # ...
82
92
  # }
83
93
  #
84
94
  # @see get Vlan resource example