puppet_x_eos_eapi 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +24 -0
  4. data/LICENSE.txt +202 -0
  5. data/README.md +87 -0
  6. data/Rakefile +1 -0
  7. data/lib/puppet_x/eos/autoload.rb +57 -0
  8. data/lib/puppet_x/eos/eapi.rb +259 -0
  9. data/lib/puppet_x/eos/module_base.rb +37 -0
  10. data/lib/puppet_x/eos/modules/daemon.rb +109 -0
  11. data/lib/puppet_x/eos/modules/extension.rb +167 -0
  12. data/lib/puppet_x/eos/modules/interface.rb +180 -0
  13. data/lib/puppet_x/eos/modules/ipinterface.rb +133 -0
  14. data/lib/puppet_x/eos/modules/mlag.rb +268 -0
  15. data/lib/puppet_x/eos/modules/ntp.rb +129 -0
  16. data/lib/puppet_x/eos/modules/ospf.rb +129 -0
  17. data/lib/puppet_x/eos/modules/portchannel.rb +277 -0
  18. data/lib/puppet_x/eos/modules/radius.rb +367 -0
  19. data/lib/puppet_x/eos/modules/snmp.rb +177 -0
  20. data/lib/puppet_x/eos/modules/switchport.rb +255 -0
  21. data/lib/puppet_x/eos/modules/system.rb +138 -0
  22. data/lib/puppet_x/eos/modules/tacacs.rb +302 -0
  23. data/lib/puppet_x/eos/modules/vlan.rb +179 -0
  24. data/lib/puppet_x/eos/modules/vxlan.rb +132 -0
  25. data/lib/puppet_x/eos/provider.rb +71 -0
  26. data/lib/puppet_x/eos/version.rb +41 -0
  27. data/lib/puppet_x/net_dev/eos_api.rb +1011 -0
  28. data/lib/puppet_x/net_dev/eos_api/common_methods.rb +27 -0
  29. data/lib/puppet_x/net_dev/eos_api/snmp_methods.rb +647 -0
  30. data/lib/puppet_x/net_dev/eos_api/version.rb +8 -0
  31. data/lib/puppet_x_eos_eapi.rb +4 -0
  32. data/puppet_x_eos_eapi.gemspec +31 -0
  33. data/spec/fixtures/fixture_all_portchannel_modes.json +8 -0
  34. data/spec/fixtures/fixture_all_portchannels_detailed.json +15 -0
  35. data/spec/fixtures/fixture_create_vlan_error.json +17 -0
  36. data/spec/fixtures/fixture_create_vlan_success.json +12 -0
  37. data/spec/fixtures/fixture_eapi_conf.yaml +4 -0
  38. data/spec/fixtures/fixture_enable_configure_vlan_3111_name_foo.json +14 -0
  39. data/spec/fixtures/fixture_enable_configure_vlan_foo_name_bar.json +19 -0
  40. data/spec/fixtures/fixture_get_snmp_communities_non_existent_acl.yaml +2 -0
  41. data/spec/fixtures/fixture_get_snmp_location_westeros.json +5 -0
  42. data/spec/fixtures/fixture_portchannel_min_links_1.json +8 -0
  43. data/spec/fixtures/fixture_portchannel_min_links_2.json +8 -0
  44. data/spec/fixtures/fixture_running_config.yaml +1 -0
  45. data/spec/fixtures/fixture_running_configuration_radius_configured.yaml +30 -0
  46. data/spec/fixtures/fixture_running_configuration_radius_default.yaml +29 -0
  47. data/spec/fixtures/fixture_running_configuration_radius_server_groups.yaml +38 -0
  48. data/spec/fixtures/fixture_running_configuration_radius_servers.yaml +34 -0
  49. data/spec/fixtures/fixture_running_configuration_tacacs_configured.yaml +38 -0
  50. data/spec/fixtures/fixture_running_configuration_tacacs_default.yaml +38 -0
  51. data/spec/fixtures/fixture_running_configuration_tacacs_groups.yaml +1 -0
  52. data/spec/fixtures/fixture_running_configuration_tacacs_groups_3.yaml +43 -0
  53. data/spec/fixtures/fixture_running_configuration_tacacs_servers.yaml +41 -0
  54. data/spec/fixtures/fixture_s4_show_etherchannel_detailed.json +9 -0
  55. data/spec/fixtures/fixture_show_flowcontrol_et1.json +5 -0
  56. data/spec/fixtures/fixture_show_interfaces.json +297 -0
  57. data/spec/fixtures/fixture_show_interfaces_switchport_format_text.json +9 -0
  58. data/spec/fixtures/fixture_show_port_channel_summary_2_lags.json +9 -0
  59. data/spec/fixtures/fixture_show_port_channel_summary_static.json +9 -0
  60. data/spec/fixtures/fixture_show_snmp_community.yaml +2 -0
  61. data/spec/fixtures/fixture_show_snmp_contact_empty.json +5 -0
  62. data/spec/fixtures/fixture_show_snmp_contact_name.json +5 -0
  63. data/spec/fixtures/fixture_show_snmp_disabled.json +5 -0
  64. data/spec/fixtures/fixture_show_snmp_enabled.json +5 -0
  65. data/spec/fixtures/fixture_show_snmp_host.yaml +2 -0
  66. data/spec/fixtures/fixture_show_snmp_host_duplicates.yaml +2 -0
  67. data/spec/fixtures/fixture_show_snmp_host_more_duplicates.yaml +2 -0
  68. data/spec/fixtures/fixture_show_snmp_location_empty.json +5 -0
  69. data/spec/fixtures/fixture_show_snmp_trap.yaml +2 -0
  70. data/spec/fixtures/fixture_show_snmp_user.yaml +2 -0
  71. data/spec/fixtures/fixture_show_snmp_user_raw_text.yaml +1 -0
  72. data/spec/fixtures/fixture_show_vlan.json +37 -0
  73. data/spec/fixtures/fixture_show_vlan_3110.json +18 -0
  74. data/spec/fixtures/fixture_show_vlan_4000.json +18 -0
  75. data/spec/fixtures/fixture_snmp_host_opts.yaml +11 -0
  76. data/spec/spec_helper.rb +21 -0
  77. data/spec/support/fixtures.rb +104 -0
  78. data/spec/unit/puppet_x/eos/eapi_spec.rb +182 -0
  79. data/spec/unit/puppet_x/eos/module_base_spec.rb +26 -0
  80. data/spec/unit/puppet_x/eos/modules/daemon_spec.rb +110 -0
  81. data/spec/unit/puppet_x/eos/modules/extension_spec.rb +197 -0
  82. data/spec/unit/puppet_x/eos/modules/fixtures/daemon_getall.json +3 -0
  83. data/spec/unit/puppet_x/eos/modules/fixtures/extension_getall.json +28 -0
  84. data/spec/unit/puppet_x/eos/modules/fixtures/hostname.json +6 -0
  85. data/spec/unit/puppet_x/eos/modules/fixtures/interface_getall.json +509 -0
  86. data/spec/unit/puppet_x/eos/modules/fixtures/ipinterface_getall.json +56 -0
  87. data/spec/unit/puppet_x/eos/modules/fixtures/mlag_get.json +21 -0
  88. data/spec/unit/puppet_x/eos/modules/fixtures/mlag_get_interfaces.json +18 -0
  89. data/spec/unit/puppet_x/eos/modules/fixtures/ntp_get.json +5 -0
  90. data/spec/unit/puppet_x/eos/modules/fixtures/ospf_instance_getall.json +58 -0
  91. data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_get.json +54 -0
  92. data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_getlacpmode.json +5 -0
  93. data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_getmembers.json +5 -0
  94. data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_po1.json +7 -0
  95. data/spec/unit/puppet_x/eos/modules/fixtures/snmp_get.json +14 -0
  96. data/spec/unit/puppet_x/eos/modules/fixtures/switchport_get.json +5 -0
  97. data/spec/unit/puppet_x/eos/modules/fixtures/switchport_get_et1.json +7 -0
  98. data/spec/unit/puppet_x/eos/modules/fixtures/switchport_getall_interfaces.json +230 -0
  99. data/spec/unit/puppet_x/eos/modules/fixtures/system_domain_list.json +5 -0
  100. data/spec/unit/puppet_x/eos/modules/fixtures/system_domain_name.json +5 -0
  101. data/spec/unit/puppet_x/eos/modules/fixtures/system_hostname.json +6 -0
  102. data/spec/unit/puppet_x/eos/modules/fixtures/system_name_servers.json +5 -0
  103. data/spec/unit/puppet_x/eos/modules/fixtures/vlan_getall.json +123 -0
  104. data/spec/unit/puppet_x/eos/modules/fixtures/vxlan_get.json +24 -0
  105. data/spec/unit/puppet_x/eos/modules/interface_spec.rb +281 -0
  106. data/spec/unit/puppet_x/eos/modules/ipinterface_spec.rb +143 -0
  107. data/spec/unit/puppet_x/eos/modules/mlag_spec.rb +349 -0
  108. data/spec/unit/puppet_x/eos/modules/ntp_spec.rb +136 -0
  109. data/spec/unit/puppet_x/eos/modules/ospf_spec.rb +143 -0
  110. data/spec/unit/puppet_x/eos/modules/portchannel_spec.rb +357 -0
  111. data/spec/unit/puppet_x/eos/modules/radius_spec.rb +509 -0
  112. data/spec/unit/puppet_x/eos/modules/snmp_spec.rb +202 -0
  113. data/spec/unit/puppet_x/eos/modules/switchport_get_et1.json +7 -0
  114. data/spec/unit/puppet_x/eos/modules/switchport_spec.rb +307 -0
  115. data/spec/unit/puppet_x/eos/modules/system_spec.rb +170 -0
  116. data/spec/unit/puppet_x/eos/modules/tacacs_spec.rb +448 -0
  117. data/spec/unit/puppet_x/eos/modules/vlan_spec.rb +244 -0
  118. data/spec/unit/puppet_x/eos/modules/vxlan_spec.rb +189 -0
  119. data/spec/unit/puppet_x/eos/provider_spec.rb +35 -0
  120. data/spec/unit/puppet_x/net_dev/eos_api/common_methods_spec.rb +34 -0
  121. data/spec/unit/puppet_x/net_dev/eos_api/snmp_methods_spec.rb +842 -0
  122. data/spec/unit/puppet_x/net_dev/eos_api_spec.rb +1000 -0
  123. metadata +369 -0
