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,13 +35,13 @@ 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 Dns class manages DNS settings on an EOS node.
42
42
  class Dns < Entity
43
43
  ##
44
- # Returns the DNS resource
44
+ # get returns the DNS resource
45
45
  #
46
46
  # @example
47
47
  # {
@@ -60,21 +60,43 @@ module Rbeapi
60
60
  response
61
61
  end
62
62
 
63
+ ##
64
+ # parse_domain_name parses the domain-name from config
65
+ #
66
+ # @api private
67
+ #
68
+ # @return [Hash<Symbol, Object>] resource hash attribute
63
69
  def parse_domain_name
64
70
  mdata = /ip domain-name ([\w.]+)/.match(config)
65
71
  { domain_name: mdata.nil? ? '' : mdata[1] }
66
72
  end
73
+ private :parse_domain_name
67
74
 
75
+ ##
76
+ # parse_name_servers parses the name-server values from
77
+ # config
78
+ #
79
+ # @api private
80
+ #
81
+ # @return [Hash<Symbol, Array>] resource hash attribute
68
82
  def parse_name_servers
69
83
  servers = config.scan(/(?:ip name-server vrf )(?:\w+)\s(.+)/)
70
84
  values = servers.each_with_object([]) { |srv, arry| arry << srv.first }
71
85
  { name_servers: values }
72
86
  end
87
+ private :parse_name_servers
73
88
 
89
+ ##
90
+ # parse_domain_list parses the domain-list from config
91
+ #
92
+ # @api private
93
+ #
94
+ # @return [Hash<Symbol, Object>] resource hash attribute
74
95
  def parse_domain_list
75
96
  search = config.scan(/(?<=^ip\sdomain-list\s).+$/)
76
97
  { domain_list: search }
77
98
  end
99
+ private :parse_domain_list
78
100
 
79
101
  ##
80
102
  # Configure the domain-name value in the running-config
@@ -135,10 +157,22 @@ module Rbeapi
135
157
  configure cmds
136
158
  end
137
159
 
160
+ ##
161
+ # add_name_server adds an ip name-server.
162
+ #
163
+ # @param [String] :server The name of the ip name-server to create
164
+ #
165
+ # @return [Boolean] returns true if the command completed successfully
138
166
  def add_name_server(server)
139
167
  configure "ip name-server #{server}"
140
168
  end
141
169
 
170
+ ##
171
+ # remove_name_server removes the specified ip name-server.
172
+ #
173
+ # @param [String] :server The name of the ip name-server to remove
174
+ #
175
+ # @return [Boolean] returns true if the command completed successfully
142
176
  def remove_name_server(server)
143
177
  configure "no ip name-server #{server}"
144
178
  end
@@ -190,10 +224,22 @@ module Rbeapi
190
224
  configure cmds
191
225
  end
192
226
 
227
+ ##
228
+ # add_domain_list adds an ip domain-list.
229
+ #
230
+ # @param [String] :name The name of the ip domain-list to add
231
+ #
232
+ # @return [Boolean] returns true if the command completed successfully
193
233
  def add_domain_list(name)
194
234
  configure "ip domain-list #{name}"
195
235
  end
196
236
 
237
+ ##
238
+ # remove_domain_list removes a specified ip domain-list.
239
+ #
240
+ # @param [String] :name The name of the ip domain-list to remove
241
+ #
242
+ # @return [Boolean] returns true if the command completed successfully
197
243
  def remove_domain_list(name)
198
244
  configure "no ip domain-list #{name}"
199
245
  end
@@ -36,7 +36,7 @@ require 'rbeapi/utils'
36
36
  # Rbeapi toplevel namespace
37
37
  module Rbeapi
38
38
  ##
39
- # Api module namespace
39
+ # Api is module namespace for working with the EOS command API
40
40
  module Api
41
41
  ##
42
42
  # The Interfaces class manages all physical and logical interfaces on an
@@ -47,10 +47,52 @@ module Rbeapi
47
47
  @instances = {}
48
48
  end
49
49
 
50
+ ##
51
+ # get returns a hash of interface configurations for the given name
52
+ #
53
+ # @example
54
+ # {
55
+ # name: <string>,
56
+ # type: <string>,
57
+ # description: <string>,
58
+ # shutdown: <boolean>
59
+ # }
60
+ #
61
+ # @param [String] :name The interface name to return a resource for from
62
+ # the nodes configuration
63
+ #
64
+ # @return [nil, Hash<Symbol, Object>] Returns the interface resource as a
65
+ # Hash. If the specified name is not found in the nodes current
66
+ # configuration a nil object is returned
50
67
  def get(name)
51
68
  get_instance(name).get(name)
52
69
  end
53
70
 
71
+ ##
72
+ # getall returns a hash of interface configurations
73
+ #
74
+ # @example
75
+ # {
76
+ # <name>: {
77
+ # name: <string>,
78
+ # type: <string>,
79
+ # description: <string>,
80
+ # shutdown: <boolean>,
81
+ # ...
82
+ # },
83
+ # <name>: {
84
+ # name: <string>,
85
+ # type: <string>,
86
+ # description: <string>,
87
+ # shutdown: <boolean>,
88
+ # ...
89
+ # },
90
+ # ...
91
+ # }
92
+ #
93
+ # @return [Hash<Symbol, Object>] Returns the interface resources as a
94
+ # Hash. If none exist in the nodes current
95
+ # configuration an empty hash is returned
54
96
  def getall
