Class: Cisco::RouterOspfVrf

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/router_ospf_vrf.rb

Overview

RouterOspfVrf - node utility class for per-VRF OSPF config management

Constant Summary collapse

OSPF_AUTO_COST =
{
  mbps: 'Mbps',
  gbps: 'Gbps',
}
OSPF_LOG_ADJACENCY =
{
  none:   'none',
  log:    '',
  detail: 'detail',
}

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(router, name, instantiate = true) ⇒ RouterOspfVrf

Returns a new instance of RouterOspfVrf.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 36

def initialize(router, name, instantiate=true)
  fail TypeError if router.nil?
  fail TypeError if name.nil?
  fail ArgumentError unless router.length > 0
  fail ArgumentError unless name.length > 0
  @router = router
  @name = name
  @parent = {}
  if @name == 'default'
    @get_args = @set_args = { name: @router }
  else
    @get_args = @set_args = { name: @router, vrf: @name }
  end

  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 23

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



23
24
25
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 23

def parent
  @parent
end

Class Method Details

.vrfsObject

Create a hash of all router ospf vrf instances



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 54

def self.vrfs
  hash_final = {}
  RouterOspf.routers.each do |instance|
    name = instance[0]
    vrf_ids = config_get('ospf', 'vrf', name: name)
    hash_tmp = {
      name => { 'default' => RouterOspfVrf.new(name, 'default', false) }
    }
    unless vrf_ids.nil?
      vrf_ids.each do |vrf|
        hash_tmp[name][vrf] = RouterOspfVrf.new(name, vrf, false)
      end
    end
    hash_final.merge!(hash_tmp)
  end
  hash_final
end

Instance Method Details

#auto_costObject



90
91
92
93
94
95
96
97
98
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 90

def auto_cost
  match = config_get('ospf', 'auto_cost', @get_args)
  return default_auto_cost if match.nil?
  if match.last.nil?
    [match.first.to_i, OSPF_AUTO_COST[:mbps]]
  else
    [match.first.to_i, match.last]
  end
end

#auto_cost_set(cost, type) ⇒ Object



100
101
102
103
104
105
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 100

def auto_cost_set(cost, type)
  @set_args[:cost] = cost
  @set_args[:type] = OSPF_AUTO_COST[type]
  config_set('ospf', 'auto_cost', @set_args)
  delete_set_args_keys([:cost, :type])
end

#bfdObject



111
112
113
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 111

def bfd
  config_get('ospf', 'bfd', @get_args)
end

#bfd=(state) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 115

def bfd=(state)
  return if state == bfd
  no_cmd = (state ? '' : 'no')
  @set_args[:state] = no_cmd
  Feature.bfd_enable
  config_set('ospf', 'bfd', @set_args)
  delete_set_args_keys([:state])
end

#createObject

Create one router ospf vrf instance



73
74
75
76
77
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 73

def create
  @parent = RouterOspf.new(@router)
  config_set('ospf', 'vrf',
             name: @router, state: '', vrf: @name) if @name != 'default'
end

#default_auto_costObject



107
108
109
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 107

def default_auto_cost
  config_get_default('ospf', 'auto_cost')
end

#default_bfdObject



124
125
126
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 124

def default_bfd
  config_get_default('ospf', 'bfd')
end

#default_default_metricObject



144
145
146
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 144

def default_default_metric
  config_get_default('ospf', 'default_metric')
end

#default_log_adjacencyObject



167
168
169
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 167

def default_log_adjacency
  config_get_default('ospf', 'log_adjacency')
end

#default_metricObject



128
129
130
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 128

def default_metric
  config_get('ospf', 'default_metric', @get_args)
end

#default_metric=(metric) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 132

def default_metric=(metric)
  if metric == default_default_metric
    @set_args[:state] = 'no'
    @set_args[:metric] = ''
  else
    @set_args[:state] = ''
    @set_args[:metric] = metric
  end
  config_set('ospf', 'default_metric', @set_args)
  delete_set_args_keys([:state, :metric])
end

#default_router_idObject



188
189
190
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 188

def default_router_id
  config_get_default('ospf', 'router_id')
end

#default_timer_throttle_lsaObject



227
228
229
230
231
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 227

def default_timer_throttle_lsa
  [default_timer_throttle_lsa_start,
   default_timer_throttle_lsa_hold,
   default_timer_throttle_lsa_max]
end

#default_timer_throttle_lsa_holdObject



237
238
239
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 237

def default_timer_throttle_lsa_hold
  config_get_default('ospf', 'timer_throttle_lsa_hold')
end

#default_timer_throttle_lsa_maxObject



241
242
243
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 241

def default_timer_throttle_lsa_max
  config_get_default('ospf', 'timer_throttle_lsa_max')
end

#default_timer_throttle_lsa_startObject



233
234
235
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 233

def default_timer_throttle_lsa_start
  config_get_default('ospf', 'timer_throttle_lsa_start')
end

#default_timer_throttle_spfObject



280
281
282
283
284
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 280