@@ -0,0 +1,133 @@
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
+
33
+ ##
34
+ # Eos is the toplevel namespace for working with Arista EOS nodes
35
+ module PuppetX
36
+ ##
37
+ # Eapi is module namesapce for working with the EOS command API
38
+ module Eos
39
+ ##
40
+ # The Ipinterface class provides an instance for managing logical
41
+ # IP interfaces configured using eAPI.
42
+ class Ipinterface
43
+ def initialize(api)
44
+ @api = api
45
+ end
46
+
47
+ ##
48
+ # Retrieves all logical IP interfaces from the running-configuration
49
+ # and returns all instances
50
+ #
51
+ # Example:
52
+ # {
53
+ # "interfaces": {
54
+ # "Ethernet1": {
55
+ # "interfaceAddress": {
56
+ # "secondaryIpsOrderedList": [],
57
+ # "broadcastAddress": "255.255.255.255",
58
+ # "secondaryIps": {},
59
+ # "primaryIp": {
60
+ # "maskLen": 32,
61
+ # "address": "1.1.1.1"
62
+ # },
63
+ # "virtualIp": {
64
+ # "maskLen": 0,
65
+ # "address": "0.0.0.0"
66
+ # }
67
+ # },
68
+ # "name": "Loopback0",
69
+ # "urpf": "disable",
70
+ # "interfaceStatus": "connected",
71
+ # "enabled": true,
72
+ # "mtu": 65535,
73
+ # "vrf": "default",
74
+ # "localProxyArp": false,
75
+ # "proxyArp": false,
76
+ # "lineProtocolStatus": "up",
77
+ # "description": "managed by PE"
78
+ # },
79
+ # "Ethernet2": { ... },
80
+ # "Ethernet3": { ... }
81
+ # }
82
+ # }
83
+ #
84
+ # @return [Hash]
85
+ def getall
86
+ @api.enable('show ip interface')
87
+ end
88
+
89
+ ##
90
+ # Create a new logical IP interface in the running-config
91
+ #
92
+ # @param [String] name The name of the interface
93
+ #
94
+ # @return [Boolean] True if the create succeeds otherwise False
95
+ def create(name)
96
+ @api.config(["interface #{name}", 'no switchport']) == [{}, {}]
97
+ end
98
+
99
+ ##
100
+ # Deletes a logical IP interface from the running-config
101
+ #
102
+ # @param [String] name The name of the interface
103
+ #
104
+ # @return [Boolean] True if the create succeeds otherwise False
105
+ def delete(name)
106
+ @api.config(["interface #{name}", 'no ip address']) == [{}, {}]
107
+ end
108
+
109
+ ##
110
+ ## Configures the IP address and mask length for the interface
111
+ #
112
+ # @param [String] name The name of the interface to configure
113
+ # @param [Hash] opts The configuration parameters for the interface
114
+ # @option opts [string] :value The value to set the address to
115
+ # @option opts [Boolean] :default The value should be set to default
116
+ #
117
+ # @return [Boolean] True if the commands succeed otherwise False
118
+ def set_address(name, opts = {})
119
+ value = opts[:value]
120
+ default = opts[:default] || false
121
+
122
+ cmds = ["interface #{name}"]
123
+ case default
124
+ when true
125
+ cmds << 'default ip address'
126
+ when false
127
+ cmds << (value.nil? ? 'no ip address' : "ip address #{value}")
128
+ end
129
+ @api.config(cmds) == [{}, {}]
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,268 @@
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
+
33
+ ##
34
+ # PuppetX is the toplevel namespace for working with Arista EOS nodes
35
+ module PuppetX
36
+ ##
37
+ # Eos is module namesapce for working with the EOS command API
38
+ module Eos
39
+ ##
40
+ # The Mlag class provides a base class instance for working with
41
+ # the global mlag configuration
42
+ #
43
+ class Mlag
44
+ ##
45
+ # Initialize instance of Snmp
46
+ #
47
+ # @param [PuppetX::Eos::Eapi] api An instance of Eapi
48
+ #
49
+ # @return [PuppetX::Eos::Mlag]
50
+ def initialize(api)
51
+ @api = api
52
+ end
53
+
54
+ ##
55
+ # Returns the Mlag hash representing global snmp configuration
56
+ #
57
+ # Example
58
+ # {
59
+ # "domain_id": <String>,
60
+ # "local_interface": <String>,
61
+ # "peer_address": <String>,
62
+ # "peer_link": <String>,
63
+ # "enable": [true, false]
64
+ # }
65
+ #
66
+ # @return [Array<Hash>] returns a Hash of attributes derived from eAPI
67
+ def get
68
+ result = @api.enable('show mlag')
69
+ attr_hash = {
70
+ domain_id: result[0]['domainId'],
71
+ peer_link: result[0]['peerLink'],
72
+ local_interface: result[0]['localInterface'],
73
+ peer_address: result[0]['peerAddress'],
74
+ enable: result[0]['state'] == 'disabled' ? :false : :true
75
+ }
76
+ attr_hash
77
+ end
78
+
79
+ ##
80
+ # Creates a new mlag instance
81
+ #
82
+ # @param [String] name The domain id of the mlag instance
83
+ #
84
+ # @return [Boolean] True if the commands succeed otherwise False
85
+ def create(name)
86
+ @api.config(['mlag configuration', "domain-id #{name}"]) == [{}, {}]
87
+ end
88
+
89
+ ##
90
+ # Deletes the current mlag configuration from the running-config
91
+ #
92
+ # @return [Boolean] True if the commands succeed otherwise False
93
+ def delete
94
+ @api.config('no mlag configuration') == [{}]
95
+ end
96
+
97
+ ##
98
+ # Defaults the current mlag configuration
99
+ #
100
+ # @return [Boolean] True if the command succeeds otherwise False
101
+ def default
102
+ @api.config('default mlag configuration') == [{}]
103
+ end
104
+
105
+ ##
106
+ # Retrieves the interfaces that are mlag enabled from the running-config
107
+ #
108
+ # @return [Array<Hash>] returns an Array of Hashes keyed by the mlag id
109
+ def get_interfaces
110
+ @api.enable('show mlag interfaces')
111
+ end
112
+
113
+ ##
114
+ # Adds a new interface to the MLAG domain with specified Mlag id
115
+ #
116
+ # @param [String] name The name of the interface to add
117
+ # @param [String] id The MLAG ID to assign to the interface
118
+ #
119
+ # @return [Boolean] True if the command succeeds otherwise False
120
+ def add_interface(name, id)
121
+ @api.config(["interface #{name}", "mlag #{id}"]) == [{}, {}]
122
+ end
123
+
124
+ ##
125
+ # Removes a previously configured interface from the Mlag domain
126
+ #
127
+ # @param [String] name The name of the interface to remove
128
+ #
129
+ # @return [Boolean] True if the command succeeds otherwise False
130
+ def remove_interface(name)
131
+ @api.config(["interface #{name}", 'no mlag']) == [{}, {}]
132
+ end
133
+
134
+ ##
135
+ # Configures the mlag id for an interface
136
+ #
137
+ # @param [String] name The interface to configure
138
+ # @param [Hash] opts The configuration parameters for mlag
139
+ # @option opts [string] :value The value to set the interface mlag id
140
+ # @option opts [Boolean] :default The value should be set to default
141
+ #
142
+ # @return [Boolean] True if the commands succeed otherwise False
143
+ def set_mlag_id(name, opts = {})
144
+ value = opts[:value] || false
145
+ default = opts[:default] || false
146
+
147
+ cmds = ["interface #{name}"]
148
+ case default
149
+ when true
150
+ cmds << 'default mlag'
151
+ when false
152
+ cmds << (value ? "mlag #{value}" : 'no mlag')
153
+ end
154
+ @api.config(cmds) == [{}, {}]
155
+ end
156
+
157
+ ##
158
+ # Configures the mlag domain_id
159
+ #
160
+ # @param [Hash] opts The configuration parameters for mlag
161
+ # @option opts [string] :value The value to set the domain-id to
162
+ # @option opts [Boolean] :default The value should be set to default
163
+ #
164
+ # @return [Boolean] True if the commands succeed otherwise False
165
+ def set_domain_id(opts = {})
166
+ value = opts[:value] || false
167
+ default = opts[:default] || false
168
+
169
+ cmds = ['mlag configuration']
170
+ case default
171
+ when true
172
+ cmds << 'default domain-id'
173
+ when false
174
+ cmds << (value ? "domain-id #{value}" : 'no domain-id')
175
+ end
176
+ @api.config(cmds) == [{}, {}]
177
+ end
178
+
179
+ ##
180
+ # Configures the mlag peer_link
181
+ #
182
+ # @param [Hash] opts The configuration parameters for mlag
183
+ # @option opts [string] :value The value to set the peer-link to
184
+ # @option opts [Boolean] :default The value should be set to default
185
+ #
186
+ # @return [Boolean] True if the commands succeed otherwise False
187
+ def set_peer_link(opts = {})
188
+ value = opts[:value] || false
189
+ default = opts[:default] || false
190
+
191
+ cmds = ['mlag configuration']
192
+ case default
193
+ when true
194
+ cmds << 'default peer-link'
195
+ when false
196
+ cmds << (value ? "peer-link #{value}" : 'no peer-link')
197
+ end
198
+ @api.config(cmds) == [{}, {}]
199
+ end
200
+
201
+ ##
202
+ # Configures the mlag peer_address
203
+ #
204
+ # @param [Hash] opts The configuration parameters for mlag
205
+ # @option opts [string] :value The value to set the peer-address to
206
+ # @option opts [Boolean] :default The value should be set to default
207
+ #
208
+ # @return [Boolean] True if the commands succeed otherwise False
209
+ def set_peer_address(opts = {})
210
+ value = opts[:value] || false
211
+ default = opts[:default] || false
212
+
213
+ cmds = ['mlag configuration']
214
+ case default
215
+ when true
216
+ cmds << 'default peer-address'
217
+ when false
218
+ cmds << (value ? "peer-address #{value}" : 'no peer-address')
219
+ end
220
+ @api.config(cmds) == [{}, {}]
221
+ end
222
+
223
+ ##
224
+ # Configures the mlag local_interface
225
+ #
226
+ # @param [Hash] opts The configuration parameters for mlag
227
+ # @option opts [string] :value The value to set the local-interface to
228
+ # @option opts [Boolean] :default The value should be set to default
229
+ #
230
+ # @return [Boolean] True if the commands succeed otherwise False
231
+ def set_local_interface(opts = {})
232
+ value = opts[:value] || false
233
+ default = opts[:default] || false
234
+
235
+ cmds = ['mlag configuration']
236
+ case default
237
+ when true
238
+ cmds << 'default local-interface'
239
+ when false
240
+ cmds << (value ? "local-interface #{value}" : 'no local-interface')
241
+ end
242
+ @api.config(cmds) == [{}, {}]
243
+ end
244
+
245
+ ##
246
+ # Configures the mlag operational state
247
+ #
248
+ # @param [Hash] opts The configuration parameters for mlag
249
+ # @option opts [string] :value The value to set the state to
250
+ # @option opts [Boolean] :default The value should be set to default
251
+ #
252
+ # @return [Boolean] True if the commands succeed otherwise False
253
+ def set_shutdown(opts = {})
254
+ value = opts[:value] || false
255
+ default = opts[:default] || false
256
+
257
+ cmds = ['mlag configuration']
258
+ case default
259
+ when true
260
+ cmds << 'default shutdown'
261
+ when false
262
+ cmds << (value ? 'shutdown' : 'no shutdown')
263
+ end
264
+ @api.config(cmds) == [{}, {}]
265
+ end
266
+ end
267
+ end
268
+ end
@@ -0,0 +1,129 @@
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
+
33
+ ##
34
+ # PuppetX is the toplevel namespace for working with Arista EOS nodes
35
+ module PuppetX
36
+ ##
37
+ # Eos is module namesapce for working with the EOS command API
38
+ module Eos
39
+ ##
40
+ # The Ntp class provides a base class instance for working with
41
+ # the global NTP configuration
42
+ #
43
+ class Ntp
44
+ ##
45
+ # Initialize instance of Snmp
46
+ #
47
+ # @param [PuppetX::Eos::Eapi] api An instance of Eapi
48
+ #
49
+ # @return [PuppetX::Eos::Ntp]
50
+ def initialize(api)
51
+ @api = api
52
+ end
53
+
54
+ ##
55
+ # Returns the Ntp hash representing current running ntp configuration
56
+ # from eAPI. Currently the servers element returns a hash of server
57
+ # keys with an empty hash value. Additional server attributes will
58
+ # be added in subsequent versions
59
+ #
60
+ # Example
61
+ # {
62
+ # "source_interface": <String>,
63
+ # "servers": {
64
+ # "A.B.C.D": {...}
65
+ # }
66
+ # }
67
+ #
68
+ # @return [Hash] returns a Hash of attributes derived from eAPI
69
+ def get
70
+ result = @api.enable('show running-config section ntp', format: 'text')
71
+ output = result.first['output']
72
+
73
+ m_source = /(?<=source\s)(\w|\d)+$/.match(output)
74
+
75
+ servers = {}
76
+ output.scan(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/).each do |srv|
77
+ servers[srv] = {}
78
+ end
79
+
80
+ attr_hash = {
81
+ 'source_interface' => m_source.nil? ? '' : m_source[0],
82
+ 'servers' => servers
83
+ }
84
+ attr_hash
85
+ end
86
+
87
+ ##
88
+ # Adds a new NTP server to the configured list
89
+ #
90
+ # @param [String] name The name of the interface to add
91
+ #
92
+ # @return [Boolean] True if the command succeeds otherwise False
93
+ def add_server(name)
94
+ @api.config("ntp server #{name}") == [{}]
95
+ end
96
+
97
+ ##
98
+ # Removes a previously configured interface from the Mlag domain
99
+ #
100
+ # @param [String] name The name of the interface to remove
101
+ #
102
+ # @return [Boolean] True if the command succeeds otherwise False
103
+ def remove_server(name)
104
+ @api.config("no ntp server #{name}") == [{}]
105
+ end
106
+
107
+ ##
108
+ # Configures the ntp source interface
109
+ #
110
+ # @param [Hash] opts The configuration parameters for mlag
111
+ # @option opts [string] :value The value to set the domain-id to
112
+ # @option opts [Boolean] :default The value should be set to default
113
+ #
114
+ # @return [Boolean] True if the commands succeed otherwise False
115
+ def set_source_interface(opts = {})
116
+ value = opts[:value] || false
117
+ default = opts[:default] || false
118
+
119
+ case default
120
+ when true
121
+ cmd = 'default ntp source'
122
+ when false
123
+ cmd = (value ? "ntp source #{value}" : 'no ntp source')
124
+ end
125
+ @api.config(cmd) == [{}]
126
+ end
127
+ end
128
+ end
129
+ end