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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +24 -0
- data/LICENSE.txt +202 -0
- data/README.md +87 -0
- data/Rakefile +1 -0
- data/lib/puppet_x/eos/autoload.rb +57 -0
- data/lib/puppet_x/eos/eapi.rb +259 -0
- data/lib/puppet_x/eos/module_base.rb +37 -0
- data/lib/puppet_x/eos/modules/daemon.rb +109 -0
- data/lib/puppet_x/eos/modules/extension.rb +167 -0
- data/lib/puppet_x/eos/modules/interface.rb +180 -0
- data/lib/puppet_x/eos/modules/ipinterface.rb +133 -0
- data/lib/puppet_x/eos/modules/mlag.rb +268 -0
- data/lib/puppet_x/eos/modules/ntp.rb +129 -0
- data/lib/puppet_x/eos/modules/ospf.rb +129 -0
- data/lib/puppet_x/eos/modules/portchannel.rb +277 -0
- data/lib/puppet_x/eos/modules/radius.rb +367 -0
- data/lib/puppet_x/eos/modules/snmp.rb +177 -0
- data/lib/puppet_x/eos/modules/switchport.rb +255 -0
- data/lib/puppet_x/eos/modules/system.rb +138 -0
- data/lib/puppet_x/eos/modules/tacacs.rb +302 -0
- data/lib/puppet_x/eos/modules/vlan.rb +179 -0
- data/lib/puppet_x/eos/modules/vxlan.rb +132 -0
- data/lib/puppet_x/eos/provider.rb +71 -0
- data/lib/puppet_x/eos/version.rb +41 -0
- data/lib/puppet_x/net_dev/eos_api.rb +1011 -0
- data/lib/puppet_x/net_dev/eos_api/common_methods.rb +27 -0
- data/lib/puppet_x/net_dev/eos_api/snmp_methods.rb +647 -0
- data/lib/puppet_x/net_dev/eos_api/version.rb +8 -0
- data/lib/puppet_x_eos_eapi.rb +4 -0
- data/puppet_x_eos_eapi.gemspec +31 -0
- data/spec/fixtures/fixture_all_portchannel_modes.json +8 -0
- data/spec/fixtures/fixture_all_portchannels_detailed.json +15 -0
- data/spec/fixtures/fixture_create_vlan_error.json +17 -0
- data/spec/fixtures/fixture_create_vlan_success.json +12 -0
- data/spec/fixtures/fixture_eapi_conf.yaml +4 -0
- data/spec/fixtures/fixture_enable_configure_vlan_3111_name_foo.json +14 -0
- data/spec/fixtures/fixture_enable_configure_vlan_foo_name_bar.json +19 -0
- data/spec/fixtures/fixture_get_snmp_communities_non_existent_acl.yaml +2 -0
- data/spec/fixtures/fixture_get_snmp_location_westeros.json +5 -0
- data/spec/fixtures/fixture_portchannel_min_links_1.json +8 -0
- data/spec/fixtures/fixture_portchannel_min_links_2.json +8 -0
- data/spec/fixtures/fixture_running_config.yaml +1 -0
- data/spec/fixtures/fixture_running_configuration_radius_configured.yaml +30 -0
- data/spec/fixtures/fixture_running_configuration_radius_default.yaml +29 -0
- data/spec/fixtures/fixture_running_configuration_radius_server_groups.yaml +38 -0
- data/spec/fixtures/fixture_running_configuration_radius_servers.yaml +34 -0
- data/spec/fixtures/fixture_running_configuration_tacacs_configured.yaml +38 -0
- data/spec/fixtures/fixture_running_configuration_tacacs_default.yaml +38 -0
- data/spec/fixtures/fixture_running_configuration_tacacs_groups.yaml +1 -0
- data/spec/fixtures/fixture_running_configuration_tacacs_groups_3.yaml +43 -0
- data/spec/fixtures/fixture_running_configuration_tacacs_servers.yaml +41 -0
- data/spec/fixtures/fixture_s4_show_etherchannel_detailed.json +9 -0
- data/spec/fixtures/fixture_show_flowcontrol_et1.json +5 -0
- data/spec/fixtures/fixture_show_interfaces.json +297 -0
- data/spec/fixtures/fixture_show_interfaces_switchport_format_text.json +9 -0
- data/spec/fixtures/fixture_show_port_channel_summary_2_lags.json +9 -0
- data/spec/fixtures/fixture_show_port_channel_summary_static.json +9 -0
- data/spec/fixtures/fixture_show_snmp_community.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_contact_empty.json +5 -0
- data/spec/fixtures/fixture_show_snmp_contact_name.json +5 -0
- data/spec/fixtures/fixture_show_snmp_disabled.json +5 -0
- data/spec/fixtures/fixture_show_snmp_enabled.json +5 -0
- data/spec/fixtures/fixture_show_snmp_host.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_host_duplicates.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_host_more_duplicates.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_location_empty.json +5 -0
- data/spec/fixtures/fixture_show_snmp_trap.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_user.yaml +2 -0
- data/spec/fixtures/fixture_show_snmp_user_raw_text.yaml +1 -0
- data/spec/fixtures/fixture_show_vlan.json +37 -0
- data/spec/fixtures/fixture_show_vlan_3110.json +18 -0
- data/spec/fixtures/fixture_show_vlan_4000.json +18 -0
- data/spec/fixtures/fixture_snmp_host_opts.yaml +11 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/fixtures.rb +104 -0
- data/spec/unit/puppet_x/eos/eapi_spec.rb +182 -0
- data/spec/unit/puppet_x/eos/module_base_spec.rb +26 -0
- data/spec/unit/puppet_x/eos/modules/daemon_spec.rb +110 -0
- data/spec/unit/puppet_x/eos/modules/extension_spec.rb +197 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/daemon_getall.json +3 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/extension_getall.json +28 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/hostname.json +6 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/interface_getall.json +509 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/ipinterface_getall.json +56 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/mlag_get.json +21 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/mlag_get_interfaces.json +18 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/ntp_get.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/ospf_instance_getall.json +58 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_get.json +54 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_getlacpmode.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_getmembers.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/portchannel_po1.json +7 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/snmp_get.json +14 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/switchport_get.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/switchport_get_et1.json +7 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/switchport_getall_interfaces.json +230 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/system_domain_list.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/system_domain_name.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/system_hostname.json +6 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/system_name_servers.json +5 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/vlan_getall.json +123 -0
- data/spec/unit/puppet_x/eos/modules/fixtures/vxlan_get.json +24 -0
- data/spec/unit/puppet_x/eos/modules/interface_spec.rb +281 -0
- data/spec/unit/puppet_x/eos/modules/ipinterface_spec.rb +143 -0
- data/spec/unit/puppet_x/eos/modules/mlag_spec.rb +349 -0
- data/spec/unit/puppet_x/eos/modules/ntp_spec.rb +136 -0
- data/spec/unit/puppet_x/eos/modules/ospf_spec.rb +143 -0
- data/spec/unit/puppet_x/eos/modules/portchannel_spec.rb +357 -0
- data/spec/unit/puppet_x/eos/modules/radius_spec.rb +509 -0
- data/spec/unit/puppet_x/eos/modules/snmp_spec.rb +202 -0
- data/spec/unit/puppet_x/eos/modules/switchport_get_et1.json +7 -0
- data/spec/unit/puppet_x/eos/modules/switchport_spec.rb +307 -0
- data/spec/unit/puppet_x/eos/modules/system_spec.rb +170 -0
- data/spec/unit/puppet_x/eos/modules/tacacs_spec.rb +448 -0
- data/spec/unit/puppet_x/eos/modules/vlan_spec.rb +244 -0
- data/spec/unit/puppet_x/eos/modules/vxlan_spec.rb +189 -0
- data/spec/unit/puppet_x/eos/provider_spec.rb +35 -0
- data/spec/unit/puppet_x/net_dev/eos_api/common_methods_spec.rb +34 -0
- data/spec/unit/puppet_x/net_dev/eos_api/snmp_methods_spec.rb +842 -0
- data/spec/unit/puppet_x/net_dev/eos_api_spec.rb +1000 -0
- metadata +369 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2014, Arista Networks, Inc.
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
|
6
|
+
# modification, are permitted provided that the following conditions are
|
|
7
|
+
# met:
|
|
8
|
+
#
|
|
9
|
+
# Redistributions of source code must retain the above copyright notice,
|
|
10
|
+
# this list of conditions and the following disclaimer.
|
|
11
|
+
#
|
|
12
|
+
# Redistributions in binary form must reproduce the above copyright
|
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
|
15
|
+
#
|
|
16
|
+
# Neither the name of Arista Networks nor the names of its
|
|
17
|
+
# contributors may be used to endorse or promote products derived from
|
|
18
|
+
# this software without specific prior written permission.
|
|
19
|
+
#
|
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
23
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
|
|
24
|
+
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
27
|
+
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
28
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
29
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
|
30
|
+
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
#
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# PuppetX is the toplevel namespace for working with Arista EOS nodes
|
|
35
|
+
module PuppetX
|
|
36
|
+
##
|
|
37
|
+
# Eos is module namesapce for working with the EOS command API
|
|
38
|
+
module Eos
|
|
39
|
+
##
|
|
40
|
+
# The Snmp class provides a base class instance for working with
|
|
41
|
+
# the global SNMP configuration
|
|
42
|
+
#
|
|
43
|
+
class Snmp
|
|
44
|
+
##
|
|
45
|
+
# Initialize instance of Snmp
|
|
46
|
+
#
|
|
47
|
+
# @param [PuppetX::Eos::Eapi] api An instance of Eapi
|
|
48
|
+
#
|
|
49
|
+
# @return [PuppetX::Eos::Snmp]
|
|
50
|
+
def initialize(api)
|
|
51
|
+
@api = api
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
##
|
|
55
|
+
# Returns the SNMP hash representing global snmp configuration
|
|
56
|
+
#
|
|
57
|
+
# Example
|
|
58
|
+
# {
|
|
59
|
+
# "contact": <String>,
|
|
60
|
+
# "location": <String>,
|
|
61
|
+
# "chassis_id": <String>,
|
|
62
|
+
# "source_interface": <String>
|
|
63
|
+
# }
|
|
64
|
+
#
|
|
65
|
+
# @return [Array<Hash>] returns an Array of Hashes
|
|
66
|
+
def get
|
|
67
|
+
result = @api.enable(['show snmp contact',
|
|
68
|
+
'show snmp location',
|
|
69
|
+
'show snmp chassis',
|
|
70
|
+
'show snmp source-interface'],
|
|
71
|
+
format: 'text')
|
|
72
|
+
|
|
73
|
+
attr_hash = {}
|
|
74
|
+
|
|
75
|
+
(0..3).each do |i|
|
|
76
|
+
m = /(?<=:\s)(.*)$/.match(result[i]['output'])
|
|
77
|
+
case i
|
|
78
|
+
when 0
|
|
79
|
+
attr_hash[:contact] = !m.nil? ? m[0] : ''
|
|
80
|
+
when 1
|
|
81
|
+
attr_hash[:location] = !m.nil? ? m[0] : ''
|
|
82
|
+
when 2
|
|
83
|
+
attr_hash[:chassis_id] = !m.nil? ? m[0] : ''
|
|
84
|
+
when 3
|
|
85
|
+
attr_hash[:source_interface] = !m.nil? ? m[0] : ''
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
attr_hash
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
##
|
|
92
|
+
# Configures the snmp contact
|
|
93
|
+
#
|
|
94
|
+
# @param [Hash] opts The configuration parameters for snmp
|
|
95
|
+
# @option opts [string] :value The value to set the contact to
|
|
96
|
+
# @option opts [Boolean] :default The value should be set to default
|
|
97
|
+
#
|
|
98
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
99
|
+
def set_contact(opts = {})
|
|
100
|
+
value = opts[:value] || false
|
|
101
|
+
default = opts[:default] || false
|
|
102
|
+
|
|
103
|
+
case default
|
|
104
|
+
when true
|
|
105
|
+
cmds = 'default snmp contact'
|
|
106
|
+
when false
|
|
107
|
+
cmds = (value ? "snmp contact #{value}" : 'no snmp contact')
|
|
108
|
+
end
|
|
109
|
+
@api.config(cmds) == [{}]
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
##
|
|
113
|
+
# Configures the snmp location
|
|
114
|
+
#
|
|
115
|
+
# @param [Hash] opts The configuration parameters for snmp
|
|
116
|
+
# @option opts [string] :value The value to set the location to
|
|
117
|
+
# @option opts [Boolean] :default The value should be set to default
|
|
118
|
+
#
|
|
119
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
120
|
+
def set_location(opts = {})
|
|
121
|
+
value = opts[:value] || false
|
|
122
|
+
default = opts[:default] || false
|
|
123
|
+
|
|
124
|
+
case default
|
|
125
|
+
when true
|
|
126
|
+
cmds = 'default snmp location'
|
|
127
|
+
when false
|
|
128
|
+
cmds = (value ? "snmp location #{value}" : 'no snmp location')
|
|
129
|
+
end
|
|
130
|
+
@api.config(cmds) == [{}]
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
##
|
|
134
|
+
# Configures the snmp chassis-id
|
|
135
|
+
#
|
|
136
|
+
# @param [Hash] opts The configuration parameters for snmp
|
|
137
|
+
# @option opts [string] :value The value to set the chassis-id to
|
|
138
|
+
# @option opts [Boolean] :default The value should be set to default
|
|
139
|
+
#
|
|
140
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
141
|
+
def set_chassis_id(opts = {})
|
|
142
|
+
value = opts[:value] || false
|
|
143
|
+
default = opts[:default] || false
|
|
144
|
+
|
|
145
|
+
case default
|
|
146
|
+
when true
|
|
147
|
+
cmds = 'default snmp chassis'
|
|
148
|
+
when false
|
|
149
|
+
cmds = (value ? "snmp chassis #{value}" : 'no snmp chassis')
|
|
150
|
+
end
|
|
151
|
+
@api.config(cmds) == [{}]
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
##
|
|
155
|
+
# Configures the snmp source-interface
|
|
156
|
+
#
|
|
157
|
+
# @param [Hash] opts The configuration parameters for snmp
|
|
158
|
+
# @option opts [string] :value The value to set the source-interface to
|
|
159
|
+
# @option opts [Boolean] :default The value should be set to default
|
|
160
|
+
#
|
|
161
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
162
|
+
def set_source_interface(opts = {})
|
|
163
|
+
value = opts[:value] || false
|
|
164
|
+
default = opts[:default] || false
|
|
165
|
+
|
|
166
|
+
case default
|
|
167
|
+
when true
|
|
168
|
+
cmds = 'default snmp source-interface'
|
|
169
|
+
when false
|
|
170
|
+
cmds = (value ? "snmp source-interface #{value}" : \
|
|
171
|
+
'no snmp source-interface')
|
|
172
|
+
end
|
|
173
|
+
@api.config(cmds) == [{}]
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2014, Arista Networks, Inc.
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
|
6
|
+
# modification, are permitted provided that the following conditions are
|
|
7
|
+
# met:
|
|
8
|
+
#
|
|
9
|
+
# Redistributions of source code must retain the above copyright notice,
|
|
10
|
+
# this list of conditions and the following disclaimer.
|
|
11
|
+
#
|
|
12
|
+
# Redistributions in binary form must reproduce the above copyright
|
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
|
15
|
+
#
|
|
16
|
+
# Neither the name of Arista Networks nor the names of its
|
|
17
|
+
# contributors may be used to endorse or promote products derived from
|
|
18
|
+
# this software without specific prior written permission.
|
|
19
|
+
#
|
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
23
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
|
|
24
|
+
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
27
|
+
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
28
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
29
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
|
30
|
+
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
#
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# PuppetX is the toplevel namespace for working with Arista EOS nodes
|
|
35
|
+
module PuppetX
|
|
36
|
+
##
|
|
37
|
+
# Eos is module namesapce for working with the EOS command API
|
|
38
|
+
module Eos
|
|
39
|
+
##
|
|
40
|
+
# The Switchport class provides a base class instance for working with
|
|
41
|
+
# logical layer-2 interfaces.
|
|
42
|
+
#
|
|
43
|
+
class Switchport
|
|
44
|
+
##
|
|
45
|
+
# Initialize instance of Switchport
|
|
46
|
+
#
|
|
47
|
+
# @param [PuppetX::Eos::Eapi] api An instance of Eapi
|
|
48
|
+
#
|
|
49
|
+
# @return [PuppetX::Eos::Switchport]
|
|
50
|
+
def initialize(api)
|
|
51
|
+
@api = api
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
##
|
|
55
|
+
# Retrieves the properies for a logical switchport from the
|
|
56
|
+
# running-config using eAPI
|
|
57
|
+
#
|
|
58
|
+
# Example
|
|
59
|
+
# {
|
|
60
|
+
# "name": <String>,
|
|
61
|
+
# "mode": [access, trunk],
|
|
62
|
+
# "trunk_allowed_vlans": [],
|
|
63
|
+
# "trunk_native_vlan": <Integer>,
|
|
64
|
+
# "access_vlan": <Integer>
|
|
65
|
+
# }
|
|
66
|
+
#
|
|
67
|
+
# @param [String] name The full name of the interface to get. The
|
|
68
|
+
# interface name must be the full interface (ie Ethernet, not Et)
|
|
69
|
+
#
|
|
70
|
+
# @return [Hash] a hash that includes the switchport properties
|
|
71
|
+
def get(name)
|
|
72
|
+
result = @api.enable("show interfaces #{name} switchport",
|
|
73
|
+
format: 'text')
|
|
74
|
+
output = result.first['output']
|
|
75
|
+
attr_hash = { name: name }
|
|
76
|
+
attr_hash[:mode] = mode_to_value output
|
|
77
|
+
attr_hash[:trunk_allowed_vlans] = trunk_vlans_to_value output
|
|
78
|
+
attr_hash[:trunk_native_vlan] = trunk_native_to_value output
|
|
79
|
+
attr_hash[:access_vlan] = access_vlan_to_value output
|
|
80
|
+
attr_hash
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
##
|
|
84
|
+
# Retrieves all switchport interfaces from the running-config
|
|
85
|
+
#
|
|
86
|
+
# @return [Array] an array of switchport hashes
|
|
87
|
+
def getall
|
|
88
|
+
result = @api.enable('show interfaces')
|
|
89
|
+
switchports = []
|
|
90
|
+
result.first['interfaces'].map do |name, attrs|
|
|
91
|
+
switchports << get(name) if attrs['forwardingModel'] == 'bridged'
|
|
92
|
+
end
|
|
93
|
+
switchports
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
##
|
|
97
|
+
# Creates a new logical switchport interface in EOS
|
|
98
|
+
#
|
|
99
|
+
# @param [String] name The name of the logical interface
|
|
100
|
+
#
|
|
101
|
+
# @return [Boolean] True if it succeeds otherwise False
|
|
102
|
+
def create(name)
|
|
103
|
+
@api.config(["interface #{name}", 'no ip address',
|
|
104
|
+
'switchport']) == [{}, {}, {}]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
##
|
|
108
|
+
# Deletes a logical switchport interface from the running-config
|
|
109
|
+
#
|
|
110
|
+
# @param [String] name The name of the logical interface
|
|
111
|
+
#
|
|
112
|
+
# @return [Boolean] True if it succeeds otherwise False
|
|
113
|
+
def delete(name)
|
|
114
|
+
@api.config(["interface #{name}", 'no switchport']) == [{}, {}]
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
##
|
|
118
|
+
# Defaults a logical switchport interface in the running-config
|
|
119
|
+
#
|
|
120
|
+
# @param [String] name The name of the logical interface
|
|
121
|
+
#
|
|
122
|
+
# @return [Boolean] True if it succeeds otherwise False
|
|
123
|
+
def default(name)
|
|
124
|
+
@api.config(["interface #{name}",
|
|
125
|
+
'default switchport']) == [{}, {}]
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
##
|
|
129
|
+
# Configures the switchport mode for the specified interafce. Valid
|
|
130
|
+
# modes are access (default) or trunk
|
|
131
|
+
#
|
|
132
|
+
# @param [String] name The name of the interface to configure
|
|
133
|
+
# @param [Hash] opts The configuration parameters for the interface
|
|
134
|
+
# @option opts [string] :value The value to set the mode to
|
|
135
|
+
# @option opts [Boolean] :default The value should be set to default
|
|
136
|
+
#
|
|
137
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
138
|
+
def set_mode(name, opts = {})
|
|
139
|
+
value = opts[:value]
|
|
140
|
+
default = opts[:default] || false
|
|
141
|
+
|
|
142
|
+
cmds = ["interface #{name}"]
|
|
143
|
+
case default
|
|
144
|
+
when true
|
|
145
|
+
cmds << 'default switchport mode'
|
|
146
|
+
when false
|
|
147
|
+
cmds << (value.nil? ? 'no switchport mode' : \
|
|
148
|
+
"switchport mode #{value}")
|
|
149
|
+
end
|
|
150
|
+
@api.config(cmds) == [{}, {}]
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
##
|
|
154
|
+
# Configures the trunk port allowed vlans for the specified interface.
|
|
155
|
+
# This value is only valid if the switchport mode is configure as
|
|
156
|
+
# trunk.
|
|
157
|
+
#
|
|
158
|
+
# @param [String] name The name of the interface to configure
|
|
159
|
+
# @param [Hash] opts The configuration parameters for the interface
|
|
160
|
+
# @option opts [string] :value The list of vlans to allow
|
|
161
|
+
# @option opts [Boolean] :default The value should be set to default
|
|
162
|
+
#
|
|
163
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
164
|
+
def set_trunk_allowed_vlans(name, opts = {})
|
|
165
|
+
value = opts[:value]
|
|
166
|
+
default = opts[:default] || false
|
|
167
|
+
|
|
168
|
+
cmds = ["interface #{name}"]
|
|
169
|
+
case default
|
|
170
|
+
when true
|
|
171
|
+
cmds << 'default switchport trunk allowed vlan'
|
|
172
|
+
when false
|
|
173
|
+
cmds << (value.nil? ? 'no switchport trunk allowed vlan' : \
|
|
174
|
+
"switchport trunk allowed vlan #{value}")
|
|
175
|
+
end
|
|
176
|
+
@api.config(cmds) == [{}, {}]
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
##
|
|
180
|
+
# Configures the trunk port native vlan for the specified interface.
|
|
181
|
+
# This value is only valid if the switchport mode is configure as
|
|
182
|
+
# trunk.
|
|
183
|
+
#
|
|
184
|
+
# @param [String] name The name of the interface to configure
|
|
185
|
+
# @param [Hash] opts The configuration parameters for the interface
|
|
186
|
+
# @option opts [string] :value The value of the trunk native vlan
|
|
187
|
+
# @option opts [Boolean] :default The value should be set to default
|
|
188
|
+
#
|
|
189
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
190
|
+
def set_trunk_native_vlan(name, opts = {})
|
|
191
|
+
value = opts[:value]
|
|
192
|
+
default = opts[:default] || false
|
|
193
|
+
|
|
194
|
+
cmds = ["interface #{name}"]
|
|
195
|
+
case default
|
|
196
|
+
when true
|
|
197
|
+
cmds << 'default switchport trunk native vlan'
|
|
198
|
+
when false
|
|
199
|
+
cmds << (value.nil? ? 'no switchport trunk native vlan' : \
|
|
200
|
+
"switchport trunk native vlan #{value}")
|
|
201
|
+
end
|
|
202
|
+
@api.config(cmds) == [{}, {}]
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
##
|
|
206
|
+
# Configures the access port vlan for the specified interface.
|
|
207
|
+
# This value is only valid if the switchport mode is configure
|
|
208
|
+
# in access mode.
|
|
209
|
+
#
|
|
210
|
+
# @param [String] name The name of the interface to configure
|
|
211
|
+
# @param [Hash] opts The configuration parameters for the interface
|
|
212
|
+
# @option opts [string] :value The value of the access vlan
|
|
213
|
+
# @option opts [Boolean] :default The value should be set to default
|
|
214
|
+
#
|
|
215
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
216
|
+
def set_access_vlan(name, opts = {})
|
|
217
|
+
value = opts[:value]
|
|
218
|
+
default = opts[:default] || false
|
|
219
|
+
|
|
220
|
+
cmds = ["interface #{name}"]
|
|
221
|
+
case default
|
|
222
|
+
when true
|
|
223
|
+
cmds << 'default switchport access vlan'
|
|
224
|
+
when false
|
|
225
|
+
cmds << (value.nil? ? 'no switchport access vlan' : \
|
|
226
|
+
"switchport access vlan #{value}")
|
|
227
|
+
end
|
|
228
|
+
@api.config(cmds) == [{}, {}]
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
private
|
|
232
|
+
|
|
233
|
+
def mode_to_value(config)
|
|
234
|
+
m = /(?<=Operational Mode:\s)(?<mode>[[:alnum:]|\s]+)\n/.match(config)
|
|
235
|
+
m['mode'] == 'static access' ? 'access' : 'trunk'
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def trunk_vlans_to_value(config)
|
|
239
|
+
m = /(?<=Trunking VLANs Enabled:\s)(?<vlans>[[[:alnum:]]+|ALL])/
|
|
240
|
+
.match(config)
|
|
241
|
+
return m['vlans'] unless m.nil?
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def trunk_native_to_value(config)
|
|
245
|
+
m = /(?<=Trunking Native Mode VLAN:\s)(?<trunk_vlan>\d+)/.match(config)
|
|
246
|
+
return m['trunk_vlan'] unless m.nil?
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def access_vlan_to_value(config)
|
|
250
|
+
m = /(?<=Access Mode VLAN:\s)(?<access_vlan>\d+)/.match(config)
|
|
251
|
+
return m['access_vlan'] unless m.nil?
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2014, Arista Networks, Inc.
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
|
6
|
+
# modification, are permitted provided that the following conditions are
|
|
7
|
+
# met:
|
|
8
|
+
#
|
|
9
|
+
# Redistributions of source code must retain the above copyright notice,
|
|
10
|
+
# this list of conditions and the following disclaimer.
|
|
11
|
+
#
|
|
12
|
+
# Redistributions in binary form must reproduce the above copyright
|
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
|
15
|
+
#
|
|
16
|
+
# Neither the name of Arista Networks nor the names of its
|
|
17
|
+
# contributors may be used to endorse or promote products derived from
|
|
18
|
+
# this software without specific prior written permission.
|
|
19
|
+
#
|
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
23
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
|
|
24
|
+
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
27
|
+
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
28
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
29
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
|
30
|
+
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
#
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# PuppetX is the toplevel namespace for working with Arista EOS nodes
|
|
35
|
+
module PuppetX
|
|
36
|
+
##
|
|
37
|
+
# Eos is module namesapce for working with the EOS command API
|
|
38
|
+
module Eos
|
|
39
|
+
##
|
|
40
|
+
# The System class provides management of system level functions
|
|
41
|
+
#
|
|
42
|
+
class System
|
|
43
|
+
##
|
|
44
|
+
# Initializes a new instance of System.
|
|
45
|
+
#
|
|
46
|
+
# @param [PuppetX::Eos::Eapi] api An instance of Eapi
|
|
47
|
+
#
|
|
48
|
+
# @return [PuppetX::Eos::System] instance
|
|
49
|
+
def initialize(api)
|
|
50
|
+
@api = api
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
##
|
|
54
|
+
# Returns the configured system hostname from the running-config
|
|
55
|
+
#
|
|
56
|
+
# @return [String] the configured system hostname
|
|
57
|
+
def get_hostname
|
|
58
|
+
result = @api.enable('show hostname')
|
|
59
|
+
result.first['hostname'].gsub("\n", '')
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
##
|
|
63
|
+
# Returns the configured domain-name from the running-config
|
|
64
|
+
#
|
|
65
|
+
# @return [String] the configured domain-name
|
|
66
|
+
def get_domain_name
|
|
67
|
+
result = @api.enable('show ip domain-name', 'text')
|
|
68
|
+
result.first['output'].gsub("\n", '')
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
##
|
|
72
|
+
# Returns the configure domain-list from the running-config. If no
|
|
73
|
+
# domain-list has been created, then an empty array is returned
|
|
74
|
+
#
|
|
75
|
+
# @return [Array] the list of configured domain names
|
|
76
|
+
def get_domain_list
|
|
77
|
+
result = @api.enable('show running-config section ip\sdomain-list',
|
|
78
|
+
'text')
|
|
79
|
+
result.first['output'].scan(/(?<=list\s).*$/)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
##
|
|
83
|
+
# Returns the list of configured name-servers from the running-config
|
|
84
|
+
#
|
|
85
|
+
# @return [Array] the list of configured name servers
|
|
86
|
+
def get_name_servers
|
|
87
|
+
result = @api.enable('show ip name-server', 'text')
|
|
88
|
+
result.first['output'].split("\n")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
##
|
|
92
|
+
# Configures the system hostname
|
|
93
|
+
#
|
|
94
|
+
# @param [String] name The name to configure the hostname to
|
|
95
|
+
#
|
|
96
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
97
|
+
def set_hostname(name)
|
|
98
|
+
@api.config("hostname #{name}") == [{}]
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
##
|
|
102
|
+
# Configures the system domain-name
|
|
103
|
+
#
|
|
104
|
+
# @param [String] name The name to configure the domain-name to
|
|
105
|
+
#
|
|
106
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
107
|
+
def set_domain_name(name)
|
|
108
|
+
@api.config("ip domain-name #{name}")
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
##
|
|
112
|
+
# Configures the system name servers
|
|
113
|
+
#
|
|
114
|
+
# @param [Array] list of name-server values
|
|
115
|
+
#
|
|
116
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
117
|
+
def set_name_servers(servers)
|
|
118
|
+
servers.each do |srv|
|
|
119
|
+
resp = @api.config("ip name-server #{srv}")
|
|
120
|
+
return false unless resp == [{}]
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
##
|
|
125
|
+
# Configures the list of domain suffixes to search
|
|
126
|
+
#
|
|
127
|
+
# @param[Array] list of domain-name values
|
|
128
|
+
#
|
|
129
|
+
# @return [Boolean] True if the commands succeed otherwise False
|
|
130
|
+
def set_domain_list(domains)
|
|
131
|
+
domains.each do |name|
|
|
132
|
+
resp = @api.config("ip domain-list #{name}")
|
|
133
|
+
return false unless resp == [{}]
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|