├── cookbooks
├── ohai
│ ├── files
│ │ └── default
│ │ │ └── plugins
│ │ │ └── README
│ ├── metadata.rb
│ ├── CHANGELOG.md
│ ├── attributes
│ │ └── default.rb
│ ├── CONTRIBUTING
│ ├── recipes
│ │ └── default.rb
│ ├── README.md
│ ├── metadata.json
│ └── LICENSE
└── eos
│ ├── CHANGELOG.md
│ ├── LICENSE
│ ├── recipes
│ ├── default.rb
│ ├── vlan.rb
│ ├── interface.rb
│ ├── portchannel.rb
│ └── switchport.rb
│ ├── README.md
│ ├── resources
│ ├── vlan.rb
│ ├── interface.rb
│ ├── switchport.rb
│ └── portchannel.rb
│ ├── attributes
│ └── default.rb
│ ├── metadata.rb
│ ├── libraries
│ ├── default.rb
│ └── eos_config.rb
│ ├── files
│ └── default
│ │ └── ohai
│ │ └── eos.rb
│ ├── providers
│ ├── interface.rb
│ ├── vlan.rb
│ ├── portchannel.rb
│ └── switchport.rb
│ └── metadata.json
├── README.md
└── LICENSE
/cookbooks/ohai/files/default/plugins/README:
--------------------------------------------------------------------------------
1 | This directory contains custom plugins for Ohai.
2 |
--------------------------------------------------------------------------------
/cookbooks/ohai/metadata.rb:
--------------------------------------------------------------------------------
1 | name "ohai"
2 | maintainer "Opscode, Inc"
3 | maintainer_email "cookbooks@opscode.com"
4 | license "Apache 2.0"
5 | description "Distributes a directory of custom ohai plugins"
6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7 | version "1.1.10"
8 |
9 | recipe "ohai::default", "Distributes a directory of custom ohai plugins"
10 |
11 | attribute "ohai/plugin_path",
12 | :display_name => "Ohai Plugin Path",
13 | :description => "Distribute plugins to this path.",
14 | :type => "string",
15 | :required => "optional",
16 | :default => "/etc/chef/ohai_plugins"
17 |
18 | attribute "ohai/plugins",
19 | :display_name => "Ohai Plugin Sources",
20 | :description => "Read plugins from these cookbooks and paths",
21 | :type => "hash",
22 | :required => "optional",
23 | :default => {'ohai' => 'plugins'}
24 |
--------------------------------------------------------------------------------
/cookbooks/ohai/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## v1.1.10:
2 |
3 | ### Improvement
4 |
5 | - [COOK-2286]: OHAI cookbook README does not include implementation
6 | example
7 |
8 | ## v1.1.8:
9 |
10 | * [COOK-1918] - Ohai cookbook to distribute plugins fails on windows
11 | * [COOK-2096] - Ohai cookbook sets unix-only default path attribute
12 |
13 | ## v1.1.6:
14 |
15 | * [COOK-2057] - distribution from another cookbok fails if ohai
16 | attributes are loaded after the other cookbook
17 |
18 | ## v1.1.4:
19 |
20 | * [COOK-1128] - readme update, Replace reference to deprecated chef
21 | cookbook with one to chef-client
22 |
23 | ## v1.1.2:
24 |
25 | * [COOK-1424] - prevent plugin_path growth to infinity
26 |
27 | ## v1.1.0:
28 |
29 | * [COOK-1174] - custom_plugins is only conditionally available
30 | * [COOK-1383] - allow plugins from other cookbooks
31 |
32 | ## v1.0.2
33 |
34 | - [COOK-463] ohai cookbook default recipe should only reload plugins if there were updates
35 |
--------------------------------------------------------------------------------
/cookbooks/eos/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # CHANGELOG
2 |
3 | ## 0.1.4, 2013-11-26
4 | * updated providers to support new attributes in Devops Extension
5 |
6 | ## 0.1.3, 2013-09-04
7 | * updated provider to use the Devops Extension for EOS
8 |
9 | ## 0.1.2, 2013-07-19
10 | * fixed bug found with portchannel data bag entries
11 | * added some additional debug messages to aid with troubleshooting
12 | * change ohai plugin attributes from default to normal for plugin path
13 | * fixed minor issue with get_config to find the right attribute
14 |
15 | ## 0.1.1, 2013-07-02
16 | * fixed bug found in edit_portchannel in lag provider
17 | * added initial support for ohai
18 | * added ohai plugin (eos/version)
19 |
20 | ## 0.1.0, 2013-07-01
21 | * Initial release of eos cookbook
22 | * Initial release of interface (resource/provider/recipe)
23 | * Initial release of vlan (resource/provider/recipe)
24 | * Initial release of switchport (resource/provider/recipe)
25 | * Initial release of portchannel (resource/provider/recipe)
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Chef EOS Cookbooks
2 |
3 | ## Overview
4 | This repository contains cookbooks developed for integrating with Arista Networks EOS operating system. The cookbooks provided here are released freely to the devops community and are supported by the community for managing network resources in EOS. Please see the README file for individual cookbooks for description and usage instructions.
5 |
6 | ## Cookbooks
7 | The cookbooks provided here are summarized below. Please see the README file in each cookbook for any specific notes.
8 |
9 |
10 |
11 | - eos
12 | - The eos cookbook implements recipes and providers specifically for managing Arista EOS based devices
13 |
14 | - netdev_eos
15 | - The netdev_eos_ cookbook implements recipes and providers for use with netdev lightweight resource providers
16 |
17 |
18 |
19 | ## Getting Involved
20 | * irc.freenode.net: #arista
21 |
22 | ## Contributors
23 | * Peter Sprygada, Arista Networks
24 |
25 | ## License
26 | BSD-2, See LICENSE file
27 |
--------------------------------------------------------------------------------
/cookbooks/ohai/attributes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: ohai
3 | # Attribute:: default
4 | #
5 | # Copyright 2010, Opscode, Inc
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | # FHS location would be /var/lib/chef/ohai_plugins or similar.
21 | case node["platform_family"]
22 | when "windows"
23 | default["ohai"]["plugin_path"] = "C:/chef/ohai_plugins"
24 | else
25 | default["ohai"]["plugin_path"] = "/etc/chef/ohai_plugins"
26 | end
27 |
28 | # The list of plugins and their respective file locations
29 | default["ohai"]["plugins"]["ohai"] = "plugins"
30 |
--------------------------------------------------------------------------------
/cookbooks/ohai/CONTRIBUTING:
--------------------------------------------------------------------------------
1 | If you would like to contribute, please open a ticket in JIRA:
2 |
3 | * http://tickets.opscode.com
4 |
5 | Create the ticket in the COOK project and use the cookbook name as the
6 | component.
7 |
8 | For all code contributions, we ask that contributors sign a
9 | contributor license agreement (CLA). Instructions may be found here:
10 |
11 | * http://wiki.opscode.com/display/chef/How+to+Contribute
12 |
13 | When contributing changes to individual cookbooks, please do not
14 | modify the version number in the metadata.rb. Also please do not
15 | update the CHANGELOG.md for a new version. Not all changes to a
16 | cookbook may be merged and released in the same versions. Opscode will
17 | handle the version updates during the release process. You are welcome
18 | to correct typos or otherwise make updates to documentation in the
19 | README.
20 |
21 | If a contribution adds new platforms or platform versions, indicate
22 | such in the body of the commit message(s), and update the relevant
23 | COOK ticket. When writing commit messages, it is helpful for others if
24 | you indicate the COOK ticket. For example:
25 |
26 | git commit -m '[COOK-1041] Updated pool resource to correctly delete.'
27 |
28 | In the ticket itself, it is also helpful if you include log output of
29 | a successful Chef run, but this is not absolutely required.
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013, Arista Networks
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | Redistributions in binary form must reproduce the above copyright notice, this
11 | list of conditions and the following disclaimer in the documentation and/or
12 | other materials provided with the distribution.
13 |
14 | Neither the name of the {organization} nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 |
30 |
--------------------------------------------------------------------------------
/cookbooks/eos/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013, Arista Networks
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | Redistributions in binary form must reproduce the above copyright notice, this
11 | list of conditions and the following disclaimer in the documentation and/or
12 | other materials provided with the distribution.
13 |
14 | Neither the name of the {organization} nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 |
30 |
--------------------------------------------------------------------------------
/cookbooks/eos/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : recipes/default.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 |
34 | ohai "load_eos" do
35 | action :reload
36 | plugin "eos"
37 | end
38 |
--------------------------------------------------------------------------------
/cookbooks/ohai/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: ohai
3 | # Recipe:: default
4 | #
5 | # Copyright 2011, Opscode, Inc
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | unless Ohai::Config[:plugin_path].include?(node['ohai']['plugin_path'])
21 | Ohai::Config[:plugin_path] << node['ohai']['plugin_path']
22 | end
23 | Chef::Log.info("ohai plugins will be at: #{node['ohai']['plugin_path']}")
24 |
25 | # This is done during the compile phase so new plugins can be used in
26 | # resources later in the run.
27 | reload_ohai = false
28 | node['ohai']['plugins'].each_pair do |source_cookbook, path|
29 |
30 | rd = remote_directory node['ohai']['plugin_path'] do
31 | cookbook source_cookbook
32 | source path
33 | mode '0755' unless platform_family?('windows')
34 | recursive true
35 | purge false
36 | action :nothing
37 | end
38 |
39 | rd.run_action(:create)
40 | reload_ohai ||= rd.updated?
41 |
42 | end
43 |
44 | resource = ohai 'custom_plugins' do
45 | action :nothing
46 | end
47 |
48 | # only reload ohai if new plugins were dropped off OR
49 | # node['ohai']['plugin_path'] does not exists in client.rb
50 | if reload_ohai ||
51 | !(::IO.read(Chef::Config[:config_file]) =~ /Ohai::Config\[:plugin_path\]\s*<<\s*["']#{node['ohai']['plugin_path']}["']/)
52 |
53 | resource.run_action(:reload)
54 | end
55 |
--------------------------------------------------------------------------------
/cookbooks/eos/README.md:
--------------------------------------------------------------------------------
1 | # Arista EOS Cookbook
2 |
3 | ## Overview
4 | The eos cookbook provides a set of recipes, resources and providers for managing network resources on Arista EOS devices. The recipes in this cookbook make use of data bags to provide node specific configuration.
5 |
6 | In order to 'attach' a data bag configuration to a node, attributes are used to uniquely identify the node's data bag. The selector will first look for a data bag with the name found in eos/config/databag. The default data bag name is eos_config. In the data bag, you can specify how to unique represent the nodes specific data bag item. The eos/config/identifier attribute will specify the value to use. This value can be one of hostname, macaddress or serialnumber. The default value is hostname.
7 |
8 | If you wish to supply your node specific configuration via an alternative mechanism, you can modify eos/config/provider to other and override the get_config method. This will allow you to return your own hash with configuration values.
9 |
10 | ## Recipes
11 | Below is a list of the cookbooks provided with a quick summary of each. Please see the README for each cookbook for any notes specific to usage.
12 |
13 |
14 | - interface
15 | - This cookbook provides management of physical interfaces in EOS
16 |
17 | - switchport
18 | - This cookbook provides the management of switchport resources in EOS
19 |
20 | - portchannel
21 | - This cookbook provides management (create, delete) of port-channel interfaces in EOS. _Note: this recipe only works with EOS 4.10_
22 |
23 | - vlan
24 | - This cookbook provides management of vlan resources in EOS
25 |
26 |
27 | ## Dependencies
28 | * Chef 10 or later
29 | * Arista EOS 4.12 or later
30 | * Devops Extension for EOS
31 |
32 | ## Contributors
33 | * Peter Sprygada, Arista Networks
34 |
35 | ## License
36 | BSD-3, See LICENSE file
--------------------------------------------------------------------------------
/cookbooks/eos/resources/vlan.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : resources/vlan.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 | actions :manage, :remove
34 | default_action :manage
35 |
36 | attribute :name, :kind_of => String, :name_attribute => true
37 | attribute :vlan_id, :kind_of => String, :required => true
38 | attribute :state, :kind_of => String, :equal_to => ['present', 'absent']
39 |
40 | attr_accessor :exists
--------------------------------------------------------------------------------
/cookbooks/eos/attributes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : attributes/default.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 | default[:eos][:config][:identifier] = "hostname"
34 | default[:eos][:config][:databag] = "eos_config"
35 | default[:eos][:config][:provider] = "databag"
36 |
37 | normal[:ohai][:plugin_path] = "/persist/local/chef/ohai_plugins"
38 | normal[:ohai][:plugins][:eos] = "ohai"
39 |
--------------------------------------------------------------------------------
/cookbooks/eos/resources/interface.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : resources/interface.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 | actions :manage, :default
34 | default_action :manage
35 |
36 | attribute :name, :kind_of => String, :name_attribute => true, :required => true
37 | attribute :admin, :kind_of => String, :equal_to => ['enable', 'disable']
38 | attribute :description, :kind_of => String
39 | attribute :state, :kind_of => String, :equal_to => ['default']
40 |
41 | attr_accessor :exists
42 |
--------------------------------------------------------------------------------
/cookbooks/eos/resources/switchport.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : resources/switchport.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 |
34 | actions :manage, :remove
35 | default_action :manage
36 |
37 | attribute :name, :kind_of => String, :name_attribute => true, :required => true
38 | attribute :untagged_vlan, :kind_of => String
39 | attribute :tagged_vlans, :kind_of => Array
40 | attribute :vlan_tagging, :kind_of => String, :equal_to => ['enable', 'disable']
41 | attribute :state, :kind_of => String, :equal_to => ['present', 'absent']
42 |
43 | attr_accessor :exists
44 |
--------------------------------------------------------------------------------
/cookbooks/eos/resources/portchannel.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : resources/portchannel.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 | actions :manage, :remove
34 | default_action :create
35 |
36 | attribute :name, :kind_of => String, :name_attribute => true, :required => true
37 | attribute :links, :kind_of => Array
38 | attribute :minimum_links, :kind_of => Integer
39 | attribute :lacp, :kind_of => String, :equal_to => ['disable', 'active', 'passive']
40 | attribute :active, :kind_of => [TrueClass, FalseClass], :default => true
41 |
42 | attr_accessor :exists
--------------------------------------------------------------------------------
/cookbooks/eos/metadata.rb:
--------------------------------------------------------------------------------
1 | name 'eos'
2 | maintainer 'Arista Networks'
3 | maintainer_email 'devops@aristanetworks.com'
4 | license 'BSD-3'
5 | description 'Implements an recipes for managing network resources on EOS devices'
6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7 | version '0.1.4'
8 |
9 | recipe "interface",
10 | "Manages physical interface resources on EOS based devices"
11 |
12 | recipe "vlan",
13 | "Manages vlan resources on EOS based devices"
14 |
15 | recipe "switchport",
16 | "Manages switchport resources on EOS based devices"
17 |
18 | recipe "portchannel",
19 | "Manages lag (port-channel) resources on EOS based devices"
20 |
21 | attribute 'eos/config/identifier',
22 | :display_name => "Identifier",
23 | :description => "The unique node identifier to use to local the data bag item",
24 | :type => "string",
25 | :required => "required",
26 | :receipes => ['eos::interface', 'eos::switchport', 'eos::vlan', 'eos::portchannel'],
27 | :default => "hostname"
28 |
29 | attribute 'eos/config/databag',
30 | :display_name => "Data bag name",
31 | :description => 'The name of the data bag to use for finding settings',
32 | :type => 'string',
33 | :required => 'required',
34 | :receipes => ['eos::interface', 'eos::switchport', 'eos::vlan', 'eos::portchannel'],
35 | :default => 'eos_config'
36 |
37 | attribute 'eos/config/provider',
38 | :display_name => 'Config provider',
39 | :description => 'The name of the provider for the EOS configuration',
40 | :type => 'string',
41 | :required => 'required',
42 | :receipes => ['eos::interface', 'eos::switchport', 'eos::vlan', 'eos::portchannel'],
43 | :default => 'databag'
44 |
45 | attribute 'ohai/plugin_path',
46 | :display_name => 'OHAI Plugin Path',
47 | :description => 'Sets the plugin path for OHAI plugins to persistent storage',
48 | :type => 'string',
49 | :required => 'recommended',
50 | :receipes => ['eos::default'],
51 | :default => '/persist/local/chef/ohai_plugins'
52 |
53 | attribute 'ohai/plugins/eos',
54 | :display_name => 'OAHI EOS Plugin',
55 | :description => 'Loads the custom EOS plugin for OHAI',
56 | :type => 'string',
57 | :required => 'recommended',
58 | :receipes => ['eos::default'],
59 | :default => 'ohai'
60 |
--------------------------------------------------------------------------------
/cookbooks/eos/libraries/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : library/default.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 | require 'yajl'
34 |
35 | def has_changed?(curres, newres)
36 | Chef::Log.debug "Checking: #{curres} is equal to #{newres}"
37 | return curres != newres && !newres.nil?
38 | end
39 |
40 | def run_command(command, jsonify=false)
41 | Chef::Log.info "Running command: #{command}"
42 | command = Mixlib::ShellOut.new(command)
43 | command.run_command()
44 | return jsonify ? to_json(command.stdout) : command.stdout
45 | end
46 |
47 | def to_json(obj)
48 | Chef::Log.debug "JSON output: #{obj}"
49 | parser = Yajl::Parser.new
50 | return parser.parse(obj)
51 | end
52 |
--------------------------------------------------------------------------------
/cookbooks/eos/recipes/vlan.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : recipes/vlan.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 |
34 | config = get_config()
35 | if config.has_key?('vlans')
36 | config['vlans'].each do |name, attribs|
37 | Chef::Log.info "Processing vlan #{name}"
38 |
39 | if attribs['state'] == 'absent'
40 | eos_vlan name do
41 | vlan_id attribs['vlan_id'].to_s
42 | action :remove
43 | end
44 |
45 | else
46 | eos_vlan name do
47 | vlan_id attribs['vlan_id'].to_s
48 | action :manage
49 | end
50 | end
51 |
52 | end
53 | else
54 | Chef::Log.fatal "Could not load vlan configuration"
55 | end
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/cookbooks/eos/recipes/interface.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : recipes/interface.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 |
34 | config = get_config()
35 | if config.has_key?('interfaces')
36 | config['interfaces'].each do |name, attribs|
37 | Chef::Log.info "Processing interface #{name}"
38 |
39 | if attribs['state'] == 'default'
40 | eos_interface name do
41 | action :default
42 | end
43 |
44 | else
45 | eos_interface name do
46 | admin attribs['admin'] if attribs['admin']
47 | description attribs['description'] if attribs['description']
48 | action :manage
49 | end
50 | end
51 |
52 | end
53 | else
54 | Chef::Log.fatal "Could not load interface configuration"
55 | end
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/cookbooks/eos/files/default/ohai/eos.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : files/defaults/eos.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 | require 'yajl'
34 |
35 | provides "eos"
36 | provides "eos/version"
37 |
38 | eos Mash.new unless eos
39 | eos[:version] = Mash.new unless eos[:version]
40 |
41 | parser = Yajl::Parser.new
42 |
43 | begin
44 | cmd = 'devops command show version'
45 | command = Mixlib::ShellOut.new(cmd)
46 | command.run_command()
47 | resp = parser.parse(command.stdout)
48 | if resp['status'] == 200
49 | resp['result'][0].each do | key, value |
50 | eos[:version][key] = value
51 | end
52 | else
53 | Chef::Log.warn "Command returned a status of 404 (Not Found)"
54 | end
55 | rescue => e
56 | Chef::Log.warn "Ohai eos version plugin failed with '#{e}'"
57 | end
58 |
--------------------------------------------------------------------------------
/cookbooks/eos/recipes/portchannel.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : recipes/portchannel.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 |
34 | config = get_config()
35 | if config.has_key?('portchannel')
36 | config['portchannel'].each do |name, attribs|
37 | Chef::Log.info "Processing port-channel #{name}"
38 |
39 | if attribs['state'] == 'absent'
40 | eos_portchannel name do
41 | action :remove
42 | end
43 |
44 | else
45 | eos_portchannel name do
46 | links attribs['links'] if attribs['links']
47 | minimum_links attribs['minimum_links'].to_i if attribs['minimum_links']
48 | lacp attribs['lacp'] if attribs['lacp']
49 | action :manage
50 | end
51 | end
52 |
53 | end
54 | else
55 | Chef::Log.fatal "Could not load port-channel configuration"
56 | end
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/cookbooks/eos/recipes/switchport.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : recipes/switchport.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 |
34 | config = get_config()
35 | if config.has_key?('switchports')
36 | config['switchports'].each do |name, attribs|
37 | Chef::Log.info "Processing switchport #{name}"
38 |
39 | if attribs['state'] == 'absent'
40 | eos_switchport name do
41 | action :remove
42 | end
43 |
44 | else
45 | eos_switchport name do
46 | untagged_vlan attribs['untagged_vlan'] if attribs['untagged_vlan']
47 | tagged_vlans attribs['tagged_vlans'] if attribs['tagged_vlans']
48 | vlan_tagging attribs['vlan_tagging'] if attribs['vlan_tagging']
49 | action :manage
50 | end
51 | end
52 |
53 | end
54 | else
55 | Chef::Log.fatal "Could not load switchport configuration"
56 | end
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/cookbooks/eos/libraries/eos_config.rb:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2013, Arista Networks
2 | # All rights reserved.
3 | #
4 | # Redistribution and use in source and binary forms, with or without modification,
5 | # are permitted provided that the following conditions are met:
6 | #
7 | # Redistributions of source code must retain the above copyright notice, this
8 | # list of conditions and the following disclaimer.
9 | #
10 | # Redistributions in binary form must reproduce the above copyright notice, this
11 | # list of conditions and the following disclaimer in the documentation and/or
12 | # other materials provided with the distribution.
13 | #
14 | # Neither the name of the {organization} nor the names of its
15 | # contributors may be used to endorse or promote products derived from
16 | # this software without specific prior written permission.
17 | #
18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | #
29 | class Chef
30 | class Recipe
31 | def get_config()
32 | config_provider = node[:eos][:config][:provider]
33 | Chef::Log.info "My config provider is #{config_provider}"
34 |
35 | if config_provider == "databag"
36 | databag = node[:eos][:config][:databag]
37 | Chef::Log.info "My data bag is #{databag}"
38 |
39 | identifier = node[:eos][:config][:identifier]
40 | Chef::Log.info "Eos config identifer is #{identifier}"
41 |
42 | case identifier
43 | when "hostname"
44 | identity = node[:hostname]
45 | when "macaddress"
46 | identity = node[:eos][:version][:macaddress]
47 | when "serialnum"
48 | identity = node[:eos][:version][:serialnumber]
49 | when "model"
50 | identity= node[:eos][:version][:model]
51 | end
52 | Chef::Log.info "Eos config identity is #{identity}"
53 |
54 | config = data_bag_item(databag, identity)
55 | return config
56 | elsif config_provider == "other"
57 | return nil
58 | else
59 | Chef::Log.fatal "Unknown or unsupported config provider"
60 | end
61 | end
62 | end
63 | end
--------------------------------------------------------------------------------
/cookbooks/ohai/README.md:
--------------------------------------------------------------------------------
1 | Description
2 | ===========
3 |
4 | Creates a configured plugin path for distributing custom Ohai plugins, and reloads them via Ohai within the context of a Chef Client run during the compile phase (if needed).
5 |
6 | Attributes
7 | ==========
8 |
9 | `node['ohai']['plugin_path']` - location to drop off plugins directory, default is `/etc/chef/ohai_plugins`. This is not FHS-compliant, an FHS location would be something like `/var/lib/ohai/plugins`, or `/var/lib/chef/ohai_plugins` or similar.
10 |
11 | Neither an FHS location or the default value of this attribute are in the default Ohai plugin path. Set the Ohai plugin path with the config setting "`Ohai::Config[:plugin_path]`" in the Chef config file (the `chef-client::config` recipe does this automatically for you!). The attribute is not set to the default plugin path that Ohai ships with because we don't want to risk destroying existing essential plugins for Ohai.
12 |
13 | `node['ohai']['plugins']` - sources of plugins, defaults to the `files/default/plugins` directory of this cookbook. You can add additional cookbooks by adding the name of the cookbook as a key and the path of the files directory as the value. You have to make sure that you don't have any file conflicts between multiple cookbooks. The last one to write wins.
14 |
15 | Usage
16 | =====
17 |
18 | Put the recipe `ohai` at the start of the node's run list to make sure that custom plugins are loaded early on in the Chef run and data is available for later recipes.
19 |
20 | The execution of the custom plugins occurs within the recipe during the compile phase, so you can write new plugins and use the data they return in your Chef recipes.
21 |
22 | For information on how to write custom plugins for Ohai, please see the Chef wiki pages.
23 |
24 | http://wiki.opscode.com/display/chef/Writing+Ohai+Plugins
25 |
26 | *PLEASE NOTE* - This recipe reloads the Ohai plugins a 2nd time during the Chef run if:
27 |
28 | * The "`Ohai::Config[:plugin_path]`" config setting has *NOT* been properly set in the Chef config file
29 | * The "`Ohai::Config[:plugin_path]`" config setting has been properly set in the Chef config file and there are updated plugins dropped off at "`node['ohai']['plugin_path']`".
30 |
31 | Example
32 | =======
33 | For an example implementation, inspect the ohai_plugin.rb
34 | recipe in the nginx community cookbook.
35 |
36 | License and Author
37 | ==================
38 |
39 | Author:: Joshua Timberman ()
40 | Author:: Seth Chisamore ()
41 |
42 | Copyright:: 2010-2011, Opscode, Inc
43 |
44 | Licensed under the Apache License, Version 2.0 (the "License");
45 | you may not use this file except in compliance with the License.
46 | You may obtain a copy of the License at
47 |
48 | http://www.apache.org/licenses/LICENSE-2.0
49 |
50 | Unless required by applicable law or agreed to in writing, software
51 | distributed under the License is distributed on an "AS IS" BASIS,
52 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53 | See the License for the specific language governing permissions and
54 | limitations under the License.
55 |
--------------------------------------------------------------------------------
/cookbooks/eos/providers/interface.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : provider/interface.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 |
34 | def whyrun_supported?
35 | true
36 | end
37 |
38 | action :manage do
39 | converge_by("manage interface #{new_resource.name}") do
40 | params = Array.new()
41 | (params << "--admin" << new_resource.admin) if has_changed?(current_resource.admin, new_resource.admin)
42 | (params << "--description" << %Q{"#{new_resource.description}"}) if has_changed?(current_resource.description, new_resource.description)
43 |
44 | if !params.empty?
45 | execute "devops interface edit" do
46 | Chef::Log.debug "Command: devops interface edit #{new_resource.name} #{params.join(' ')}"
47 | command "devops interface edit #{new_resource.name} #{params.join(' ')}"
48 | end
49 | else
50 | Chef::Log.info "No attributes have changed"
51 | end
52 | end
53 | end
54 |
55 | action :default do
56 | converge_by("remove interface #{new_resource.name}") do
57 | execute "devops interface delete" do
58 | command "devops interface delete #{new_resource.name}"
59 | end
60 | end
61 | end
62 |
63 | def load_current_resource
64 | Chef::Log.info "Loading current resource #{@new_resource.name}"
65 |
66 | resp = run_command("devops interface list", jsonify=true)
67 | if !resp['result'].nil?
68 | interface = resp['result'][@new_resource.name]
69 |
70 | @current_resource = Chef::Resource::EosInterface.new(@new_resource.name)
71 | @current_resource.admin(interface['admin'])
72 | @current_resource.description(interface['description'])
73 | @current_resource.exists = true
74 |
75 | else
76 | Chef::Log.fatal "Unable to load current resource"
77 |
78 | end
79 |
80 | end
81 |
82 |
83 |
--------------------------------------------------------------------------------
/cookbooks/ohai/metadata.json:
--------------------------------------------------------------------------------
1 | {"name":"ohai","description":"Distributes a directory of custom ohai plugins","long_description":"Description\n===========\n\nCreates a configured plugin path for distributing custom Ohai plugins, and reloads them via Ohai within the context of a Chef Client run during the compile phase (if needed).\n\nAttributes\n==========\n\n`node['ohai']['plugin_path']` - location to drop off plugins directory, default is `/etc/chef/ohai_plugins`. This is not FHS-compliant, an FHS location would be something like `/var/lib/ohai/plugins`, or `/var/lib/chef/ohai_plugins` or similar.\n\nNeither an FHS location or the default value of this attribute are in the default Ohai plugin path. Set the Ohai plugin path with the config setting \"`Ohai::Config[:plugin_path]`\" in the Chef config file (the `chef-client::config` recipe does this automatically for you!). The attribute is not set to the default plugin path that Ohai ships with because we don't want to risk destroying existing essential plugins for Ohai.\n\n`node['ohai']['plugins']` - sources of plugins, defaults to the `files/default/plugins` directory of this cookbook. You can add additional cookbooks by adding the name of the cookbook as a key and the path of the files directory as the value. You have to make sure that you don't have any file conflicts between multiple cookbooks. The last one to write wins.\n\nUsage\n=====\n\nPut the recipe `ohai` at the start of the node's run list to make sure that custom plugins are loaded early on in the Chef run and data is available for later recipes.\n\nThe execution of the custom plugins occurs within the recipe during the compile phase, so you can write new plugins and use the data they return in your Chef recipes.\n\nFor information on how to write custom plugins for Ohai, please see the Chef wiki pages.\n\nhttp://wiki.opscode.com/display/chef/Writing+Ohai+Plugins\n\n*PLEASE NOTE* - This recipe reloads the Ohai plugins a 2nd time during the Chef run if:\n\n* The \"`Ohai::Config[:plugin_path]`\" config setting has *NOT* been properly set in the Chef config file\n* The \"`Ohai::Config[:plugin_path]`\" config setting has been properly set in the Chef config file and there are updated plugins dropped off at \"`node['ohai']['plugin_path']`\".\n\nExample\n=======\nFor an example implementation, inspect the ohai_plugin.rb\nrecipe in the nginx community cookbook.\n\nLicense and Author\n==================\n\nAuthor:: Joshua Timberman ()\nAuthor:: Seth Chisamore ()\n\nCopyright:: 2010-2011, Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","maintainer":"Opscode, Inc","maintainer_email":"cookbooks@opscode.com","license":"Apache 2.0","platforms":{},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{"ohai/plugin_path":{"display_name":"Ohai Plugin Path","description":"Distribute plugins to this path.","type":"string","required":"optional","default":"/etc/chef/ohai_plugins","choice":[],"calculated":false,"recipes":[]},"ohai/plugins":{"display_name":"Ohai Plugin Sources","description":"Read plugins from these cookbooks and paths","type":"hash","required":"optional","default":{"ohai":"plugins"},"choice":[],"calculated":false,"recipes":[]}},"groupings":{},"recipes":{"ohai::default":"Distributes a directory of custom ohai plugins"},"version":"1.1.10"}
--------------------------------------------------------------------------------
/cookbooks/eos/providers/vlan.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : provider/vlan.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 |
34 | def whyrun_supported?
35 | true
36 | end
37 |
38 | action :manage do
39 | converge_by("manage will create vlan #{@new_resource.name}") do
40 | if !@current_resource.exists
41 | converge_by("Vlan #{@new_resource.name} will be created") do
42 | create_vlan
43 | end
44 | else
45 | converge_by("manage will edit vlan #{@new_resource.name}") do
46 | edit_vlan
47 | end
48 | end
49 | end
50 | end
51 |
52 | action :remove do
53 | if @current_resource.exists
54 | converge_by("remove vlan #{@current_resource.name}") do
55 | execute "devops vlan delete" do
56 | Chef::Log.debug "Command: devops vlan delete #{new_resource.vlan_id}"
57 | command "devops vlan delete #{new_resource.vlan_id}"
58 | end
59 | end
60 | else
61 | Chef::Log.info("Vlan doesn't exist, nothing to delete")
62 | end
63 | end
64 |
65 | def load_current_resource
66 | Chef::Log.info "Loading current resource #{@new_resource.name}"
67 | @current_resource = Chef::Resource::EosVlan.new(@new_resource.name)
68 | @current_resource.vlan_id(@new_resource.vlan_id)
69 | @current_resource.exists = false
70 |
71 | if resource_exists?
72 | resp = run_command('devops vlan list', jsonify=true)
73 | vlan = resp['result'][@current_resource.vlan_id]
74 | @current_resource.vlan_id(vlan['vlan_id'])
75 | @current_resource.exists = true
76 |
77 | else
78 | Chef::Log.info "Vlan #{@new_resource.name} (#{@new_resource.vlan_id}) doesn't exist"
79 | end
80 |
81 | end
82 |
83 | def resource_exists?
84 | Chef::Log.info("Looking to see if vlan #{@new_resource.name} (#{@new_resource.vlan_id}) exists")
85 | resp = run_command('devops vlan list', jsonify=true)
86 | return resp['result'].has_key?(@new_resource.vlan_id)
87 | end
88 |
89 | def create_vlan
90 | execute "devops vlan create" do
91 | params = []
92 | params << "--name" << new_resource.name
93 | command "devops vlan create #{new_resource.vlan_id} #{params.join(' ')}"
94 | end
95 | end
96 |
97 | def edit_vlan
98 | params = []
99 | (params << "--name" << new_resource.name) if has_changed?(current_resource.name, new_resource.name)
100 | if !params.empty?
101 | execute "devops vlan edit" do
102 | Chef::Log.debug "Command: devops vlan edit #{new_resource.vlan_id} #{params.join(' ')}"
103 | command "devops vlan edit #{new_resource.vlan_id} #{params.join(' ')}"
104 | end
105 | else
106 | Chef::Log.info "No attributes have changed"
107 | end
108 | end
109 |
110 |
111 |
--------------------------------------------------------------------------------
/cookbooks/eos/providers/portchannel.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : provider/portchannel.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 |
34 | def whyrun_supported?
35 | true
36 | end
37 |
38 | action :manage do
39 | converge_by("create lag #{@new_resource.name}") do
40 | if !@current_resource.exists
41 | converge_by("lag #{@new_resource.name} will be created") do
42 | create_lag
43 | end
44 | else
45 | converge_by("edit lag #{@new_resource.name} will be modified") do
46 | edit_lag
47 | end
48 | end
49 | end
50 | end
51 |
52 | action :remove do
53 | if @current_resource.exists
54 | converge_by("remove lag #{@current_resource.name}") do
55 | execute "devops lag delete" do
56 | command "devops lag delete #{new_resource.name}"
57 | end
58 | end
59 | else
60 | Chef::Log.info("Lag #{new_resource.name} doesn't exist, nothing to delete")
61 | end
62 | end
63 |
64 | def load_current_resource
65 | Chef::Log.info "Loading current resource #{@new_resource.name}"
66 | @current_resource = Chef::Resource::EosPortchannel.new(@new_resource.name)
67 | @current_resource.exists = false
68 |
69 | if resource_exists?
70 | resp = run_command('devops lag list', jsonify=true)
71 | lag = resp['result'][@new_resource.name]
72 | @current_resource.links(lag['links'])
73 | @current_resource.minimum_links(lag['minimum_links'])
74 | @current_resource.lacp(lag['lacp'])
75 | @current_resource.exists = true
76 |
77 | else
78 | Chef::Log.info "Lag interface #{@new_resource.name} doesn't exist"
79 | end
80 |
81 | end
82 |
83 | def resource_exists?
84 | Chef::Log.info("Looking to see if lag #{@new_resource.name} exists")
85 | lags = run_command('devops lag list', jsonify=true)
86 | return lags['result'].has_key?(@new_resource.name)
87 | end
88 |
89 |
90 | def create_lag
91 | params = Array.new()
92 | (params << "--links" << new_resource.links.join(',')) if new_resource.links
93 | (params << "--minimum-links" << new_resource.minimum_links) if new_resource.minimum_links
94 | (params << "--lacp" << new_resource.lacp) if new_resource.lacp
95 | if !params.empty?
96 | execute "devops lag create" do
97 | command "devops lag create #{new_resource.name} #{params.join(' ')}"
98 | end
99 | end
100 | end
101 |
102 | def edit_lag
103 | params = Array.new()
104 | (params << "--links" << new_resource.links.join(',')) if has_changed?(current_resource.links, new_resource.links)
105 | (params << "--minimum-links" << new_resource.minimum_links) if has_changed?(current_resource.minimum_links, new_resource.minimum_links)
106 | (params << "--lacp" << new_resource.lacp) if has_changed?(current_resource.lacp, new_resource.lacp)
107 | if !params.empty?
108 | execute "devops lag edit" do
109 | Chef::Log.debug("devops lag edit #{new_resource.name} #{params.join(' ')}")
110 | command "devops lag edit #{new_resource.name} #{params.join(' ')}"
111 | end
112 | end
113 | end
114 |
115 |
116 |
--------------------------------------------------------------------------------
/cookbooks/eos/providers/switchport.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Cookbook : eos
3 | # File : provider/switchport.rb
4 | #
5 | # Copyright (c) 2013, Arista Networks
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without modification,
9 | # are permitted provided that the following conditions are met:
10 | #
11 | # Redistributions of source code must retain the above copyright notice, this
12 | # list of conditions and the following disclaimer.
13 | #
14 | # Redistributions in binary form must reproduce the above copyright notice, this
15 | # list of conditions and the following disclaimer in the documentation and/or
16 | # other materials provided with the distribution.
17 | #
18 | # Neither the name of the {organization} nor the names of its
19 | # contributors may be used to endorse or promote products derived from
20 | # this software without specific prior written permission.
21 | #
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | #
33 |
34 | def whyrun_supported?
35 | true
36 | end
37 |
38 | action :manage do
39 | converge_by("manage will create switchport #{@new_resource.name}") do
40 | if !@current_resource.exists
41 | converge_by("L2interface #{@new_resource.name} will be created") do
42 | create_switchport
43 | end
44 | else
45 | converge_by("manage will modify switchport #{@new_resource.name}") do
46 | edit_switchport
47 | end
48 | end
49 | end
50 | end
51 |
52 | action :remove do
53 | if @current_resource.exists
54 | converge_by("remove l2interface #{@current_resource.name}") do
55 | execute "devops switchport delete" do
56 | Chef::Log.debug "Command: devops switchport delete #{new_resource.name}"
57 | command "devops switchport delete #{new_resource.name}"
58 | end
59 | end
60 | else
61 | Chef::Log.info("L2interface doesn't exist, nothing to delete")
62 | end
63 | end
64 |
65 | def load_current_resource
66 | Chef::Log.info "Loading current resource #{@new_resource.name}"
67 | @current_resource = Chef::Resource::EosSwitchport.new(@new_resource.name)
68 | @current_resource.exists = false
69 |
70 | if resource_exists?
71 | resp = run_command('devops switchport list', jsonify=true)
72 | interface = resp['result'][@new_resource.name]
73 | @current_resource.untagged_vlan(interface['untagged_vlan'])
74 | @current_resource.tagged_vlans(interface['tagged_vlans'])
75 | @current_resource.vlan_tagging(interface['vlan_tagging'])
76 | @current_resource.exists = true
77 |
78 | else
79 | Chef::Log.info "L2 interface #{@new_resource.name} doesn't exist"
80 | end
81 |
82 | end
83 |
84 | def resource_exists?
85 | Chef::Log.info("Looking to see if l2interface #{@new_resource.name} exists")
86 | resp = run_command('devops switchport list', jsonify=true)
87 | return resp['result'].has_key?(@new_resource.name)
88 | end
89 |
90 |
91 | def create_switchport
92 | params = Array.new()
93 | (params << "--untagged-vlan" << new_resource.untagged_vlan) if new_resource.untagged_vlan
94 | (params << "--tagged-vlans" << new_resource.tagged_vlans.join(',')) if new_resource.tagged_vlans
95 | (params << "--vlan-tagging" << new_resource.vlan_tagging) if new_resource.vlan_tagging
96 | if !params.empty?
97 | execute "devops switchport create" do
98 | Chef::Log.debug "Command: devops switchport create #{new_resource.name} #{params.join(' ')}"
99 | command "devops switchport create #{new_resource.name} #{params.join(' ')}"
100 | end
101 | end
102 | end
103 |
104 | def edit_switchport
105 | params = Array.new()
106 | (params << "--untagged-vlan" << new_resource.untagged_vlan) if has_changed?(current_resource.untagged_vlan, new_resource.untagged_vlan)
107 | (params << "--tagged-vlans" << new_resource.tagged_vlans.join(',')) if has_changed?(current_resource.tagged_vlans, new_resource.tagged_vlans)
108 | (params << "--vlan-tagging" << new_resource.vlan_tagging) if has_changed?(current_resource.vlan_tagging, new_resource.vlan_tagging)
109 | if !params.empty?
110 | execute "devops switchport edit" do
111 | Chef::Log.debug "Command: devops switchport edit #{new_resource.name} #{params.join(' ')}"
112 | command "devops switchport edit #{new_resource.name} #{params.join(' ')}"
113 | end
114 | end
115 | end
116 |
117 |
118 |
--------------------------------------------------------------------------------
/cookbooks/eos/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | },
4 | "attributes": {
5 | "eos/config/databag": {
6 | "required": "required",
7 | "type": "string",
8 | "receipes": [
9 | "eos::interface",
10 | "eos::switchport",
11 | "eos::vlan",
12 | "eos::portchannel"
13 | ],
14 | "calculated": false,
15 | "choice": [
16 |
17 | ],
18 | "display_name": "Data bag name",
19 | "default": "eos_config",
20 | "description": "The name of the data bag to use for finding settings",
21 | "recipes": [
22 |
23 | ]
24 | },
25 | "ohai/plugins/eos": {
26 | "required": "recommended",
27 | "type": "string",
28 | "receipes": [
29 | "eos::default"
30 | ],
31 | "calculated": false,
32 | "choice": [
33 |
34 | ],
35 | "display_name": "OAHI EOS Plugin",
36 | "default": "ohai",
37 | "description": "Loads the custom EOS plugin for OHAI",
38 | "recipes": [
39 |
40 | ]
41 | },
42 | "eos/config/provider": {
43 | "required": "required",
44 | "type": "string",
45 | "receipes": [
46 | "eos::interface",
47 | "eos::switchport",
48 | "eos::vlan",
49 | "eos::portchannel"
50 | ],
51 | "calculated": false,
52 | "choice": [
53 |
54 | ],
55 | "display_name": "Config provider",
56 | "default": "databag",
57 | "description": "The name of the provider for the EOS configuration",
58 | "recipes": [
59 |
60 | ]
61 | },
62 | "eos/config/identifier": {
63 | "required": "required",
64 | "type": "string",
65 | "receipes": [
66 | "eos::interface",
67 | "eos::switchport",
68 | "eos::vlan",
69 | "eos::portchannel"
70 | ],
71 | "calculated": false,
72 | "choice": [
73 |
74 | ],
75 | "display_name": "Identifier",
76 | "default": "hostname",
77 | "description": "The unique node identifier to use to local the data bag item",
78 | "recipes": [
79 |
80 | ]
81 | },
82 | "ohai/plugin_path": {
83 | "required": "recommended",
84 | "type": "string",
85 | "receipes": [
86 | "eos::default"
87 | ],
88 | "calculated": false,
89 | "choice": [
90 |
91 | ],
92 | "display_name": "OHAI Plugin Path",
93 | "default": "/persist/local/chef/ohai_plugins",
94 | "description": "Sets the plugin path for OHAI plugins to persistent storage",
95 | "recipes": [
96 |
97 | ]
98 | }
99 | },
100 | "replacing": {
101 | },
102 | "maintainer": "Arista Networks",
103 | "providing": {
104 | },
105 | "groupings": {
106 | },
107 | "suggestions": {
108 | },
109 | "license": "BSD-3",
110 | "name": "eos",
111 | "conflicting": {
112 | },
113 | "long_description": "# Arista EOS Cookbook\n\n## Overview\nThe eos cookbook provides a set of recipes, resources and providers for managing network resources on Arista EOS devices. The recipes in this cookbook make use of data bags to provide node specific configuration. \n\nIn order to 'attach' a data bag configuration to a node, attributes are used to uniquely identify the node's data bag. The selector will first look for a data bag with the name found in eos/config/databag. The default data bag name is eos_config. In the data bag, you can specify how to unique represent the nodes specific data bag item. The eos/config/identifier attribute will specify the value to use. This value can be one of hostname, macaddress or serialnumber. The default value is hostname.\n\nIf you wish to supply your node specific configuration via an alternative mechanism, you can modify eos/config/provider to other and override the get_config method. This will allow you to return your own hash with configuration values.\n\n## Recipes\nBelow is a list of the cookbooks provided with a quick summary of each. Please see the README for each cookbook for any notes specific to usage.\n\n\n- interface
\n- This cookbook provides management of physical interfaces in EOS
\n\n- switchport
\n- This cookbook provides the management of switchport resources in EOS
\n\n- portchannel
\n- This cookbook provides management (create, delete) of port-channel interfaces in EOS. _Note: this recipe only works with EOS 4.10_
\n\n- vlan
\n- This cookbook provides management of vlan resources in EOS
\n
\n\n## Dependencies\n * Chef 10 or later\n * Arista EOS 4.12 or later\n * Devops Extension for EOS\n\n## Contributors\n * Peter Sprygada, Arista Networks\n\n## License\nBSD-3, See LICENSE file",
114 | "version": "0.1.4",
115 | "recommendations": {
116 | },
117 | "maintainer_email": "devops@aristanetworks.com",
118 | "description": "Implements an recipes for managing network resources on EOS devices",
119 | "recipes": {
120 | "switchport": "Manages switchport resources on EOS based devices",
121 | "portchannel": "Manages lag (port-channel) resources on EOS based devices",
122 | "vlan": "Manages vlan resources on EOS based devices",
123 | "interface": "Manages physical interface resources on EOS based devices"
124 | },
125 | "platforms": {
126 | }
127 | }
--------------------------------------------------------------------------------
/cookbooks/ohai/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------