cisco_node_utils 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +81 -1
- data/.travis.yml +9 -0
- data/CHANGELOG.md +72 -6
- data/CONTRIBUTING.md +32 -7
- data/README.md +70 -7
- data/Rakefile +17 -0
- data/bin/check_metric_limits.rb +109 -0
- data/bin/git/hooks/commit-msg/enforce_style +81 -0
- data/bin/git/hooks/hook_lib +108 -0
- data/bin/git/hooks/hooks-wrapper +38 -0
- data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
- data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
- data/bin/git/hooks/post-flow-release-start/update-version +19 -0
- data/bin/git/hooks/post-merge/update-hooks +6 -0
- data/bin/git/hooks/post-rewrite/update-hooks +6 -0
- data/bin/git/hooks/pre-commit/rubocop +20 -0
- data/bin/git/hooks/pre-commit/validate-diffs +31 -0
- data/bin/git/hooks/pre-push/check-changelog +24 -0
- data/bin/git/hooks/pre-push/rubocop +7 -0
- data/bin/git/update-hooks +65 -0
- data/cisco_node_utils.gemspec +9 -3
- data/docs/README-develop-best-practices.md +404 -0
- data/docs/README-develop-node-utils-APIs.md +215 -365
- data/docs/README-maintainers.md +33 -3
- data/docs/template-router.rb +89 -91
- data/docs/template-test_router.rb +52 -55
- data/lib/.rubocop.yml +18 -0
- data/lib/cisco_node_utils.rb +2 -19
- data/lib/cisco_node_utils/README_YAML.md +1 -9
- data/lib/cisco_node_utils/bgp.rb +664 -0
- data/lib/cisco_node_utils/bgp_af.rb +530 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
- data/lib/cisco_node_utils/command_reference.rb +72 -74
- data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
- data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
- data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
- data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
- data/lib/cisco_node_utils/configparser_lib.rb +152 -147
- data/lib/cisco_node_utils/dns_domain.rb +79 -0
- data/lib/cisco_node_utils/domain_name.rb +71 -0
- data/lib/cisco_node_utils/interface.rb +167 -161
- data/lib/cisco_node_utils/interface_ospf.rb +78 -81
- data/lib/cisco_node_utils/name_server.rb +64 -0
- data/lib/cisco_node_utils/node.rb +154 -198
- data/lib/cisco_node_utils/node_util.rb +61 -0
- data/lib/cisco_node_utils/ntp_config.rb +65 -0
- data/lib/cisco_node_utils/ntp_server.rb +76 -0
- data/lib/cisco_node_utils/platform.rb +174 -165
- data/lib/cisco_node_utils/radius_global.rb +146 -0
- data/lib/cisco_node_utils/radius_server.rb +295 -0
- data/lib/cisco_node_utils/router_ospf.rb +59 -63
- data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
- data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
- data/lib/cisco_node_utils/snmpgroup.rb +22 -23
- data/lib/cisco_node_utils/snmpserver.rb +99 -103
- data/lib/cisco_node_utils/snmpuser.rb +294 -274
- data/lib/cisco_node_utils/syslog_server.rb +92 -0
- data/lib/cisco_node_utils/syslog_settings.rb +69 -0
- data/lib/cisco_node_utils/tacacs_server.rb +137 -133
- data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
- data/lib/cisco_node_utils/version.rb +2 -1
- data/lib/cisco_node_utils/vlan.rb +28 -31
- data/lib/cisco_node_utils/vrf.rb +80 -0
- data/lib/cisco_node_utils/vtp.rb +100 -97
- data/lib/cisco_node_utils/yum.rb +15 -17
- data/tests/.rubocop.yml +15 -0
- data/tests/basetest.rb +81 -36
- data/tests/ciscotest.rb +38 -78
- data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
- data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
- data/tests/test_bgp_af.rb +920 -0
- data/tests/test_bgp_neighbor.rb +403 -0
- data/tests/test_bgp_neighbor_af.rb +589 -0
- data/tests/test_command_config.rb +65 -62
- data/tests/test_command_reference.rb +31 -45
- data/tests/test_dns_domain.rb +113 -0
- data/tests/test_domain_name.rb +86 -0
- data/tests/test_interface.rb +424 -548
- data/tests/test_interface_ospf.rb +248 -432
- data/tests/test_interface_svi.rb +56 -79
- data/tests/test_interface_switchport.rb +196 -272
- data/tests/test_name_server.rb +85 -0
- data/tests/test_node.rb +7 -6
- data/tests/test_node_ext.rb +133 -186
- data/tests/test_ntp_config.rb +49 -0
- data/tests/test_ntp_server.rb +74 -0
- data/tests/test_platform.rb +58 -37
- data/tests/test_radius_global.rb +78 -0
- data/tests/test_radius_server.rb +185 -0
- data/tests/test_router_bgp.rb +838 -0
- data/tests/test_router_ospf.rb +49 -80
- data/tests/test_router_ospf_vrf.rb +274 -392
- data/tests/test_snmpcommunity.rb +128 -172
- data/tests/test_snmpgroup.rb +12 -14
- data/tests/test_snmpserver.rb +160 -189
- data/tests/test_snmpuser.rb +568 -717
- data/tests/test_syslog_server.rb +88 -0
- data/tests/test_syslog_settings.rb +54 -0
- data/tests/test_tacacs_server.rb +113 -148
- data/tests/test_tacacs_server_host.rb +108 -161
- data/tests/test_vlan.rb +63 -79
- data/tests/test_vrf.rb +92 -0
- data/tests/test_vtp.rb +108 -126
- data/tests/test_yum.rb +47 -41
- metadata +92 -56
- data/.rubocop_todo.yml +0 -293
- data/docs/.rubocop.yml +0 -13
- data/docs/template-feature.rb +0 -45
- data/docs/template-test_feature.rb +0 -51
- data/tests/test_all_cisco.rb +0 -46
@@ -0,0 +1,146 @@
|
|
1
|
+
# Radius Global provider class
|
2
|
+
|
3
|
+
# Jonathan Tripathy et al., September 2015
|
4
|
+
|
5
|
+
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
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
|
+
require_relative 'node_util'
|
20
|
+
|
21
|
+
module Cisco
|
22
|
+
# RadiusGlobal - node utility class for
|
23
|
+
# Radius Global configuration management
|
24
|
+
class RadiusGlobal < NodeUtil
|
25
|
+
attr_reader :name
|
26
|
+
|
27
|
+
def initialize(name)
|
28
|
+
fail TypeError unless name.is_a?(String)
|
29
|
+
fail ArgumentError,
|
30
|
+
"This provider only accepts an id of 'default'" \
|
31
|
+
unless name.eql?('default')
|
32
|
+
@name = name
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.radius_global
|
36
|
+
hash = {}
|
37
|
+
hash['default'] = RadiusGlobal.new('default')
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
|
41
|
+
def ==(other)
|
42
|
+
name == other.name
|
43
|
+
end
|
44
|
+
|
45
|
+
def timeout
|
46
|
+
val = config_get('radius_global', 'timeout')
|
47
|
+
val = val[0].to_i unless val.nil?
|
48
|
+
val
|
49
|
+
end
|
50
|
+
|
51
|
+
def default_timeout
|
52
|
+
val = config_get_default('radius_global', 'timeout').to_i
|
53
|
+
val
|
54
|
+
end
|
55
|
+
|
56
|
+
def timeout=(val)
|
57
|
+
unless val.nil?
|
58
|
+
fail ArgumentError, 'timeout must be an Integer' \
|
59
|
+
unless val.is_a?(Integer)
|
60
|
+
end
|
61
|
+
|
62
|
+
if val.nil? && !timeout.nil?
|
63
|
+
config_set('radius_global',
|
64
|
+
'timeout',
|
65
|
+
state: 'no',
|
66
|
+
timeout: timeout)
|
67
|
+
else
|
68
|
+
config_set('radius_global',
|
69
|
+
'timeout',
|
70
|
+
state: '',
|
71
|
+
timeout: val)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def retransmit_count
|
76
|
+
val = config_get('radius_global', 'retransmit')
|
77
|
+
val = val[0].to_i unless val.nil?
|
78
|
+
val
|
79
|
+
end
|
80
|
+
|
81
|
+
def default_retransmit_count
|
82
|
+
val = config_get_default('radius_global', 'retransmit').to_i
|
83
|
+
val
|
84
|
+
end
|
85
|
+
|
86
|
+
def retransmit_count=(val)
|
87
|
+
unless val.nil?
|
88
|
+
fail ArgumentError, 'retransmit_count must be an Integer' \
|
89
|
+
unless val.is_a?(Integer)
|
90
|
+
end
|
91
|
+
|
92
|
+
if val.nil? && !retransmit_count.nil?
|
93
|
+
config_set('radius_global',
|
94
|
+
'retransmit',
|
95
|
+
state: 'no',
|
96
|
+
count: retransmit_count)
|
97
|
+
else
|
98
|
+
config_set('radius_global',
|
99
|
+
'retransmit',
|
100
|
+
state: '',
|
101
|
+
count: val)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def key_format
|
106
|
+
val = config_get('radius_global', 'key_format')
|
107
|
+
val = val[0].to_i unless val.nil?
|
108
|
+
val
|
109
|
+
end
|
110
|
+
|
111
|
+
def key
|
112
|
+
val = config_get('radius_global', 'key')
|
113
|
+
val = val[0] unless val.nil?
|
114
|
+
val
|
115
|
+
end
|
116
|
+
|
117
|
+
def key_set(value, format)
|
118
|
+
unless value.nil?
|
119
|
+
fail ArgumentError, 'value must be a String' \
|
120
|
+
unless value.is_a?(String)
|
121
|
+
end
|
122
|
+
|
123
|
+
unless format.nil?
|
124
|
+
fail ArgumentError, 'format must be an Integer' \
|
125
|
+
unless format.is_a?(Integer)
|
126
|
+
end
|
127
|
+
|
128
|
+
if value.nil? && !key.nil?
|
129
|
+
config_set('radius_global',
|
130
|
+
'key',
|
131
|
+
state: 'no',
|
132
|
+
key: "#{key_format} #{key}")
|
133
|
+
elsif !format.nil?
|
134
|
+
config_set('radius_global',
|
135
|
+
'key',
|
136
|
+
state: '',
|
137
|
+
key: "#{format} #{value}")
|
138
|
+
else
|
139
|
+
config_set('radius_global',
|
140
|
+
'key',
|
141
|
+
state: '',
|
142
|
+
key: "#{value}")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end # class
|
146
|
+
end # module
|
@@ -0,0 +1,295 @@
|
|
1
|
+
# Radius Server provider class
|
2
|
+
|
3
|
+
# Jonathan Tripathy et al., September 2015
|
4
|
+
|
5
|
+
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
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
|
+
require File.join(File.dirname(__FILE__), 'node_util')
|
20
|
+
|
21
|
+
module Cisco
|
22
|
+
# RadiusServer - node utility class for
|
23
|
+
# Raidus Server configuration management
|
24
|
+
class RadiusServer < NodeUtil
|
25
|
+
attr_reader :name
|
26
|
+
|
27
|
+
def initialize(name, instantiate=true)
|
28
|
+
unless name[/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/]
|
29
|
+
fail ArgumentError, 'Invalid value (Name is not an IP address)'
|
30
|
+
end
|
31
|
+
@name = name
|
32
|
+
|
33
|
+
create if instantiate
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.radiusservers
|
37
|
+
hash = {}
|
38
|
+
|
39
|
+
radiusservers_list = config_get('radius_server', 'hosts')
|
40
|
+
return hash if radiusservers_list.nil?
|
41
|
+
|
42
|
+
radiusservers_list.each do |id|
|
43
|
+
hash[id] = RadiusServer.new(id, false)
|
44
|
+
end
|
45
|
+
|
46
|
+
hash
|
47
|
+
end
|
48
|
+
|
49
|
+
def create
|
50
|
+
config_set('radius_server',
|
51
|
+
'hosts',
|
52
|
+
state: '',
|
53
|
+
ip: @name)
|
54
|
+
end
|
55
|
+
|
56
|
+
def destroy
|
57
|
+
config_set('radius_server',
|
58
|
+
'hosts',
|
59
|
+
state: 'no',
|
60
|
+
ip: @name)
|
61
|
+
end
|
62
|
+
|
63
|
+
def ==(other)
|
64
|
+
name == other.name
|
65
|
+
end
|
66
|
+
|
67
|
+
def auth_port
|
68
|
+
val = config_get('radius_server', 'auth-port', @name)
|
69
|
+
val = val[0].to_i unless val.nil?
|
70
|
+
val
|
71
|
+
end
|
72
|
+
|
73
|
+
def default_auth_port
|
74
|
+
val = config_get_default('radius_server', 'auth-port')
|
75
|
+
val
|
76
|
+
end
|
77
|
+
|
78
|
+
def auth_port=(val)
|
79
|
+
unless val.nil?
|
80
|
+
fail ArgumentError, 'auth_port must be an Integer' \
|
81
|
+
unless val.is_a?(Integer)
|
82
|
+
end
|
83
|
+
|
84
|
+
if val.nil? && !auth_port.nil?
|
85
|
+
config_set('radius_server',
|
86
|
+
'auth-port',
|
87
|
+
state: 'no',
|
88
|
+
ip: @name,
|
89
|
+
port: auth_port)
|
90
|
+
else
|
91
|
+
config_set('radius_server',
|
92
|
+
'auth-port',
|
93
|
+
state: '',
|
94
|
+
ip: @name,
|
95
|
+
port: val)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def acct_port
|
100
|
+
val = config_get('radius_server', 'acct-port', @name)
|
101
|
+
val = val[0].to_i unless val.nil?
|
102
|
+
val
|
103
|
+
end
|
104
|
+
|
105
|
+
def default_acct_port
|
106
|
+
val = config_get_default('radius_server', 'acct-port')
|
107
|
+
val
|
108
|
+
end
|
109
|
+
|
110
|
+
def acct_port=(val)
|
111
|
+
unless val.nil?
|
112
|
+
fail ArgumentError, 'acct_port must be an Integer' \
|
113
|
+
unless val.is_a?(Integer)
|
114
|
+
end
|
115
|
+
|
116
|
+
if val.nil? && !acct_port.nil?
|
117
|
+
config_set('radius_server',
|
118
|
+
'acct-port',
|
119
|
+
state: 'no',
|
120
|
+
ip: @name,
|
121
|
+
port: acct_port)
|
122
|
+
else
|
123
|
+
config_set('radius_server',
|
124
|
+
'acct-port',
|
125
|
+
state: '',
|
126
|
+
ip: @name,
|
127
|
+
port: val)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def timeout
|
132
|
+
val = config_get('radius_server', 'timeout', @name)
|
133
|
+
val = val[0].to_i unless val.nil?
|
134
|
+
val
|
135
|
+
end
|
136
|
+
|
137
|
+
def default_timeout
|
138
|
+
val = config_get_default('radius_server', 'timeout')
|
139
|
+
val
|
140
|
+
end
|
141
|
+
|
142
|
+
def timeout=(val)
|
143
|
+
unless val.nil?
|
144
|
+
fail ArgumentError, 'timeout must be an Integer' \
|
145
|
+
unless val.is_a?(Integer)
|
146
|
+
end
|
147
|
+
|
148
|
+
if val.nil? && !timeout.nil?
|
149
|
+
config_set('radius_server',
|
150
|
+
'timeout',
|
151
|
+
state: 'no',
|
152
|
+
ip: @name,
|
153
|
+
timeout: timeout)
|
154
|
+
else
|
155
|
+
config_set('radius_server',
|
156
|
+
'timeout',
|
157
|
+
state: '',
|
158
|
+
ip: @name,
|
159
|
+
timeout: val)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def retransmit_count
|
164
|
+
val = config_get('radius_server', 'retransmit', @name)
|
165
|
+
val = val[0].to_i unless val.nil?
|
166
|
+
val
|
167
|
+
end
|
168
|
+
|
169
|
+
def default_retransmit_count
|
170
|
+
val = config_get_default('radius_server', 'retransmit')
|
171
|
+
val
|
172
|
+
end
|
173
|
+
|
174
|
+
def retransmit_count=(val)
|
175
|
+
unless val.nil?
|
176
|
+
fail ArgumentError, 'retransmit_count must be an Integer' \
|
177
|
+
unless val.is_a?(Integer)
|
178
|
+
end
|
179
|
+
|
180
|
+
if val.nil? && !retransmit_count.nil?
|
181
|
+
config_set('radius_server',
|
182
|
+
'retransmit',
|
183
|
+
state: 'no',
|
184
|
+
ip: @name,
|
185
|
+
count: retransmit_count)
|
186
|
+
else
|
187
|
+
config_set('radius_server',
|
188
|
+
'retransmit',
|
189
|
+
state: '',
|
190
|
+
ip: @name,
|
191
|
+
count: val)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def accounting
|
196
|
+
val = config_get('radius_server', 'accounting', @name)
|
197
|
+
if val.nil?
|
198
|
+
false
|
199
|
+
else
|
200
|
+
val[0].eql?('accounting') ? true : false
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def default_accounting
|
205
|
+
val = config_get_default('radius_server', 'accounting')
|
206
|
+
val
|
207
|
+
end
|
208
|
+
|
209
|
+
def accounting=(val)
|
210
|
+
if !val
|
211
|
+
config_set('radius_server',
|
212
|
+
'accounting',
|
213
|
+
state: 'no',
|
214
|
+
ip: @name)
|
215
|
+
else
|
216
|
+
config_set('radius_server',
|
217
|
+
'accounting',
|
218
|
+
state: '',
|
219
|
+
ip: @name)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def authentication
|
224
|
+
val = config_get('radius_server', 'authentication', @name)
|
225
|
+
if val.nil?
|
226
|
+
false
|
227
|
+
else
|
228
|
+
val[0].eql?('authentication') ? true : false
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def default_authentication
|
233
|
+
val = config_get_default('radius_server', 'authentication')
|
234
|
+
val
|
235
|
+
end
|
236
|
+
|
237
|
+
def authentication=(val)
|
238
|
+
if !val
|
239
|
+
config_set('radius_server',
|
240
|
+
'authentication',
|
241
|
+
state: 'no',
|
242
|
+
ip: @name)
|
243
|
+
else
|
244
|
+
config_set('radius_server',
|
245
|
+
'authentication',
|
246
|
+
state: '',
|
247
|
+
ip: @name)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def key_format
|
252
|
+
val = config_get('radius_server', 'key_format', @name)
|
253
|
+
val = val[0].to_i unless val.nil?
|
254
|
+
val
|
255
|
+
end
|
256
|
+
|
257
|
+
def key
|
258
|
+
val = config_get('radius_server', 'key', @name)
|
259
|
+
val = val[0] unless val.nil?
|
260
|
+
val
|
261
|
+
end
|
262
|
+
|
263
|
+
def key_set(value, format)
|
264
|
+
unless value.nil?
|
265
|
+
fail ArgumentError, 'value must be a String' \
|
266
|
+
unless value.is_a?(String)
|
267
|
+
end
|
268
|
+
|
269
|
+
unless format.nil?
|
270
|
+
fail ArgumentError, 'format must be an Integer' \
|
271
|
+
unless format.is_a?(Integer)
|
272
|
+
end
|
273
|
+
|
274
|
+
if value.nil? && !key.nil?
|
275
|
+
config_set('radius_server',
|
276
|
+
'key',
|
277
|
+
state: 'no',
|
278
|
+
ip: @name,
|
279
|
+
key: "#{key_format} #{key}")
|
280
|
+
elsif !format.nil?
|
281
|
+
config_set('radius_server',
|
282
|
+
'key',
|
283
|
+
state: '',
|
284
|
+
ip: @name,
|
285
|
+
key: "#{format} #{value}")
|
286
|
+
else
|
287
|
+
config_set('radius_server',
|
288
|
+
'key',
|
289
|
+
state: '',
|
290
|
+
ip: @name,
|
291
|
+
key: "#{value}")
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end # class
|
295
|
+
end # module
|
@@ -1,6 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# NXAPI implementation of RouterOspf class
|
3
|
-
#
|
4
1
|
# November 2014, Chris Van Heuveln
|
5
2
|
#
|
6
3
|
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
@@ -17,80 +14,79 @@
|
|
17
14
|
# See the License for the specific language governing permissions and
|
18
15
|
# limitations under the License.
|
19
16
|
|
20
|
-
|
17
|
+
require_relative 'node_util'
|
21
18
|
|
22
19
|
module Cisco
|
23
|
-
class
|
24
|
-
|
25
|
-
|
26
|
-
@@node = Cisco::Node.instance
|
20
|
+
# RouterOspf - node utility class for process-level OSPF config management
|
21
|
+
class RouterOspf < NodeUtil
|
22
|
+
attr_reader :name
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
def initialize(name, instantiate=true)
|
25
|
+
fail ArgumentError unless name.length > 0
|
26
|
+
@name = name
|
31
27
|
|
32
|
-
|
33
|
-
|
28
|
+
create if instantiate
|
29
|
+
end
|
34
30
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
# Create a hash of all router ospf instances
|
32
|
+
def self.routers
|
33
|
+
ospf_ids = config_get('ospf', 'router')
|
34
|
+
return {} if ospf_ids.nil?
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
hash = {}
|
37
|
+
ospf_ids.each do |name|
|
38
|
+
hash[name] = RouterOspf.new(name, false)
|
39
|
+
end
|
40
|
+
return hash
|
41
|
+
rescue Cisco::CliError => e
|
42
|
+
# cmd will syntax reject when feature is not enabled
|
43
|
+
raise unless e.clierror =~ /Syntax error/
|
44
|
+
return {}
|
43
45
|
end
|
44
|
-
return hash
|
45
|
-
rescue Cisco::CliError => e
|
46
|
-
# cmd will syntax reject when feature is not enabled
|
47
|
-
raise unless e.clierror =~ /Syntax error/
|
48
|
-
return {}
|
49
|
-
end
|
50
|
-
|
51
|
-
def RouterOspf.enabled
|
52
|
-
feat = @@node.config_get("ospf", "feature")
|
53
|
-
return (!feat.nil? and !feat.empty?)
|
54
|
-
rescue Cisco::CliError => e
|
55
|
-
# cmd will syntax reject when feature is not enabled
|
56
|
-
raise unless e.clierror =~ /Syntax error/
|
57
|
-
return false
|
58
|
-
end
|
59
46
|
|
60
|
-
|
61
|
-
|
62
|
-
|
47
|
+
def self.enabled
|
48
|
+
feat = config_get('ospf', 'feature')
|
49
|
+
return (!feat.nil? && !feat.empty?)
|
50
|
+
rescue Cisco::CliError => e
|
51
|
+
# cmd will syntax reject when feature is not enabled
|
52
|
+
raise unless e.clierror =~ /Syntax error/
|
53
|
+
return false
|
54
|
+
end
|
63
55
|
|
64
|
-
|
65
|
-
|
66
|
-
|
56
|
+
def self.enable(state='')
|
57
|
+
config_set('ospf', 'feature', state)
|
58
|
+
end
|
67
59
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
60
|
+
def ospf_router(name, state='')
|
61
|
+
config_set('ospf', 'router', state, name)
|
62
|
+
end
|
72
63
|
|
73
|
-
|
74
|
-
|
75
|
-
if RouterOspf.enabled
|
64
|
+
def enable_create_router_ospf(name)
|
65
|
+
RouterOspf.enable
|
76
66
|
ospf_router(name)
|
77
|
-
else
|
78
|
-
enable_create_router_ospf(name)
|
79
67
|
end
|
80
|
-
end
|
81
68
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
69
|
+
# Create one router ospf instance
|
70
|
+
def create
|
71
|
+
if RouterOspf.enabled
|
72
|
+
ospf_router(name)
|
73
|
+
else
|
74
|
+
enable_create_router_ospf(name)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Destroy one router ospf instance
|
79
|
+
def destroy
|
80
|
+
ospf_ids = config_get('ospf', 'router')
|
81
|
+
return if ospf_ids.nil?
|
82
|
+
if ospf_ids.size == 1
|
83
|
+
RouterOspf.enable('no')
|
84
|
+
else
|
85
|
+
ospf_router(name, 'no')
|
86
|
+
end
|
87
|
+
rescue Cisco::CliError => e
|
88
|
+
# cmd will syntax reject when feature is not enabled
|
89
|
+
raise unless e.clierror =~ /Syntax error/
|
90
90
|
end
|
91
|
-
rescue Cisco::CliError => e
|
92
|
-
# cmd will syntax reject when feature is not enabled
|
93
|
-
raise unless e.clierror =~ /Syntax error/
|
94
91
|
end
|
95
92
|
end
|
96
|
-
end
|