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

#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_default_metricObject



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

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

#default_log_adjacencyObject



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

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

#default_metricObject



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

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

#default_metric=(metric) ⇒ Object



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

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



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

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

#default_timer_throttle_lsaObject



210
211
212
213
214
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 210

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



220
221
222
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 220

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

#default_timer_throttle_lsa_maxObject



224
225
226
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 224

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

#default_timer_throttle_lsa_startObject



216
217
218
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 216

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

#default_timer_throttle_spfObject



263
264
265
266
267
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 263

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



273
274
275
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 273

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

#default_timer_throttle_spf_maxObject



277
278
279
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 277

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

#default_timer_throttle_spf_startObject



269
270
271
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 269

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



131
132
133
134
135
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 131

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



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 137

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



154
155
156
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 154

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

#router_id=(rid) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 158

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



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

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



190
191
192
193
194
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 190

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



196
197
198
199
200
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 196

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



202
203
204
205
206
207
208
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 202

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



184
185
186
187
188
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 184

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



228
229
230
231
232
233
234
235
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 228

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



243
244
245
246
247
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 243

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



249
250
251
252
253
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 249

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



255
256
257
258
259
260
261
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 255

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



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

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