puppet_x_eos_eapi 0.2.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 (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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a352c49c584998cfbb646599f4b466df8d337682
4
+ data.tar.gz: 618f0683af4bc6e6eb95b4555c0e11bfab0a77c7
5
+ SHA512:
6
+ metadata.gz: b44235dcc678fada446474a370d557e8afe60d5550652e43e242a7181f7e14aadf3938288a79d0235dadbfd87b3716e7ceaf25a700b5feb2ad7c4278b230df69
7
+ data.tar.gz: c319f1db4c39716a5ff0851b815a084ce613daa993b339d76ace9316ae84169d29eb232407bbc61b722dd391319471194e5cee89f4cc05e5adf5c34f78c52b64
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
2
+
3
+ gem 'net_http_unix'
4
+
5
+ group :development do
6
+ gem 'guard'
7
+ gem 'guard-rspec'
8
+ gem 'guard-rubocop'
9
+ gem 'guard-shell'
10
+ end
11
+
12
+ group :development, :test do
13
+ gem 'rake', '~> 10.1.0'
14
+ gem 'rspec', '~> 3.0.0'
15
+ gem 'rspec-mocks', '~> 3.0.0'
16
+ gem 'simplecov'
17
+ gem 'yard'
18
+ gem 'redcarpet', '~> 3.1.2'
19
+ gem 'pry', require: false
20
+ gem 'pry-doc', require: false
21
+ gem 'pry-stack_explorer', require: false
22
+ end
23
+
24
+ # vim:ft=ruby
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2014 Puppet Labs
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Arista eAPI Ruby Library
2
+
3
+ This ruby gem library implements configuration tasks using the Arista EOS eAPI.
4
+ The goal if this library is to provide a reusable set of classes and methods
5
+ for use with Puppet types and providers.
6
+
7
+ ## Installation for Development
8
+
9
+ First, clone the repository to your local development system:
10
+
11
+ $ cd /workspace
12
+ $ git clone git@github.com:puppetlabs/puppet_x_eos_eapi.git
13
+
14
+ Then add these lines to your module's Gemfile in order to use your development
15
+ copy of the Gem library:
16
+
17
+ ```ruby
18
+ puppet_x_eos_eapi_version = ENV['GEM_PUPPET_X_EOS_EAPI_VERSION']
19
+ if puppet_x_eos_eapi_version
20
+ gem 'puppet_x_eos_eapi', *location_for(puppet_x_eos_eapi_version)
21
+ else
22
+ gem 'puppet_x_eos_eapi'
23
+ end
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ export GEM_PUPPET_X_EOS_EAPI_VERSION=file:///workspace/puppet_x_eos_eapi
29
+ $ bundle install --path .bundle/gems/
30
+
31
+ ## Usage
32
+
33
+ Provider's extend themselves by including the API methods into the provider
34
+ class. For example,
35
+
36
+ ```ruby
37
+ # encoding: utf-8
38
+
39
+ require 'puppet/type'
40
+ require 'puppet_x_eos_eapi'
41
+ Puppet::Type.type(:network_snmp).provide(:eos) do
42
+
43
+ # Create methods that set the @property_hash for the #flush method
44
+ mk_resource_methods
45
+
46
+ # Mix in the api as instance methods
47
+ include PuppetX::Eos::ProviderMethods
48
+ # Mix in the api as class methods
49
+ extend PuppetX::Eos::ProviderMethods
50
+ # Mix in common provider class methods (e.g. self.prefetch)
51
+ extend PuppetX::Eos::ProviderClassMethods
52
+
53
+ def initialize(resource = {})
54
+ super(resource)
55
+ @property_flush = {}
56
+ end
57
+ end
58
+ ```
59
+
60
+ ## Behavior tests
61
+
62
+ When making changes to this Gem, please check the spec tests, code coverage,
63
+ documentation coverage, and rubocop warnings:
64
+
65
+ Behavior Tests:
66
+
67
+ bundle exec rspec spec
68
+
69
+ Code Coverage is automatically generated after the spec tests are run:
70
+
71
+ open coverage/index.html
72
+
73
+ Documentation:
74
+
75
+ bundle exec yard
76
+
77
+ Rubocop warnings:
78
+
79
+ bundle exec rubocop
80
+
81
+ ## Contributing
82
+
83
+ 1. Fork it
84
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
85
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
86
+ 4. Push to the branch (`git push origin my-new-feature`)
87
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,57 @@
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
+ require 'puppet_x/eos/module_base'
34
+
35
+ ##
36
+ # PuppetX namespace
37
+ module PuppetX
38
+ ##
39
+ # Eos namespace
40
+ module Eos
41
+ autoload :Vlan, 'puppet_x/eos/modules/vlan'
42
+ autoload :Extension, 'puppet_x/eos/modules/extension'
43
+ autoload :Daemon, 'puppet_x/eos/modules/daemon'
44
+ autoload :Interface, 'puppet_x/eos/modules/interface'
45
+ autoload :Switchport, 'puppet_x/eos/modules/switchport'
46
+ autoload :Ipinterface, 'puppet_x/eos/modules/ipinterface'
47
+ autoload :Snmp, 'puppet_x/eos/modules/snmp'
48
+ autoload :Vxlan, 'puppet_x/eos/modules/vxlan'
49
+ autoload :Mlag, 'puppet_x/eos/modules/mlag'
50
+ autoload :Ntp, 'puppet_x/eos/modules/ntp'
51
+ autoload :Ospf, 'puppet_x/eos/modules/ospf'
52
+ autoload :Portchannel, 'puppet_x/eos/modules/portchannel'
53
+ autoload :System, 'puppet_x/eos/modules/system'
54
+ autoload :Radius, 'puppet_x/eos/modules/radius'
55
+ autoload :Tacacs, 'puppet_x/eos/modules/tacacs'
56
+ end
57
+ end
@@ -0,0 +1,259 @@
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 'net/http'
33
+ require 'net_http_unix'
34
+ require 'json'
35
+ require 'syslog'
36
+
37
+ require 'puppet_x/eos/version'
38
+ require 'puppet_x/eos/autoload'
39
+
40
+ ##
41
+ # PuppetX namespace
42
+ module PuppetX
43
+ ##
44
+ # Eos namespace
45
+ module Eos
46
+ ##
47
+ # Eapi class
48
+ class Eapi
49
+ attr_reader :hostname
50
+ attr_reader :port
51
+ attr_reader :username
52
+ attr_reader :password
53
+ attr_reader :enable_pwd
54
+ attr_reader :use_ssl
55
+ attr_reader :uri
56
+ attr_reader :socket
57
+
58
+ # The default path to the EOS command api unix domain socket.
59
+ SOCKET_PATH = '/var/run/command-api.sock'
60
+
61
+ # ApiError is raised when there are errors in the REST API repsonse.
62
+ class ApiError < Exception; end
63
+
64
+ ##
65
+ # Initialize an instance of Eapi. This class provides direct API
66
+ # connectivity to command API running on Arista EOS switches. This class
67
+ # will send and receive eAPI calls using JSON-RPC over HTTP/S. Each
68
+ # option has a corresponding environment variable which will override the
69
+ # options hash if defined.
70
+ #
71
+ # @param [Hash] opts The eAPI configuration options
72
+ #
73
+ # @option opts [String] :hostname (EOS_HOSTNAME) Hostname or IP address
74
+ # of eAPI endpoint.
75
+ # @option opts [String] :username (EOS_USERNAME) eAPI username
76
+ # @option opts [String] :password (EOS_PASSWORD) eAPI password
77
+ # @option opts [String] :enable_pwd (EOS_ENABLE_PASSWORD) Enable mode
78
+ # password
79
+ # @option opts [Boolean] :use_ssl (EOS_USE_SSL) eAPI protocol
80
+ # @option opts [Integer] :port (EOS_PORT) eAPI port
81
+ # @option opts [String] :socket ('/var/run/command-api.sock') Initialize
82
+ # an HTTP client using a unix domain socket. This option will negate
83
+ # the :hostname, :port, :username, :password, :port, and :use_ssl
84
+ # options
85
+ #
86
+ # @return [Eos::Eapi] instance of Eos::Eapi
87
+ def initialize(opts = {})
88
+ @hostname = ENV['EOS_HOSTNAME'] || opts[:hostname] || 'localhost'
89
+ @username = ENV['EOS_USERNAME'] || opts[:username] || 'admin'
90
+ @password = ENV['EOS_PASSWORD'] || opts[:password] || ''
91
+ @enable_pwd = ENV['EOS_ENABLE_PASSWORD'] || opts[:enable_pwd] || ''
92
+ use_ssl = (ENV['EOS_USE_SSL'] || opts[:use_ssl]) ? true : false
93
+ @protocol = use_ssl ? 'https' : 'http'
94
+ port = (ENV['EOS_PORT'] || opts[:port]) || (use_ssl ? '443' : '80')
95
+ @port = port.to_i
96
+ unless ENV['EOS_DISABLE_SOCKET']
97
+ @socket = ENV['EOS_SOCKET_PATH'] || opts[:socket]
98
+ unless @socket
99
+ sock_path = Pathname.new(SOCKET_PATH)
100
+ if sock_path.socket? && sock_path.readable? && sock_path.writable?
101
+ @socket = SOCKET_PATH
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ ##
108
+ # uri returns a URI object
109
+ #
110
+ # @return [Uri]
111
+ def uri
112
+ return @uri if @uri
113
+ @uri = URI("#{@protocol}://#{@hostname}:#{@port}")
114
+ end
115
+
116
+ ##
117
+ # http returns a memoized HTTP object instance
118
+ #
119
+ # @return [Net::Http] http client
120
+ def http
121
+ return @http if @http
122
+ if @socket
123
+ @http = NetX::HTTPUnix.new("unix://#{@socket}")
124
+ else
125
+ @http = Net::HTTP.new(uri.host, uri.port)
126
+ end
127
+ end
128
+
129
+ ##
130
+ # Autloads an eAPI provider module for working with EOS objects
131
+ #
132
+ # @return [Object]
133
+ def method_missing(name)
134
+ name = "PuppetX::Eos::#{name}"
135
+ klass = name.split('::').inject(Object) { |a, e| a.const_get e }
136
+ klass.new self
137
+ end
138
+
139
+ ##
140
+ # The request method converts an array of commands to a valid
141
+ # eAPI request hash. The request message can be then sent to the eAPI
142
+ # end point using JSON-RPC over HTTP/S. eAPI exposes a single method,
143
+ # runCmds.
144
+ #
145
+ # @param [Array<String>] command An array of commands to be inserted
146
+ #
147
+ # @return [Hash] returns a hash that can be serialized to JSON and sent
148
+ # to the command API end point
149
+ def request(command, params = {})
150
+ # id = params[:id] || SecureRandom.uuid
151
+ id = 1
152
+ format = params[:format] || 'json'
153
+ cmds = [*command]
154
+ params = { 'version' => 1, 'cmds' => cmds, 'format' => format }
155
+ { 'jsonrpc' => '2.0', 'method' => 'runCmds',
156
+ 'params' => params, 'id' => id }
157
+ end
158
+
159
+ ##
160
+ # The invoke method takes the JSON formatted message and sends it
161
+ # to the eAPI end point. The response return value from command API
162
+ # is parsed from JSON and returned as an array of hashes with the output
163
+ # for each command
164
+ #
165
+ # @param [Array<String>] ordered list of commands to send to the host
166
+ #
167
+ # return [Array<Hash>] ordered list of ouput from the command execution
168
+ def invoke(body)
169
+ request = Net::HTTP::Post.new('/command-api')
170
+ request.body = JSON.dump(body)
171
+ request.basic_auth @username, @password
172
+ response = http.request(request)
173
+ JSON(response.body)
174
+ end
175
+
176
+ ##
177
+ # The execute method takes the array of commands and inserts
178
+ # the 'enable' command to make certain the commands are executed in
179
+ # priviledged mode. If an enable password is needed, it is inserted
180
+ # into the command stack as well. Since the enable command will generate
181
+ # an empty hash on the response, it is popped off before returning the
182
+ # array of hashes
183
+ #
184
+ # @param [Array<String>] ordered list of commands to insert into the
185
+ # POST request
186
+ #
187
+ # @return [Array<Hash>] ordered list of output from the command
188
+ #
189
+ # @raise [Eos::Eapi::CommandError] if the response from invoke contains
190
+ # the key error
191
+ def execute(commands, options = {})
192
+ modified_commands = [{cmd: 'enable', input: @enable_pwd}, *commands]
193
+ resp = invoke(request(modified_commands, options))
194
+ if resp['error']
195
+ data = resp['error']['data']
196
+ fail ApiError, "command #{commands.inspect} failed: #{format_error(data)}"
197
+ end
198
+ result = resp['result']
199
+ result.shift
200
+ result
201
+ end
202
+
203
+ ##
204
+ # The enable method is a convenience method that will handling putting
205
+ # the switch into priviledge mode prior to executing commands.
206
+ #
207
+ # @param [Array<String>] commands An ordered list of commands to execute
208
+ #
209
+ # @return [Array<Hash>] ordered list of output from commands
210
+ def enable(commands, options = {})
211
+ execute([*commands], options)
212
+ end
213
+
214
+ ##
215
+ # The config method is a convenience method that will handling putting
216
+ # the switch into config mode prior to executing commands. The method
217
+ # will insert 'config' at the top of the command stack and then pop
218
+ # the empty hash from the response output before return the array
219
+ # to the caller
220
+ #
221
+ # @param [Array<String>] commands An ordered list of commands to execute
222
+ #
223
+ # @return [Array<Hash>] ordered list of output from commands
224
+ def config(commands)
225
+ commands = [*commands] unless commands.respond_to?('each')
226
+ commands.insert(0, 'configure')
227
+ begin
228
+ result = enable(commands)
229
+ result.shift
230
+ result
231
+ rescue
232
+ return nil
233
+ end
234
+ end
235
+
236
+ ##
237
+ # format_error takes the value of the 'error' key from the EOS API
238
+ # response and formats the error strings into a string suitable for error
239
+ # messages.
240
+ #
241
+ # @param [Array<Hash>] data Array of data from the API response, this
242
+ # will be lcoated in the sub-key api_response['error']['data']
243
+ #
244
+ # @api private
245
+ #
246
+ # @return [String] the human readable error message
247
+ def format_error(data)
248
+ if data
249
+ data.each_with_object([]) do |i, ary|
250
+ ary.push(*i['errors']) if i['errors']
251
+ end.join(', ')
252
+ else
253
+ 'unknown error'
254
+ end
255
+ end
256
+ private :format_error
257
+ end
258
+ end
259
+ end