55
97
  interfaces = config.scan(/(?<=^interface\s).+$/)
56
98
 
@@ -60,6 +102,13 @@ module Rbeapi
60
102
  end
61
103
  end
62
104
 
105
+ ##
106
+ # get_instance returns an interface instance for the given name
107
+ #
108
+ # @param [String] :name The interface name to return an instance for
109
+ #
110
+ # @return [Object] Returns the interface instance as an
111
+ # Object.
63
112
  def get_instance(name)
64
113
  name = name[0, 2].upcase
65
114
  case name
@@ -287,20 +336,18 @@ module Rbeapi
287
336
  # get returns the specified Ethernet interface resource hash that
288
337
  # represents the interface's current configuration in the node.
289
338
  #
290
- # The resource hash returned contains the following information:
291
- #
292
- # * name (string): the interface name (eg Ethernet1)
293
- # * type (string): will always be 'ethernet'
294
- # * description (string): the interface description value
295
- # * speed (string): the current speed setting for the interface speed
296
- # * forced (boolean): true if auto negotiation is disabled otherwise
297
- # false
298
- # * sflow (boolean): true if sflow is enabled on the interface
299
- # otherwise false
300
- # * flowcontrol_send (string): the interface flowcontrol send value.
301
- # Valid values are 'on' or 'off'
302
- # * flowconrol_receive (string): the interface flowcontrol receive
303
- # value. Valid values are 'on' or 'off'
339
+ # @example
340
+ # {
341
+ # name: <string>,
342
+ # type: <string>,
343
+ # description: <string>,
344
+ # shutdown: <boolean>,
345
+ # speed: <string>,
346
+ # forced: <boolean>,
347
+ # sflow: <boolean>,
348
+ # flowcontrol_send: <string>,
349
+ # flowcontrol_receive: <string>
350
+ # }
304
351
  #
305
352
  # @param [String] :name The interface name to return a resource hash
306
353
  # for from the node's running configuration
@@ -319,7 +366,6 @@ module Rbeapi
319
366
  response.merge!(parse_sflow(config))
320
367
  response.merge!(parse_flowcontrol_send(config))
321
368
  response.merge!(parse_flowcontrol_receive(config))
322
-
323
369
  response
324
370
  end
325
371
 
@@ -773,24 +819,41 @@ module Rbeapi
773
819
  # @param [Array] :members The array of physical interface members to add
774
820
  # to the port-channel logical interface.
775
821
  #
822
+ # @param [str] :mode The LACP mode to configure the member interfaces to.
823
+ # Valid values are 'on, 'passive', 'active'. When there are
824
+ # existing channel-group members and their lacp mode differs
825
+ # from this attribute, all of those members will be removed and
826
+ # then re-added using the specified lacp mode. If this attribute
827
+ # is omitted, the existing lacp mode will be used for new
828
+ # member additions.
829
+ #
776
830
  # @return [Boolean] returns true if the command completed successfully
777
- def set_members(name, members)
831
+ def set_members(name, members, mode = nil)
778
832
  current_members = Set.new parse_members(name)[:members]
779
833
  members = Set.new members
780
834
 
835
+ lacp_mode = parse_lacp_mode(name)[:lacp_mode]
836
+ if mode && mode != lacp_mode
837
+ lacp_mode = mode
838
+ set_lacp_mode(name, lacp_mode)
839
+ end
840
+
841
+ cmds = []
842
+ grpid = /(\d+)/.match(name)[0]
843
+
781
844
  # remove members from the current port-channel interface
782
845
  current_members.difference(members).each do |intf|
783
- result = remove_member(name, intf)
784
- return false unless result
846
+ cmds << "interface #{intf}"
847
+ cmds << "no channel-group #{grpid}"
785
848
  end
786
849
 
787
850
  # add new member interfaces to the port-channel
788
851
  members.difference(current_members).each do |intf|
789
- result = add_member(name, intf)
790
- return false unless result
852
+ cmds << "interface #{intf}"
853
+ cmds << "channel-group #{grpid} mode #{lacp_mode}"
791
854
  end
792
855
 
793
- true
856
+ configure(cmds)
794
857
  end
795
858
 
796
859
  ##
@@ -938,16 +1001,18 @@ module Rbeapi
938
1001
  # BaseInterface get method and adds the Vxlan specific attributes to
939
1002
  # the hash
940
1003
  #
