Class: Cisco::RouterOspfVrf

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

Constant Summary collapse

OSPF_AUTO_COST =
{
  :mbps => "Mbps",
  :gbps => "Gbps",
}
OSPF_LOG_ADJACENCY =
{
  :none   => "none",
  :log    => "",
  :detail => "detail",
}
@@node =
Cisco::Node.instance

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router, name, instantiate = true) ⇒ RouterOspfVrf

Returns a new instance of RouterOspfVrf.

Raises:

  • (TypeError)


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

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

  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 25

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



25
26
27
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 25

def parent
  @parent
end

Class Method Details

.vrfsObject

Create a hash of all router ospf vrf instances



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 55

def RouterOspfVrf.vrfs
  hash_final = {}
  RouterOspf.routers.each do |instance|
    name = instance[0]
    vrf_ids = @@node.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



94
95
96
97
98
99
100
101
102
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 94

def auto_cost
  match = @@node.config_get("ospf", "auto_cost", @get_args)
  return default_auto_cost if match.nil?
  # Multiple matches are possible but the first match is used.
  # This can be removed when rally defect DE3614 is resolved.
  match[0].last.nil? ?
    [match[0].first.to_i, OSPF_AUTO_COST[:mbps]] :
    [match[0].first.to_i, match[0].last]
end

#auto_cost_set(cost, type) ⇒ Object



104
105
106
107
108
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 104

def auto_cost_set(cost, type)
  @set_args[:cost], @set_args[:type] = cost, OSPF_AUTO_COST[type]
  @@node.config_set("ospf", "auto_cost", @set_args)
  set_args_keys_delete([:cost, :type])
end

#createObject

Create one router ospf vrf instance



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

def create
  @parent = RouterOspf.new(@router)
  @@node.config_set("ospf", "vrf", { :name  => @router,
                                     :state => "",
                                     :vrf   => @name }) if
                                    @name != "default"
end

#default_auto_costObject



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

def default_auto_cost
  @@node.config_get_default("ospf", "auto_cost")
end

#default_default_metricObject



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

def default_default_metric
  @@node.config_get_default("ospf", "default_metric")
end

#default_log_adjacencyObject



152
153
154
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 152

def default_log_adjacency
  @@node.config_get_default("ospf", "log_adjacency")
end

#default_metricObject



114
115
116
117
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 114

def default_metric
  match = @@node.config_get("ospf", "default_metric", @get_args)
  match.nil? ? default_default_metric : match.first.to_i
end

#default_metric=(metric) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 119

def default_metric=(metric)
  if metric == default_default_metric
    @set_args[:state], @set_args[:metric] = "no", ""
  else
    @set_args[:state], @set_args[:metric] = "", metric
  end
  @@node.config_set("ospf", "default_metric", @set_args)
  set_args_keys_delete([:state, :metric])
end

#default_router_idObject



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

def default_router_id
  @@node.config_get_default("ospf", "router_id")
end

#default_timer_throttle_lsaObject



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

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



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

def default_timer_throttle_lsa_hold
  @@node.config_get_default("ospf", "timer_throttle_lsa_hold")
end

#default_timer_throttle_lsa_maxObject



218
219
220
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 218

def default_timer_throttle_lsa_max
  @@node.config_get_default("ospf", "timer_throttle_lsa_max")
end

#default_timer_throttle_lsa_startObject



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

def default_timer_throttle_lsa_start
  @@node.config_get_default("ospf", "timer_throttle_lsa_start")
end

#default_timer_throttle_spfObject



252
253
254
255
256
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 252

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



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

def default_timer_throttle_spf_hold
  @@node.config_get_default("ospf", "timer_throttle_spf_hold")
end

#default_timer_throttle_spf_maxObject



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

def default_timer_throttle_spf_max
  @@node.config_get_default("ospf", "timer_throttle_spf_max")
end

#default_timer_throttle_spf_startObject



258
259
260
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 258

def default_timer_throttle_spf_start
  @@node.config_get_default("ospf", "timer_throttle_spf_start")
end

#destroyObject

Destroy one router ospf vrf instance

Raises:

  • (RuntimeError)


82
83
84
85
86
87
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 82

def destroy
  raise RuntimeError if @name == "default"
  @@node.config_set("ospf", "vrf", { :name  => @router,
                                     :state => "no",
                                     :vrf   => @name })
end

#log_adjacencyObject



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

def log_adjacency
  match = @@node.config_get("ospf", "log_adjacency", @get_args)
  return default_log_adjacency if match.nil?
  # Multiple matches are possible but the first match is used.
  # This can be removed when rally defect DE3614 is resolved.
  match[0].flatten.last.nil? ? :log : :detail
end

#log_adjacency=(type) ⇒ Object



141
142
143
144
145
146
147
148
149
150
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 141

def log_adjacency=(type)
  case type
  when :none
      @set_args[:state], @set_args[:type] = "no", ""
  when :log, :detail
      @set_args[:state], @set_args[:type] = "", OSPF_LOG_ADJACENCY[type]
  end
  @@node.config_set("ospf", "log_adjacency", @set_args)
  set_args_keys_delete([:state, :type])
end

#router_idObject



156
157
158
159
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 156

def router_id
  match = @@node.config_get("ospf", "router_id", @get_args)
  match.nil? ? default_router_id : match.first
end

#router_id=(router_id) ⇒ Object



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

def router_id=(router_id)
  router_id == default_router_id ?
    (@set_args[:state], @set_args[:router_id] = "no", "") :
    (@set_args[:state], @set_args[:router_id] = "", router_id)

  @@node.config_set("ospf", "router_id", @set_args)
  set_args_keys_delete([:state, :router_id])
end

#set_args_keys_delete(list) ⇒ Object

Helper method to delete @set_args hash keys



90
91
92
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 90

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

#timer_throttle_lsaObject



174
175
176
177
178
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 174

def timer_throttle_lsa
  match = @@node.config_get("ospf", "timer_throttle_lsa", @get_args)
  (match.nil? or match.first.nil?) ? default_timer_throttle_lsa :
    match.first.collect(&:to_i)
end

#timer_throttle_lsa_holdObject



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

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



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

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



198
199
200
201
202
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 198

def timer_throttle_lsa_set(start, hold, max)
  @set_args[:start], @set_args[:hold], @set_args[:max] = start, hold, max
  @@node.config_set("ospf", "timer_throttle_lsa", @set_args)
  set_args_keys_delete([:start, :hold, :max])
end

#timer_throttle_lsa_startObject



180
181
182
183
184
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 180

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



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

def timer_throttle_spf
  match = @@node.config_get("ospf", "timer_throttle_spf", @get_args)
  (match.nil? or match.first.nil?) ? default_timer_throttle_spf :
    match.first.collect(&:to_i)
end

#timer_throttle_spf_holdObject



234
235
236
237
238
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 234

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



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

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



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

def timer_throttle_spf_set(start, hold, max)
  @set_args[:start], @set_args[:hold], @set_args[:max] = start, hold, max
  @@node.config_set("ospf", "timer_throttle_spf", @set_args)
  set_args_keys_delete([:start, :hold, :max])
end

#timer_throttle_spf_startObject



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

def timer_throttle_spf_start
  start, hold, max = timer_throttle_spf
  return default_timer_throttle_spf_start if start.nil?
  start
end