Class: Cisco::RouterBgpAFAggrAddr
- Inherits:
-
NodeUtil
- Object
- NodeUtil
- Cisco::RouterBgpAFAggrAddr
show all
- Defined in:
- lib/cisco_node_utils/bgp_af_aggr_addr.rb
Overview
node_utils class for bgp address-family aggregate address management
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from NodeUtil
client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?
Constructor Details
#initialize(asn, vrf, af, aggr_addr, instantiate = true) ⇒ RouterBgpAFAggrAddr
Returns a new instance of RouterBgpAFAggrAddr.
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 26
def initialize(asn, vrf, af, aggr_addr, instantiate=true)
@asn = asn
@asn = asn.to_i unless /\d+.\d+/.match(asn.to_s)
@vrf = vrf
@afi, @safi = af
@aa = aggr_addr
temp_af = [@afi.to_s, @safi.to_s]
@bgp_af = RouterBgpAF.afs[@asn][vrf][temp_af]
fail "bgp address family #{@asn} #{vrf} #{af} does not exist" if
@bgp_af.nil?
set_args_keys_default
create if instantiate
end
|
Instance Attribute Details
#aa ⇒ Object
Returns the value of attribute aa.
24
25
26
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 24
def aa
@aa
end
|
#afi ⇒ Object
Returns the value of attribute afi.
24
25
26
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 24
def afi
@afi
end
|
#asn ⇒ Object
Returns the value of attribute asn.
24
25
26
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 24
def asn
@asn
end
|
#safi ⇒ Object
Returns the value of attribute safi.
24
25
26
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 24
def safi
@safi
end
|
#vrf ⇒ Object
Returns the value of attribute vrf.
24
25
26
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 24
def vrf
@vrf
end
|
Class Method Details
.aas ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 40
def self.aas
aa_hash = {}
RouterBgpAF.afs.each do |asn, vrfs|
aa_hash[asn] = {}
vrfs.each do |vrf, afs|
aa_hash[asn][vrf] = {}
afs.each do |af, _obj|
aa_hash[asn][vrf][af] = {}
afi, safi = af
get_args = { asnum: asn, afi: afi, safi: safi }
get_args[:vrf] = vrf unless vrf == 'default'
aa_list = config_get('bgp_af_aa', 'all_aa', get_args)
next if aa_list.nil?
aa_list.each do |aa|
aa_hash[asn][vrf][af][aa] =
RouterBgpAFAggrAddr.new(asn, vrf, af, aa, false)
end
end
end
end
aa_hash
end
|
Instance Method Details
#aa_maps_get ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 94
def aa_maps_get
str = config_get('bgp_af_aa', 'aggr_addr', @get_args)
return if str.nil?
str.slice!('as-set') if str.include?('as-set')
str.slice!('summary-only') if str.include?('summary-only')
str.strip!
return if str.empty?
regexp = Regexp.new(' *(?<admap>advertise-map \S+)?'\
' *(?<sumap>suppress-map \S+)?'\
' *(?<atmap>attribute-map \S+)?')
regexp.match(str)
end
|
#aa_set(attrs) ⇒ Object
The CLI can take many forms like: aggregate-address 1.1.1.1/32 as-set advertise-map adm aggregate-address 1.1.1.1/32 suppress-map sum attribute-map atm aggregate-address 1.1.1.1/32 summary-only aggregate-address 2.2.2.2/32 summary-only
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 185
def aa_set(attrs)
destroy
set_args_keys_default
[:suppress_map,
:advertise_map,
:attribute_map,
].each do |p|
attrs[p] = '' if attrs[p].nil? || attrs[p] == false
send(p.to_s + '=', attrs[p])
end
[:summary_only,
:as_set,
].each do |p|
attrs[p] = false if attrs[p].nil?
send(p.to_s + '=', attrs[p])
end
@set_args[:state] = ''
config_set('bgp_af_aa', 'aggr_addr', @set_args)
end
|
#advertise_map ⇒ Object
135
136
137
138
139
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 135
def advertise_map
val = Utils.(aa_maps_get, 'admap', 'advertise-map')
return default_advertise_map if val.nil?
val
end
|
#advertise_map=(map) ⇒ Object
141
142
143
144
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 141
def advertise_map=(map)
@set_args[:advertise] =
Utils.attach_prefix(map, :advertise, 'advertise-map')
end
|
#as_set ⇒ Object
107
108
109
110
111
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 107
def as_set
str = config_get('bgp_af_aa', 'aggr_addr', @get_args)
return false if str.nil?
str.include?('as-set') ? true : false
end
|
#as_set=(val) ⇒ Object
113
114
115
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 113
def as_set=(val)
@set_args[:as_set] = val ? 'as-set' : ''
end
|
#attribute_map ⇒ Object
165
166
167
168
169
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 165
def attribute_map
val = Utils.(aa_maps_get, 'atmap', 'attribute-map')
return default_attribute_map if val.nil?
val
end
|
#attribute_map=(map) ⇒ Object
171
172
173
174
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 171
def attribute_map=(map)
@set_args[:attribute] =
Utils.attach_prefix(map, :attribute, 'attribute-map')
end
|
#create ⇒ Object
80
81
82
83
84
85
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 80
def create
set_args_keys(state: '', as_set: '', summ: '', advertise: '',
admap: '', suppress: '', sumap: '', attribute: '',
atmap: '')
config_set('bgp_af_aa', 'aggr_addr', @set_args)
end
|
#default_advertise_map ⇒ Object
146
147
148
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 146
def default_advertise_map
config_get_default('bgp_af_aa', 'advertise_map')
end
|
#default_as_set ⇒ Object
117
118
119
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 117
def default_as_set
config_get_default('bgp_af_aa', 'as_set')
end
|
#default_attribute_map ⇒ Object
176
177
178
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 176
def default_attribute_map
config_get_default('bgp_af_aa', 'attribute_map')
end
|
#default_summary_only ⇒ Object
131
132
133
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 131
def default_summary_only
config_get_default('bgp_af_aa', 'summary_only')
end
|
#default_suppress_map ⇒ Object
161
162
163
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 161
def default_suppress_map
config_get_default('bgp_af_aa', 'suppress_map')
end
|
#destroy ⇒ Object
87
88
89
90
91
92
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 87
def destroy
set_args_keys(state: 'no', as_set: '', summ: '', advertise: '',
admap: '', suppress: '', sumap: '', attribute: '',
atmap: '')
config_set('bgp_af_aa', 'aggr_addr', @set_args)
end
|
#set_args_keys(hash = {}) ⇒ Object
rubocop:disable Style/AccessorMethodName
71
72
73
74
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 71
def set_args_keys(hash={})
set_args_keys_default
@set_args = @get_args.merge!(hash) unless hash.empty?
end
|
#set_args_keys_default ⇒ Object
Helper method to delete @set_args hash keys
64
65
66
67
68
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 64
def set_args_keys_default
keys = { asnum: @asn, afi: @afi, safi: @safi, address: @aa }
keys[:vrf] = @vrf unless @vrf == 'default'
@get_args = @set_args = keys
end
|
#summary_only ⇒ Object
121
122
123
124
125
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 121
def summary_only
str = config_get('bgp_af_aa', 'aggr_addr', @get_args)
return false if str.nil?
str.include?('summary-only') ? true : false
end
|
#summary_only=(val) ⇒ Object
127
128
129
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 127
def summary_only=(val)
@set_args[:summ] = val ? 'summary-only' : ''
end
|
#suppress_map ⇒ Object
150
151
152
153
154
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 150
def suppress_map
val = Utils.(aa_maps_get, 'sumap', 'suppress-map')
return default_suppress_map if val.nil?
val
end
|
#suppress_map=(map) ⇒ Object
156
157
158
159
|
# File 'lib/cisco_node_utils/bgp_af_aggr_addr.rb', line 156
def suppress_map=(map)
@set_args[:suppress] =
Utils.attach_prefix(map, :suppress, 'suppress-map')
end
|