941
- # The returned resource hash contains the following
942
- #
943
- # * name: (String) The full interface name identifier
944
- # * type: (String) 'vxlan'
945
- # * description: (String) The configured interface description
946
- # * shutdown: (Boolean) The admin state of the interface
947
- # * source_interface: (String) The vxlan source-interface value
948
- # * multicast_group: (String) The vxlan multicast-group value
949
- # * udp_port: (Fixnum) The vxlan udp-port value
950
- # * flood_list: (Array) The list of VTEPs to flood traffic towards
1004
+ # @example
1005
+ # {
1006
+ # name: <string>,
1007
+ # type: <string>,
1008
+ # description: <string>,
1009
+ # shutdown: <boolean>,
1010
+ # source_interface: <string>,
1011
+ # multicast_group: <string>,
1012
+ # udp_port: <fixnum>,
1013
+ # flood_list: <array>,
1014
+ # vlans: <hash>
1015
+ # }
951
1016
  #
952
1017
  # @param [String] :name The interface name to return from the nodes
953
1018
  # configuration. This optional parameter defaults to Vxlan1
@@ -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 Ipinterface class provides an instance for managing logical
@@ -79,7 +79,17 @@ module Rbeapi
79
79
  #
80
80
  # @example
81
81
  # {
82
- # <name>: {...}
82
+ # <name>: {
83
+ # address: <string>
84
+ # mtu: <string>
85
+ # helper_addresses: array<strings>
86
+ # },
87
+ # <name>: {
88
+ # address: <string>
89
+ # mtu: <string>
90
+ # helper_addresses: array<strings>
91
+ # },
92
+ # ...
83
93
  # }
84
94
  #
85
95
  # @see get Ipaddress resource example
@@ -103,6 +113,7 @@ module Rbeapi
103
113
  # ipaddress resource hash.
104
114
  #
105
115
  # @api private
116
+ #
106
117
  # @param [String] :config The IP interface configuration block returned
107
118
  # from the node's running configuration
108
119
  #
@@ -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 Logging class manages logging settings on an EOS node.
@@ -46,7 +46,7 @@ module Rbeapi
46
46
  #
47
47
  # @example
48
48
  # {
49
- # enable: [true, false]
49
+ # enable: [true, false],
50
50
  # hosts: array<strings>
51
51
  # }
52
52
  #
@@ -65,6 +65,10 @@ module Rbeapi
65
65
  # command is expected to always be in the node's configuration. This
66
66
  # methods return value is intended to be merged into the logging resource
67
67
  # hash.
68
+ #
69
+ # @api private
70
+ #
71
+ # @return [Hash<Symbol, Object>] resource hash attribute
68
72
  def parse_enable
69
73
  value = /no logging on/ !~ config
70
74
  { enable: value }
@@ -76,10 +80,15 @@ module Rbeapi
76
80
  # logging hosts are configured, then the value for hosts will be an empty
77
81
  # array. The return value is intended to be merged into the logging
78
82
  # resource hash
83
+ #
84
+ # @api private
85
+ #
86
+ # @return [Hash<Symbol, Object>] resource hash attribute
79
87
  def parse_hosts
80
88
  hosts = config.scan(/(?<=^logging\shost\s)[^\s]+/)
81
89
  { hosts: hosts }
82
90
  end
91
+ private :parse_hosts
83
92
 
84
93
  ##
85
94
  # set_enable configures the global logging instance on the node as either
@@ -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 Mlag class provides a configuration instance for working with
@@ -50,15 +50,25 @@ module Rbeapi
50
50
  # get scans the current nodes configuration and returns the values as
51
51
  # a Hash describing the current state.
52
52
  #
53
- # The resource hash returned contains the following:
54
- # * domain_id: (String) The MLAG domain-id value
55
- # * local_interface: (String) The MLAG local-interface value
56
- # * peer_address: (String) The IP address of the MLAG peer
57
- # * peer_link: (String) The MLAG transit peer-link value
58
- # * shutdown: (Boolean) The administrative staet of the mlag
59
- # configuration
60
- # * interfaces: (Hash) The list of configured MLAG interfaces. (See
61
- # parse_interfaces for the Hash details)
53
+ # @example
54
+ # {
55
+ # global: {
56
+ # domain_id: <string>,
57
+ # local_interface: <string>,
58
+ # peer_address: <string>,
59
+ # peer_link: <string>,
60
+ # shutdown: <boolean>
61
+ # },
62
+ # interfaces: {
63
+ # <name>: {
64
+ # mlag_id: <fixnum>
65
+ # },
66
+ # <name>: {
67
+ # mlag_id: <fixnum>
68
+ # },
69
+ # ...
70
+ # }
71
+ # }
62
72
  #
63
73
  # @see parse_interfaces
64
74
  #
@@ -32,10 +32,10 @@
32
32
  require 'rbeapi/api'
33
33
 
34
34
  ##
35
- # Eos is the toplevel namespace for working with Arista EOS nodes
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 Ntp class provides an instance for working with the nodes
@@ -48,7 +48,7 @@ module Rbeapi
48
48
  #
49
49
  # @example
50
50
  # {
51
- # source_interface: <string>
51
+ # source_interface: <string>,
52
52
  # servers: {
53
53
  # prefer: [true, false]
54
54
  # }
@@ -95,6 +95,7 @@ module Rbeapi
95
95
  end
96
96
  { servers: values }
97
97
  end
98
+ private :parse_servers
98
99
 
99
100
  ##
100
101
  # set_source_interface configures the ntp source value in the nodes