cisco_node_utils 1.0.1 → 1.1.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 +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
|
@@ -322,12 +322,4 @@ vtp:
|
|
|
322
322
|
|
|
323
323
|
## Style Guide
|
|
324
324
|
|
|
325
|
-
Please
|
|
326
|
-
feature in alphabetical order as well. As YAML permits duplicate entries
|
|
327
|
-
(in which case the last entry overrides any earlier entries), keeping a
|
|
328
|
-
consistent order helps to prevent accidentally introducing such duplication.
|
|
329
|
-
|
|
330
|
-
Note that `~` is the YAML syntax that corresponds to Ruby's `nil`.
|
|
331
|
-
|
|
332
|
-
Use the key-value wildcarding style wherever possible, as it's more flexible
|
|
333
|
-
than the printf-style wildcarding.
|
|
325
|
+
Please see [YAML Best Practices](../../docs/README-develop-best-practices.md#ydbp).
|
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
# June 2015, Michael G Wiebe
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2015 Cisco and/or its affiliates.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
require_relative 'node_util'
|
|
18
|
+
|
|
19
|
+
module Cisco
|
|
20
|
+
# RouterBgp - node utility class for BGP general config management
|
|
21
|
+
class RouterBgp < NodeUtil
|
|
22
|
+
attr_reader :asnum, :vrf
|
|
23
|
+
|
|
24
|
+
def initialize(asnum, vrf='default', instantiate=true)
|
|
25
|
+
fail ArgumentError unless vrf.is_a? String
|
|
26
|
+
fail ArgumentError unless vrf.length > 0
|
|
27
|
+
@asnum = RouterBgp.process_asnum(asnum)
|
|
28
|
+
@vrf = vrf
|
|
29
|
+
if @vrf == 'default'
|
|
30
|
+
@get_args = @set_args = { asnum: @asnum }
|
|
31
|
+
else
|
|
32
|
+
@get_args = @set_args = { asnum: @asnum, vrf: @vrf }
|
|
33
|
+
end
|
|
34
|
+
create if instantiate
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.process_asnum(asnum)
|
|
38
|
+
err_msg = "BGP asnum must be either a 'String' or an" \
|
|
39
|
+
" 'Integer' object"
|
|
40
|
+
fail ArgumentError, err_msg unless asnum.is_a?(Integer) ||
|
|
41
|
+
asnum.is_a?(String)
|
|
42
|
+
if asnum.is_a? String
|
|
43
|
+
# Match ASDOT '1.5' or ASPLAIN '55' strings
|
|
44
|
+
fail ArgumentError unless /^(\d+|\d+\.\d+)$/.match(asnum)
|
|
45
|
+
asnum = RouterBgp.dot_to_big(asnum) if /\d+\.\d+/.match(asnum)
|
|
46
|
+
end
|
|
47
|
+
asnum.to_i
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Create a hash of all router bgp default and non-default
|
|
51
|
+
# vrf instances
|
|
52
|
+
def self.routers
|
|
53
|
+
bgp_ids = config_get('bgp', 'router')
|
|
54
|
+
return {} if bgp_ids.nil?
|
|
55
|
+
|
|
56
|
+
hash_final = {}
|
|
57
|
+
# TODO: Remove loop if only single ASN supported by RFC?
|
|
58
|
+
bgp_ids.each do |asnum|
|
|
59
|
+
asnum = asnum.to_i unless /\d+.\d+/.match(asnum)
|
|
60
|
+
hash_tmp = { asnum =>
|
|
61
|
+
{ 'default' => RouterBgp.new(asnum, 'default', false) } }
|
|
62
|
+
vrf_ids = config_get('bgp', 'vrf', asnum: asnum)
|
|
63
|
+
unless vrf_ids.nil?
|
|
64
|
+
vrf_ids.each do |vrf|
|
|
65
|
+
hash_tmp[asnum][vrf] = RouterBgp.new(asnum, vrf, false)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
hash_final.merge!(hash_tmp)
|
|
69
|
+
end
|
|
70
|
+
return hash_final
|
|
71
|
+
rescue Cisco::CliError => e
|
|
72
|
+
# cmd will syntax reject when feature is not enabled
|
|
73
|
+
raise unless e.clierror =~ /Syntax error/
|
|
74
|
+
return {}
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def self.enabled
|
|
78
|
+
feat = config_get('bgp', 'feature')
|
|
79
|
+
return !(feat.nil? || feat.empty?)
|
|
80
|
+
rescue Cisco::CliError => e
|
|
81
|
+
# cmd will syntax reject when feature is not enabled
|
|
82
|
+
raise unless e.clierror =~ /Syntax error/
|
|
83
|
+
return false
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def self.enable(state='')
|
|
87
|
+
config_set('bgp', 'feature', state: state)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Convert BGP ASN ASDOT+ to ASPLAIN
|
|
91
|
+
def self.dot_to_big(dot_str)
|
|
92
|
+
fail ArgumentError unless dot_str.is_a? String
|
|
93
|
+
return dot_str unless /\d+\.\d+/.match(dot_str)
|
|
94
|
+
mask = 0b1111111111111111
|
|
95
|
+
high = dot_str.to_i
|
|
96
|
+
low = 0
|
|
97
|
+
low_match = dot_str.match(/\.(\d+)/)
|
|
98
|
+
low = low_match[1].to_i if low_match
|
|
99
|
+
high_bits = (mask & high) << 16
|
|
100
|
+
low_bits = mask & low
|
|
101
|
+
high_bits + low_bits
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def router_bgp(asnum, vrf, state='')
|
|
105
|
+
# Only one bgp autonomous system number is allowed
|
|
106
|
+
# Raise an error if one is already configured that
|
|
107
|
+
# differs from the one being created.
|
|
108
|
+
configured = config_get('bgp', 'router')
|
|
109
|
+
if !configured.nil? && configured.first.to_s != asnum.to_s
|
|
110
|
+
fail %(
|
|
111
|
+
Changing the BGP Autonomous System Number is not allowed.
|
|
112
|
+
Current BGP asn: #{configured.first}
|
|
113
|
+
Attempted change to asn: #{asnum})
|
|
114
|
+
end
|
|
115
|
+
@set_args[:state] = state
|
|
116
|
+
if vrf == 'default'
|
|
117
|
+
config_set('bgp', 'router', @set_args)
|
|
118
|
+
else
|
|
119
|
+
config_set('bgp', 'vrf', @set_args)
|
|
120
|
+
end
|
|
121
|
+
set_args_keys_default
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def enable_create_router_bgp(asnum, vrf)
|
|
125
|
+
RouterBgp.enable
|
|
126
|
+
router_bgp(asnum, vrf)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Create one router bgp instance
|
|
130
|
+
def create
|
|
131
|
+
if RouterBgp.enabled
|
|
132
|
+
router_bgp(@asnum, @vrf)
|
|
133
|
+
else
|
|
134
|
+
enable_create_router_bgp(@asnum, @vrf)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Destroy router bgp instance
|
|
139
|
+
def destroy
|
|
140
|
+
vrf_ids = config_get('bgp', 'vrf', asnum: @asnum)
|
|
141
|
+
vrf_ids = ['default'] if vrf_ids.nil?
|
|
142
|
+
if vrf_ids.size == 1 || @vrf == 'default'
|
|
143
|
+
RouterBgp.enable('no')
|
|
144
|
+
else
|
|
145
|
+
router_bgp(asnum, @vrf, 'no')
|
|
146
|
+
end
|
|
147
|
+
rescue Cisco::CliError => e
|
|
148
|
+
# cmd will syntax reject when feature is not enabled
|
|
149
|
+
raise unless e.clierror =~ /Syntax error/
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Helper method to delete @set_args hash keys
|
|
153
|
+
def set_args_keys_default
|
|
154
|
+
if @vrf == 'default'
|
|
155
|
+
@set_args = { asnum: @asnum }
|
|
156
|
+
else
|
|
157
|
+
@set_args = { asnum: @asnum, vrf: @vrf }
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Attributes:
|
|
162
|
+
|
|
163
|
+
# Bestpath Getters
|
|
164
|
+
def bestpath_always_compare_med
|
|
165
|
+
match = config_get('bgp', 'bestpath_always_compare_med', @get_args)
|
|
166
|
+
match.nil? ? default_bestpath_always_compare_med : true
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def bestpath_aspath_multipath_relax
|
|
170
|
+
match = config_get('bgp', 'bestpath_aspath_multipath_relax', @get_args)
|
|
171
|
+
match.nil? ? default_bestpath_aspath_multipath_relax : true
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def bestpath_compare_routerid
|
|
175
|
+
match = config_get('bgp', 'bestpath_compare_routerid', @get_args)
|
|
176
|
+
match.nil? ? default_bestpath_compare_routerid : true
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def bestpath_cost_community_ignore
|
|
180
|
+
match = config_get('bgp', 'bestpath_cost_community_ignore', @get_args)
|
|
181
|
+
match.nil? ? default_bestpath_cost_community_ignore : true
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def bestpath_med_confed
|
|
185
|
+
match = config_get('bgp', 'bestpath_med_confed', @get_args)
|
|
186
|
+
match.nil? ? default_bestpath_med_confed : true
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def bestpath_med_missing_as_worst
|
|
190
|
+
match = config_get('bgp', 'bestpath_med_missing_as_worst', @get_args)
|
|
191
|
+
match.nil? ? default_bestpath_med_missing_as_worst : true
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def bestpath_med_non_deterministic
|
|
195
|
+
match = config_get('bgp', 'bestpath_med_non_deterministic', @get_args)
|
|
196
|
+
match.nil? ? default_bestpath_med_non_deterministic : true
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# Bestpath Setters
|
|
200
|
+
def bestpath_always_compare_med=(enable)
|
|
201
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
202
|
+
config_set('bgp', 'bestpath_always_compare_med', @set_args)
|
|
203
|
+
set_args_keys_default
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def bestpath_aspath_multipath_relax=(enable)
|
|
207
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
208
|
+
config_set('bgp', 'bestpath_aspath_multipath_relax', @set_args)
|
|
209
|
+
set_args_keys_default
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def bestpath_compare_routerid=(enable)
|
|
213
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
214
|
+
config_set('bgp', 'bestpath_compare_routerid', @set_args)
|
|
215
|
+
set_args_keys_default
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def bestpath_cost_community_ignore=(enable)
|
|
219
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
220
|
+
config_set('bgp', 'bestpath_cost_community_ignore', @set_args)
|
|
221
|
+
set_args_keys_default
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def bestpath_med_confed=(enable)
|
|
225
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
226
|
+
config_set('bgp', 'bestpath_med_confed', @set_args)
|
|
227
|
+
set_args_keys_default
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def bestpath_med_missing_as_worst=(enable)
|
|
231
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
232
|
+
config_set('bgp', 'bestpath_med_missing_as_worst', @set_args)
|
|
233
|
+
set_args_keys_default
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def bestpath_med_non_deterministic=(enable)
|
|
237
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
238
|
+
config_set('bgp', 'bestpath_med_non_deterministic', @set_args)
|
|
239
|
+
set_args_keys_default
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# Bestpath Defaults
|
|
243
|
+
def default_bestpath_always_compare_med
|
|
244
|
+
config_get_default('bgp', 'bestpath_always_compare_med')
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def default_bestpath_aspath_multipath_relax
|
|
248
|
+
config_get_default('bgp', 'bestpath_aspath_multipath_relax')
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def default_bestpath_compare_routerid
|
|
252
|
+
config_get_default('bgp', 'bestpath_compare_routerid')
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def default_bestpath_cost_community_ignore
|
|
256
|
+
config_get_default('bgp', 'bestpath_cost_community_ignore')
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def default_bestpath_med_confed
|
|
260
|
+
config_get_default('bgp', 'bestpath_med_confed')
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def default_bestpath_med_missing_as_worst
|
|
264
|
+
config_get_default('bgp', 'bestpath_med_missing_as_worst')
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def default_bestpath_med_non_deterministic
|
|
268
|
+
config_get_default('bgp', 'bestpath_med_non_deterministic')
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Cluster Id (Getter/Setter/Default)
|
|
272
|
+
def cluster_id
|
|
273
|
+
match = config_get('bgp', 'cluster_id', @get_args)
|
|
274
|
+
match.nil? ? default_cluster_id : match.first
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def cluster_id=(id)
|
|
278
|
+
# In order to remove a bgp cluster_id you cannot simply issue
|
|
279
|
+
# 'no bgp cluster-id'. IMO this should be possible because you
|
|
280
|
+
# can only configure a single bgp cluster-id.
|
|
281
|
+
#
|
|
282
|
+
# HACK: specify a dummy id when removing the feature.
|
|
283
|
+
dummy_id = 1
|
|
284
|
+
if id == default_cluster_id
|
|
285
|
+
@set_args[:state] = 'no'
|
|
286
|
+
@set_args[:id] = dummy_id
|
|
287
|
+
else
|
|
288
|
+
@set_args[:state] = ''
|
|
289
|
+
@set_args[:id] = id
|
|
290
|
+
end
|
|
291
|
+
config_set('bgp', 'cluster_id', @set_args)
|
|
292
|
+
set_args_keys_default
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def default_cluster_id
|
|
296
|
+
config_get_default('bgp', 'cluster_id')
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# Confederation Id (Getter/Setter/Default)
|
|
300
|
+
def confederation_id
|
|
301
|
+
match = config_get('bgp', 'confederation_id', @get_args)
|
|
302
|
+
match.nil? ? default_confederation_id : match.first
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def confederation_id=(id)
|
|
306
|
+
# In order to remove a bgp confed id you cannot simply issue
|
|
307
|
+
# 'no bgp confederation id'. IMO this should be possible
|
|
308
|
+
# because you can only configure a single bgp confed id.
|
|
309
|
+
#
|
|
310
|
+
# HACK: specify a dummy id when removing the feature.
|
|
311
|
+
dummy_id = 1
|
|
312
|
+
if id == default_confederation_id
|
|
313
|
+
@set_args[:state] = 'no'
|
|
314
|
+
@set_args[:id] = dummy_id
|
|
315
|
+
else
|
|
316
|
+
@set_args[:state] = ''
|
|
317
|
+
@set_args[:id] = id
|
|
318
|
+
end
|
|
319
|
+
config_set('bgp', 'confederation_id', @set_args)
|
|
320
|
+
set_args_keys_default
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
def default_confederation_id
|
|
324
|
+
config_get_default('bgp', 'confederation_id')
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# Enforce First As (Getter/Setter/Default)
|
|
328
|
+
def enforce_first_as
|
|
329
|
+
match = config_get('bgp', 'enforce_first_as', @get_args)
|
|
330
|
+
match.nil? ? false : true
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
def enforce_first_as=(enable)
|
|
334
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
335
|
+
config_set('bgp', 'enforce_first_as', @set_args)
|
|
336
|
+
set_args_keys_default
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
def default_enforce_first_as
|
|
340
|
+
config_get_default('bgp', 'enforce_first_as')
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
# Confederation Peers (Getter/Setter/Default)
|
|
344
|
+
def confederation_peers
|
|
345
|
+
match = config_get('bgp', 'confederation_peers', @get_args)
|
|
346
|
+
match.nil? ? default_confederation_peers : match.first
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def confederation_peers_set(peers)
|
|
350
|
+
# The confederation peers command is additive so we first need to
|
|
351
|
+
# remove any existing peers.
|
|
352
|
+
unless confederation_peers.empty?
|
|
353
|
+
@set_args[:state] = 'no'
|
|
354
|
+
@set_args[:peer_list] = confederation_peers
|
|
355
|
+
config_set('bgp', 'confederation_peers', @set_args)
|
|
356
|
+
end
|
|
357
|
+
unless peers == default_confederation_peers
|
|
358
|
+
@set_args[:state] = ''
|
|
359
|
+
@set_args[:peer_list] = peers
|
|
360
|
+
config_set('bgp', 'confederation_peers', @set_args)
|
|
361
|
+
end
|
|
362
|
+
set_args_keys_default
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
def default_confederation_peers
|
|
366
|
+
config_get_default('bgp', 'confederation_peers')
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
# Graceful Restart Getters
|
|
370
|
+
def graceful_restart
|
|
371
|
+
match = config_get('bgp', 'graceful_restart', @get_args)
|
|
372
|
+
match.nil? ? false : true
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
def graceful_restart_timers_restart
|
|
376
|
+
match = config_get('bgp', 'graceful_restart_timers_restart', @get_args)
|
|
377
|
+
match.nil? ? default_graceful_restart_timers_restart : match.first.to_i
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
def graceful_restart_timers_stalepath_time
|
|
381
|
+
match = config_get('bgp', 'graceful_restart_timers_stalepath_time',
|
|
382
|
+
@get_args)
|
|
383
|
+
if match.nil?
|
|
384
|
+
default_graceful_restart_timers_stalepath_time
|
|
385
|
+
else
|
|
386
|
+
match.first.to_i
|
|
387
|
+
end
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
def graceful_restart_helper
|
|
391
|
+
match = config_get('bgp', 'graceful_restart_helper', @get_args)
|
|
392
|
+
match.nil? ? default_graceful_restart_helper : true
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
# Graceful Restart Setters
|
|
396
|
+
def graceful_restart=(enable)
|
|
397
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
398
|
+
config_set('bgp', 'graceful_restart', @set_args)
|
|
399
|
+
set_args_keys_default
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
def graceful_restart_timers_restart=(seconds)
|
|
403
|
+
if seconds == default_graceful_restart_timers_restart
|
|
404
|
+
@set_args[:state] = 'no'
|
|
405
|
+
@set_args[:seconds] = ''
|
|
406
|
+
else
|
|
407
|
+
@set_args[:state] = ''
|
|
408
|
+
@set_args[:seconds] = seconds
|
|
409
|
+
end
|
|
410
|
+
config_set('bgp', 'graceful_restart_timers_restart', @set_args)
|
|
411
|
+
set_args_keys_default
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
def graceful_restart_timers_stalepath_time=(seconds)
|
|
415
|
+
if seconds == default_graceful_restart_timers_stalepath_time
|
|
416
|
+
@set_args[:state] = 'no'
|
|
417
|
+
@set_args[:seconds] = ''
|
|
418
|
+
else
|
|
419
|
+
@set_args[:state] = ''
|
|
420
|
+
@set_args[:seconds] = seconds
|
|
421
|
+
end
|
|
422
|
+
config_set('bgp', 'graceful_restart_timers_stalepath_time', @set_args)
|
|
423
|
+
set_args_keys_default
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
def graceful_restart_helper=(enable)
|
|
427
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
428
|
+
config_set('bgp', 'graceful_restart_helper', @set_args)
|
|
429
|
+
set_args_keys_default
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
# Graceful Restart Defaults
|
|
433
|
+
def default_graceful_restart
|
|
434
|
+
config_get_default('bgp', 'graceful_restart')
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
def default_graceful_restart_timers_restart
|
|
438
|
+
config_get_default('bgp', 'graceful_restart_timers_restart')
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def default_graceful_restart_timers_stalepath_time
|
|
442
|
+
config_get_default('bgp', 'graceful_restart_timers_stalepath_time')
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
def default_graceful_restart_helper
|
|
446
|
+
config_get_default('bgp', 'graceful_restart_helper')
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
# MaxAs Limit (Getter/Setter/Default)
|
|
450
|
+
def maxas_limit
|
|
451
|
+
match = config_get('bgp', 'maxas_limit', @get_args)
|
|
452
|
+
match.nil? ? default_maxas_limit : match.first.to_i
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
def maxas_limit=(limit)
|
|
456
|
+
if limit == default_maxas_limit
|
|
457
|
+
@set_args[:state] = 'no'
|
|
458
|
+
@set_args[:limit] = ''
|
|
459
|
+
else
|
|
460
|
+
@set_args[:state] = ''
|
|
461
|
+
@set_args[:limit] = limit
|
|
462
|
+
end
|
|
463
|
+
config_set('bgp', 'maxas_limit', @set_args)
|
|
464
|
+
set_args_keys_default
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
def default_maxas_limit
|
|
468
|
+
config_get_default('bgp', 'maxas_limit')
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
# Log Neighbor Changes (Getter/Setter/Default)
|
|
472
|
+
def log_neighbor_changes
|
|
473
|
+
match = config_get('bgp', 'log_neighbor_changes', @get_args)
|
|
474
|
+
match.nil? ? default_log_neighbor_changes : true
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
def log_neighbor_changes=(enable)
|
|
478
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
479
|
+
config_set('bgp', 'log_neighbor_changes', @set_args)
|
|
480
|
+
set_args_keys_default
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
def default_log_neighbor_changes
|
|
484
|
+
config_get_default('bgp', 'log_neighbor_changes')
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
# Neighbor fib down accelerate (Getter/Setter/Default)
|
|
488
|
+
def neighbor_fib_down_accelerate
|
|
489
|
+
match = config_get('bgp', 'neighbor_fib_down_accelerate', @get_args)
|
|
490
|
+
match.nil? ? default_neighbor_fib_down_accelerate : true
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
def neighbor_fib_down_accelerate=(enable)
|
|
494
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
495
|
+
config_set('bgp', 'neighbor_fib_down_accelerate', @set_args)
|
|
496
|
+
set_args_keys_default
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
def default_neighbor_fib_down_accelerate
|
|
500
|
+
config_get_default('bgp', 'neighbor_fib_down_accelerate')
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
# Reconnect Interval (Getter/Setter/Default)
|
|
504
|
+
def reconnect_interval
|
|
505
|
+
match = config_get('bgp', 'reconnect_interval', @get_args)
|
|
506
|
+
match.nil? ? default_reconnect_interval : match.first.to_i
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
def reconnect_interval=(seconds)
|
|
510
|
+
if seconds == default_reconnect_interval
|
|
511
|
+
@set_args[:state] = 'no'
|
|
512
|
+
@set_args[:seconds] = ''
|
|
513
|
+
else
|
|
514
|
+
@set_args[:state] = ''
|
|
515
|
+
@set_args[:seconds] = seconds
|
|
516
|
+
end
|
|
517
|
+
config_set('bgp', 'reconnect_interval', @set_args)
|
|
518
|
+
set_args_keys_default
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
def default_reconnect_interval
|
|
522
|
+
config_get_default('bgp', 'reconnect_interval')
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
# Router ID (Getter/Setter/Default)
|
|
526
|
+
def router_id
|
|
527
|
+
match = config_get('bgp', 'router_id', @get_args)
|
|
528
|
+
match.nil? ? default_router_id : match.first
|
|
529
|
+
end
|
|
530
|
+
|
|
531
|
+
def router_id=(id)
|
|
532
|
+
# In order to remove a bgp router-id you cannot simply issue
|
|
533
|
+
# 'no bgp router-id'. Dummy-id specified to work around this.
|
|
534
|
+
dummy_id = '1.2.3.4'
|
|
535
|
+
if id == default_router_id
|
|
536
|
+
@set_args[:state] = 'no'
|
|
537
|
+
@set_args[:id] = dummy_id
|
|
538
|
+
else
|
|
539
|
+
@set_args[:state] = ''
|
|
540
|
+
@set_args[:id] = id
|
|
541
|
+
end
|
|
542
|
+
config_set('bgp', 'router_id', @set_args)
|
|
543
|
+
set_args_keys_default
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
def default_router_id
|
|
547
|
+
config_get_default('bgp', 'router_id')
|
|
548
|
+
end
|
|
549
|
+
|
|
550
|
+
# Shutdown (Getter/Setter/Default)
|
|
551
|
+
def shutdown
|
|
552
|
+
match = config_get('bgp', 'shutdown', @asnum)
|
|
553
|
+
match.nil? ? default_shutdown : true
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
def shutdown=(enable)
|
|
557
|
+
@set_args[:state] = (enable ? '' : 'no')
|
|
558
|
+
config_set('bgp', 'shutdown', @set_args)
|
|
559
|
+
set_args_keys_default
|
|
560
|
+
end
|
|
561
|
+
|
|
562
|
+
def default_shutdown
|
|
563
|
+
config_get_default('bgp', 'shutdown')
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
# Supress Fib Pending (Getter/Setter/Default)
|
|
567
|
+
def suppress_fib_pending
|
|
568
|
+
match = config_get('bgp', 'suppress_fib_pending', @get_args)
|
|
569
|
+
match.nil? ? default_suppress_fib_pending : true
|
|
570
|
+
end
|
|
571
|
+
|
|
572
|
+
def suppress_fib_pending=(enable)
|
|
573
|
+
enable == true ? @set_args[:state] = '' : @set_args[:state] = 'no'
|
|
574
|
+
config_set('bgp', 'suppress_fib_pending', @set_args)
|
|
575
|
+
set_args_keys_default
|
|
576
|
+
end
|
|
577
|
+
|
|
578
|
+
def default_suppress_fib_pending
|
|
579
|
+
config_get_default('bgp', 'suppress_fib_pending')
|
|
580
|
+
end
|
|
581
|
+
|
|
582
|
+
# BGP Timers Getters
|
|
583
|
+
def timer_bgp_keepalive_hold
|
|
584
|
+
match = config_get('bgp', 'timer_bgp_keepalive_hold', @get_args)
|
|
585
|
+
match.nil? ? default_timer_bgp_keepalive_hold : match.first
|
|
586
|
+
end
|
|
587
|
+
|
|
588
|
+
def timer_bgp_keepalive
|
|
589
|
+
keepalive, _hold = timer_bgp_keepalive_hold
|
|
590
|
+
return default_timer_bgp_keepalive if keepalive.nil?
|
|
591
|
+
keepalive.to_i
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
def timer_bgp_holdtime
|
|
595
|
+
_keepalive, hold = timer_bgp_keepalive_hold
|
|
596
|
+
return default_timer_bgp_holdtime if hold.nil?
|
|
597
|
+
hold.to_i
|
|
598
|
+
end
|
|
599
|
+
|
|
600
|
+
def timer_bestpath_limit
|
|
601
|
+
match = config_get('bgp', 'timer_bestpath_limit', @get_args)
|
|
602
|
+
match.nil? ? default_timer_bestpath_limit : match.first.to_i
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
def timer_bestpath_limit_always
|
|
606
|
+
match = config_get('bgp', 'timer_bestpath_limit_always', @get_args)
|
|
607
|
+
match.nil? ? default_timer_bestpath_limit_always : true
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
# BGP Timers Setters
|
|
611
|
+
def timer_bgp_keepalive_hold_set(keepalive, hold)
|
|
612
|
+
if keepalive == default_timer_bgp_keepalive &&
|
|
613
|
+
hold == default_timer_bgp_holdtime
|
|
614
|
+
@set_args[:state] = 'no'
|
|
615
|
+
@set_args[:keepalive] = keepalive
|
|
616
|
+
@set_args[:hold] = hold
|
|
617
|
+
else
|
|
618
|
+
@set_args[:state] = ''
|
|
619
|
+
@set_args[:keepalive] = keepalive
|
|
620
|
+
@set_args[:hold] = hold
|
|
621
|
+
end
|
|
622
|
+
config_set('bgp', 'timer_bgp_keepalive_hold', @set_args)
|
|
623
|
+
set_args_keys_default
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
def timer_bestpath_limit_set(seconds, always=false)
|
|
627
|
+
if always
|
|
628
|
+
feature = 'timer_bestpath_limit_always'
|
|
629
|
+
else
|
|
630
|
+
feature = 'timer_bestpath_limit'
|
|
631
|
+
end
|
|
632
|
+
if seconds == default_timer_bestpath_limit
|
|
633
|
+
@set_args[:state] = 'no'
|
|
634
|
+
@set_args[:seconds] = ''
|
|
635
|
+
else
|
|
636
|
+
@set_args[:state] = ''
|
|
637
|
+
@set_args[:seconds] = seconds
|
|
638
|
+
end
|
|
639
|
+
config_set('bgp', feature, @set_args)
|
|
640
|
+
set_args_keys_default
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
# BGP Timers Defaults
|
|
644
|
+
def default_timer_bgp_keepalive_hold
|
|
645
|
+
["#{default_timer_bgp_keepalive}", "#{default_timer_bgp_holdtime}"]
|
|
646
|
+
end
|
|
647
|
+
|
|
648
|
+
def default_timer_bgp_keepalive
|
|
649
|
+
config_get_default('bgp', 'timer_bgp_keepalive')
|
|
650
|
+
end
|
|
651
|
+
|
|
652
|
+
def default_timer_bgp_holdtime
|
|
653
|
+
config_get_default('bgp', 'timer_bgp_hold')
|
|
654
|
+
end
|
|
655
|
+
|
|
656
|
+
def default_timer_bestpath_limit
|
|
657
|
+
config_get_default('bgp', 'timer_bestpath_limit')
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
def default_timer_bestpath_limit_always
|
|
661
|
+
config_get_default('bgp', 'timer_bestpath_limit_always')
|
|
662
|
+
end
|
|
663
|
+
end
|
|
664
|
+
end
|