def default_timer_throttle_spf
  [default_timer_throttle_spf_start,
   default_timer_throttle_spf_hold,
   default_timer_throttle_spf_max]
end

#default_timer_throttle_spf_holdObject



290
291
292
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 290

def default_timer_throttle_spf_hold
  config_get_default('ospf', 'timer_throttle_spf_hold')
end

#default_timer_throttle_spf_maxObject



294
295
296
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 294

def default_timer_throttle_spf_max
  config_get_default('ospf', 'timer_throttle_spf_max')
end

#default_timer_throttle_spf_startObject



286
287
288
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 286

def default_timer_throttle_spf_start
  config_get_default('ospf', 'timer_throttle_spf_start')
end

#delete_set_args_keys(list) ⇒ Object

Helper method to delete @set_args hash keys



86
87
88
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 86

def delete_set_args_keys(list)
  list.each { |key| @set_args.delete(key) }
end

#destroyObject

Destroy one router ospf vrf instance



80
81
82
83
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 80

def destroy
  fail RuntimeError if @name == 'default'
  config_set('ospf', 'vrf', name: @router, state: 'no', vrf: @name)
end

#log_adjacencyObject



148
149
150
151
152
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 148

def log_adjacency
  match = config_get('ospf', 'log_adjacency', @get_args)
  return default_log_adjacency if match.nil?
  match.flatten.last.nil? ? :log : :detail
end

#log_adjacency=(type) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 154

def log_adjacency=(type)
  case type
  when :none
    @set_args[:state] = 'no'
    @set_args[:type] = ''
  when :log, :detail
    @set_args[:state] = ''
    @set_args[:type] = OSPF_LOG_ADJACENCY[type]
  end
  config_set('ospf', 'log_adjacency', @set_args)
  delete_set_args_keys([:state, :type])
end

#router_idObject



171
172
173
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 171

def router_id
  config_get('ospf', 'router_id', @get_args)
end

#router_id=(rid) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 175

def router_id=(rid)
  if rid == default_router_id
    @set_args[:state] = 'no'
    @set_args[:router_id] = router_id
  else
    @set_args[:state] = ''
    @set_args[:router_id] = rid
  end

  config_set('ospf', 'router_id', @set_args)
  delete_set_args_keys([:state, :router_id])
end

#timer_throttle_lsaObject



192
193
194
195
196
197
198
199
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 192

def timer_throttle_lsa
  match = config_get('ospf', 'timer_throttle_lsa', @get_args)
  if match.nil?
    default_timer_throttle_lsa
  else
    match.collect(&:to_i)
  end
end

#timer_throttle_lsa_holdObject



207
208
209
210
211
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 207

def timer_throttle_lsa_hold
  _start, hold, _max = timer_throttle_lsa
  return default_timer_throttle_lsa_hold if hold.nil?
  hold
end

#timer_throttle_lsa_maxObject



213
214
215
216
217
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 213

def timer_throttle_lsa_max
  _start, _hold, max = timer_throttle_lsa
  return default_timer_throttle_lsa_max if max.nil?
  max
end

#timer_throttle_lsa_set(start, hold, max) ⇒ Object



219
220
221
222
223
224
225
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 219

def timer_throttle_lsa_set(start, hold, max)
  @set_args[:start] = start
  @set_args[:hold] = hold
  @set_args[:max] = max
  config_set('ospf', 'timer_throttle_lsa', @set_args)
  delete_set_args_keys([:start, :hold, :max])
end

#timer_throttle_lsa_startObject



201
202
203
204
205
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 201

def timer_throttle_lsa_start
  start, _hold, _max = timer_throttle_lsa
  return default_timer_throttle_lsa_start if start.nil?
  start
end

#timer_throttle_spfObject



245
246
247
248
249
250
251
252
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 245

def timer_throttle_spf
  match = config_get('ospf', 'timer_throttle_spf', @get_args)
  if match.nil?
    default_timer_throttle_spf
  else
    match.collect(&:to_i)
  end
end

#timer_throttle_spf_holdObject



260
261
262
263
264
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 260

def timer_throttle_spf_hold
  _start, hold, _max = timer_throttle_spf
  return default_timer_throttle_spf_hold if hold.nil?
  hold
end

#timer_throttle_spf_maxObject



266
267
268
269
270
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 266

def timer_throttle_spf_max
  _start, _hold, max = timer_throttle_spf
  return default_timer_throttle_spf_max if max.nil?
  max
end

#timer_throttle_spf_set(start, hold, max) ⇒ Object



272
273
274
275
276
277
278
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 272

def timer_throttle_spf_set(start, hold, max)
  @set_args[:start] = start
  @set_args[:hold] = hold
  @set_args[:max] = max
  config_set('ospf', 'timer_throttle_spf', @set_args)
  delete_set_args_keys([:start, :hold, :max])
end

#timer_throttle_spf_startObject



254
255
256
257
258
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 254

def timer_throttle_spf_start
  start, _hold, _max = timer_throttle_spf
  return default_timer_throttle_spf_start if start.nil?
  start
end