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
@@ -1,6 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# NXAPI implementation of RouterOspfVrf class
|
3
|
-
#
|
4
1
|
# Mike Wiebe, March 2015
|
5
2
|
#
|
6
3
|
# Copyright (c) 2015 Cisco and/or its affiliates.
|
@@ -17,254 +14,273 @@
|
|
17
14
|
# See the License for the specific language governing permissions and
|
18
15
|
# limitations under the License.
|
19
16
|
|
20
|
-
|
21
|
-
|
17
|
+
require_relative 'node_util'
|
18
|
+
require_relative 'router_ospf'
|
22
19
|
|
23
20
|
module Cisco
|
24
|
-
class
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
21
|
+
# RouterOspfVrf - node utility class for per-VRF OSPF config management
|
22
|
+
class RouterOspfVrf < NodeUtil
|
23
|
+
attr_reader :name, :parent
|
24
|
+
|
25
|
+
OSPF_AUTO_COST = {
|
26
|
+
mbps: 'Mbps',
|
27
|
+
gbps: 'Gbps',
|
28
|
+
}
|
29
|
+
|
30
|
+
OSPF_LOG_ADJACENCY = {
|
31
|
+
none: 'none',
|
32
|
+
log: '',
|
33
|
+
detail: 'detail',
|
34
|
+
}
|
35
|
+
|
36
|
+
def initialize(router, name, instantiate=true)
|
37
|
+
fail TypeError if router.nil?
|
38
|
+
fail TypeError if name.nil?
|
39
|
+
fail ArgumentError unless router.length > 0
|
40
|
+
fail ArgumentError unless name.length > 0
|
41
|
+
@router = router
|
42
|
+
@name = name
|
43
|
+
@parent = {}
|
44
|
+
if @name == 'default'
|
45
|
+
@get_args = @set_args = { name: @router }
|
46
|
+
else
|
47
|
+
@get_args = @set_args = { name: @router, vrf: @name }
|
48
|
+
end
|
49
|
+
|
50
|
+
create if instantiate
|
51
|
+
end
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
53
|
+
# Create a hash of all router ospf vrf instances
|
54
|
+
def self.vrfs
|
55
|
+
hash_final = {}
|
56
|
+
RouterOspf.routers.each do |instance|
|
57
|
+
name = instance[0]
|
58
|
+
vrf_ids = config_get('ospf', 'vrf', name: name)
|
59
|
+
hash_tmp = { name =>
|
60
|
+
{ 'default' => RouterOspfVrf.new(name, 'default', false) } }
|
61
|
+
unless vrf_ids.nil?
|
62
|
+
vrf_ids.each do |vrf|
|
63
|
+
hash_tmp[name][vrf] = RouterOspfVrf.new(name, vrf, false)
|
64
|
+
end
|
65
65
|
end
|
66
|
+
hash_final.merge!(hash_tmp)
|
66
67
|
end
|
67
|
-
hash_final
|
68
|
+
hash_final
|
68
69
|
end
|
69
|
-
hash_final
|
70
|
-
end
|
71
70
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
@name != "default"
|
79
|
-
end
|
71
|
+
# Create one router ospf vrf instance
|
72
|
+
def create
|
73
|
+
@parent = RouterOspf.new(@router)
|
74
|
+
config_set('ospf', 'vrf',
|
75
|
+
name: @router, state: '', vrf: @name) if @name != 'default'
|
76
|
+
end
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
:vrf => @name })
|
87
|
-
end
|
78
|
+
# Destroy one router ospf vrf instance
|
79
|
+
def destroy
|
80
|
+
fail RuntimeError if @name == 'default'
|
81
|
+
config_set('ospf', 'vrf', name: @router, state: 'no', vrf: @name)
|
82
|
+
end
|
88
83
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
# Helper method to delete @set_args hash keys
|
85
|
+
def delete_set_args_keys(list)
|
86
|
+
list.each { |key| @set_args.delete(key) }
|
87
|
+
end
|
93
88
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
89
|
+
def auto_cost
|
90
|
+
match = config_get('ospf', 'auto_cost', @get_args)
|
91
|
+
return default_auto_cost if match.nil?
|
92
|
+
# Multiple matches are possible but the first match is used.
|
93
|
+
# This can be removed when rally defect DE3614 is resolved.
|
94
|
+
if match[0].last.nil?
|
95
|
+
[match[0].first.to_i, OSPF_AUTO_COST[:mbps]]
|
96
|
+
else
|
97
|
+
[match[0].first.to_i, match[0].last]
|
98
|
+
end
|
99
|
+
end
|
103
100
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
101
|
+
def auto_cost_set(cost, type)
|
102
|
+
@set_args[:cost] = cost
|
103
|
+
@set_args[:type] = OSPF_AUTO_COST[type]
|
104
|
+
config_set('ospf', 'auto_cost', @set_args)
|
105
|
+
delete_set_args_keys([:cost, :type])
|
106
|
+
end
|
109
107
|
|
110
|
-
|
111
|
-
|
112
|
-
|
108
|
+
def default_auto_cost
|
109
|
+
config_get_default('ospf', 'auto_cost')
|
110
|
+
end
|
113
111
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
112
|
+
def default_metric
|
113
|
+
match = config_get('ospf', 'default_metric', @get_args)
|
114
|
+
match.nil? ? default_default_metric : match.first.to_i
|
115
|
+
end
|
118
116
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
117
|
+
def default_metric=(metric)
|
118
|
+
if metric == default_default_metric
|
119
|
+
@set_args[:state] = 'no'
|
120
|
+
@set_args[:metric] = ''
|
121
|
+
else
|
122
|
+
@set_args[:state] = ''
|
123
|
+
@set_args[:metric] = metric
|
124
|
+
end
|
125
|
+
config_set('ospf', 'default_metric', @set_args)
|
126
|
+
delete_set_args_keys([:state, :metric])
|
124
127
|
end
|
125
|
-
@@node.config_set("ospf", "default_metric", @set_args)
|
126
|
-
set_args_keys_delete([:state, :metric])
|
127
|
-
end
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
def default_default_metric
|
130
|
+
config_get_default('ospf', 'default_metric')
|
131
|
+
end
|
132
132
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
133
|
+
def log_adjacency
|
134
|
+
match = config_get('ospf', 'log_adjacency', @get_args)
|
135
|
+
return default_log_adjacency if match.nil?
|
136
|
+
# Multiple matches are possible but the first match is used.
|
137
|
+
# This can be removed when rally defect DE3614 is resolved.
|
138
|
+
match[0].flatten.last.nil? ? :log : :detail
|
139
|
+
end
|
140
140
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
@set_args[:state]
|
145
|
-
|
146
|
-
|
141
|
+
def log_adjacency=(type)
|
142
|
+
case type
|
143
|
+
when :none
|
144
|
+
@set_args[:state] = 'no'
|
145
|
+
@set_args[:type] = ''
|
146
|
+
when :log, :detail
|
147
|
+
@set_args[:state] = ''
|
148
|
+
@set_args[:type] = OSPF_LOG_ADJACENCY[type]
|
149
|
+
end
|
150
|
+
config_set('ospf', 'log_adjacency', @set_args)
|
151
|
+
delete_set_args_keys([:state, :type])
|
147
152
|
end
|
148
|
-
@@node.config_set("ospf", "log_adjacency", @set_args)
|
149
|
-
set_args_keys_delete([:state, :type])
|
150
|
-
end
|
151
153
|
|
152
|
-
|
153
|
-
|
154
|
-
|
154
|
+
def default_log_adjacency
|
155
|
+
config_get_default('ospf', 'log_adjacency')
|
156
|
+
end
|
155
157
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
158
|
+
def router_id
|
159
|
+
match = config_get('ospf', 'router_id', @get_args)
|
160
|
+
match.nil? ? default_router_id : match.first
|
161
|
+
end
|
160
162
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
163
|
+
def router_id=(router_id)
|
164
|
+
if router_id == default_router_id
|
165
|
+
@set_args[:state] = 'no'
|
166
|
+
@set_args[:router_id] = ''
|
167
|
+
else
|
168
|
+
@set_args[:state] = ''
|
169
|
+
@set_args[:router_id] = router_id
|
170
|
+
end
|
165
171
|
|
166
|
-
|
167
|
-
|
168
|
-
|
172
|
+
config_set('ospf', 'router_id', @set_args)
|
173
|
+
delete_set_args_keys([:state, :router_id])
|
174
|
+
end
|
169
175
|
|
170
|
-
|
171
|
-
|
172
|
-
|
176
|
+
def default_router_id
|
177
|
+
config_get_default('ospf', 'router_id')
|
178
|
+
end
|
173
179
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
180
|
+
def timer_throttle_lsa
|
181
|
+
match = config_get('ospf', 'timer_throttle_lsa', @get_args)
|
182
|
+
if match.nil? || match.first.nil?
|
183
|
+
default_timer_throttle_lsa
|
184
|
+
else
|
185
|
+
match.first.collect(&:to_i)
|
186
|
+
end
|
187
|
+
end
|
179
188
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
189
|
+
def timer_throttle_lsa_start
|
190
|
+
start, _hold, _max = timer_throttle_lsa
|
191
|
+
return default_timer_throttle_lsa_start if start.nil?
|
192
|
+
start
|
193
|
+
end
|
185
194
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
195
|
+
def timer_throttle_lsa_hold
|
196
|
+
_start, hold, _max = timer_throttle_lsa
|
197
|
+
return default_timer_throttle_lsa_hold if hold.nil?
|
198
|
+
hold
|
199
|
+
end
|
191
200
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
201
|
+
def timer_throttle_lsa_max
|
202
|
+
_start, _hold, max = timer_throttle_lsa
|
203
|
+
return default_timer_throttle_lsa_max if max.nil?
|
204
|
+
max
|
205
|
+
end
|
197
206
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
207
|
+
def timer_throttle_lsa_set(start, hold, max)
|
208
|
+
@set_args[:start] = start
|
209
|
+
@set_args[:hold] = hold
|
210
|
+
@set_args[:max] = max
|
211
|
+
config_set('ospf', 'timer_throttle_lsa', @set_args)
|
212
|
+
delete_set_args_keys([:start, :hold, :max])
|
213
|
+
end
|
203
214
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
215
|
+
def default_timer_throttle_lsa
|
216
|
+
[default_timer_throttle_lsa_start,
|
217
|
+
default_timer_throttle_lsa_hold,
|
218
|
+
default_timer_throttle_lsa_max]
|
219
|
+
end
|
209
220
|
|
210
|
-
|
211
|
-
|
212
|
-
|
221
|
+
def default_timer_throttle_lsa_start
|
222
|
+
config_get_default('ospf', 'timer_throttle_lsa_start')
|
223
|
+
end
|
213
224
|
|
214
|
-
|
215
|
-
|
216
|
-
|
225
|
+
def default_timer_throttle_lsa_hold
|
226
|
+
config_get_default('ospf', 'timer_throttle_lsa_hold')
|
227
|
+
end
|
217
228
|
|
218
|
-
|
219
|
-
|
220
|
-
|
229
|
+
def default_timer_throttle_lsa_max
|
230
|
+
config_get_default('ospf', 'timer_throttle_lsa_max')
|
231
|
+
end
|
221
232
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
233
|
+
def timer_throttle_spf
|
234
|
+
match = config_get('ospf', 'timer_throttle_spf', @get_args)
|
235
|
+
if match.nil? || match.first.nil?
|
236
|
+
default_timer_throttle_spf
|
237
|
+
else
|
238
|
+
match.first.collect(&:to_i)
|
239
|
+
end
|
240
|
+
end
|
227
241
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
242
|
+
def timer_throttle_spf_start
|
243
|
+
start, _hold, _max = timer_throttle_spf
|
244
|
+
return default_timer_throttle_spf_start if start.nil?
|
245
|
+
start
|
246
|
+
end
|
233
247
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
248
|
+
def timer_throttle_spf_hold
|
249
|
+
_start, hold, _max = timer_throttle_spf
|
250
|
+
return default_timer_throttle_spf_hold if hold.nil?
|
251
|
+
hold
|
252
|
+
end
|
239
253
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
254
|
+
def timer_throttle_spf_max
|
255
|
+
_start, _hold, max = timer_throttle_spf
|
256
|
+
return default_timer_throttle_spf_max if max.nil?
|
257
|
+
max
|
258
|
+
end
|
245
259
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
260
|
+
def timer_throttle_spf_set(start, hold, max)
|
261
|
+
@set_args[:start] = start
|
262
|
+
@set_args[:hold] = hold
|
263
|
+
@set_args[:max] = max
|
264
|
+
config_set('ospf', 'timer_throttle_spf', @set_args)
|
265
|
+
delete_set_args_keys([:start, :hold, :max])
|
266
|
+
end
|
251
267
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
268
|
+
def default_timer_throttle_spf
|
269
|
+
[default_timer_throttle_spf_start,
|
270
|
+
default_timer_throttle_spf_hold,
|
271
|
+
default_timer_throttle_spf_max]
|
272
|
+
end
|
257
273
|
|
258
|
-
|
259
|
-
|
260
|
-
|
274
|
+
def default_timer_throttle_spf_start
|
275
|
+
config_get_default('ospf', 'timer_throttle_spf_start')
|
276
|
+
end
|
261
277
|
|
262
|
-
|
263
|
-
|
264
|
-
|
278
|
+
def default_timer_throttle_spf_hold
|
279
|
+
config_get_default('ospf', 'timer_throttle_spf_hold')
|
280
|
+
end
|
265
281
|
|
266
|
-
|
267
|
-
|
282
|
+
def default_timer_throttle_spf_max
|
283
|
+
config_get_default('ospf', 'timer_throttle_spf_max')
|
284
|
+
end
|
268
285
|
end
|
269
286
|
end
|
270
|
-
end
|