Class: Cisco::RouterOspfAreaVirtualLink

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

Overview

node_utils class for ospf_area_vlink

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(ospf_router, vrf_name, area_id, virtual_link, instantiate = true) ⇒ RouterOspfAreaVirtualLink


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 28

def initialize(ospf_router, vrf_name, area_id, virtual_link,
               instantiate=true)
  fail TypeError unless ospf_router.is_a?(String)
  fail TypeError unless vrf_name.is_a?(String)
  fail ArgumentError unless ospf_router.length > 0
  fail ArgumentError unless vrf_name.length > 0
  @area_id = area_id.to_s
  fail ArgumentError if @area_id.empty?
  fail ArgumentError unless virtual_link.length > 0

  # Convert to dot-notation
  @router = ospf_router
  @vrf = vrf_name
  @area_id = IPAddr.new(area_id.to_i, Socket::AF_INET) unless @area_id[/\./]
  @vl = virtual_link

  set_args_keys_default
  create if instantiate
end

Instance Attribute Details

#area_idObject (readonly)

Returns the value of attribute area_id


26
27
28
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 26

def area_id
  @area_id
end

#routerObject (readonly)

Returns the value of attribute router


26
27
28
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 26

def router
  @router
end

#vlObject (readonly)

Returns the value of attribute vl


26
27
28
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 26

def vl
  @vl
end

#vrfObject (readonly)

Returns the value of attribute vrf


26
27
28
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 26

def vrf
  @vrf
end

Class Method Details


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 48

def self.virtual_links
  hash = {}
  RouterOspf.routers.each do |name, _obj|
    # get all virtual_links under default vrf
    links = config_get('ospf_area_vlink', 'virtual_links', name: name)
    unless links.nil?
      hash[name] = {}
      hash[name]['default'] = {}
      links.each do |area, vl|
        hash[name]['default'][area] ||= {}
        hash[name]['default'][area][vl] =
          RouterOspfAreaVirtualLink.new(name, 'default', area, vl, false)
      end
    end
    vrf_ids = config_get('ospf', 'vrf', name: name)
    next if vrf_ids.nil?
    vrf_ids.each do |vrf|
      # get all virtual_links under each vrf
      links = config_get('ospf_area_vlink', 'virtual_links',
                         name: name, vrf: vrf)
      next if links.nil?
      hash[name] ||= {}
      hash[name][vrf] = {}
      links.each do |area, vl|
        hash[name][vrf][area] ||= {}
        hash[name][vrf][area][vl] =
          RouterOspfAreaVirtualLink.new(name, vrf, area, vl, false)
      end
    end
  end
  hash
end

Instance Method Details

#==(other) ⇒ Object


107
108
109
110
111
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 107

def ==(other)
  (ospf_router == other.ospf_router) &&
    (vrf_name == other.vrf_name) && (area_id == other.area_id) &&
    (vl == other.vl)
end

#auth_key_chainObject


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

def auth_key_chain
  config_get('ospf_area_vlink', 'auth_key_chain', @get_args)
end

#auth_key_chain=(val) ⇒ Object


154
155
156
157
158
159
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 154

def auth_key_chain=(val)
  state = val ? '' : 'no'
  id = val ? val : ''
  set_args_keys(state: state, key_id: id)
  config_set('ospf_area_vlink', 'auth_key_chain', @set_args)
end

#authenticationObject

CLI can be either of the following or none authentication authentication message-digest authentication null


121
122
123
124
125
126
127
128
129
130
131
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 121

def authentication
  auth = config_get('ospf_area_vlink', 'authentication', @get_args)
  return default_authentication unless auth
  if auth.include?('message-digest')
    return 'md5'
  elsif auth.include?('null')
    return 'null'
  else
    return 'cleartext'
  end
end

#authentication=(val) ⇒ Object


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

def authentication=(val)
  state = val ? '' : 'no'
  if val.to_s == 'md5'
    auth = 'message-digest'
  elsif val.to_s == 'null'
    auth = 'null'
  else
    auth = ''
  end
  set_args_keys(state: state, auth: auth)
  config_set('ospf_area_vlink', 'authentication', @set_args)
end

#authentication_key_encryption_typeObject


165
166
167
168
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 165

def authentication_key_encryption_type
  Encryption.cli_to_symbol(
    config_get('ospf_area_vlink', 'authentication_key_enc_type', @get_args))
end

#authentication_key_passwordObject


175
176
177
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 175

def authentication_key_password
  config_get('ospf_area_vlink', 'authentication_key_password', @get_args)
end

#authentication_key_set(enctype, pw) ⇒ Object

example CLI: authentication-key 3 3109a60f51374a0d To remove the authentication-key altogether, set the password to empty string


187
188
189
190
191
192
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 187

def authentication_key_set(enctype, pw)
  state = pw.empty? ? 'no' : ''
  enctype = pw.empty? ? '' : Encryption.symbol_to_cli(enctype)
  set_args_keys(state: state, enctype: enctype, password: pw)
  config_set('ospf_area_vlink', 'authentication_key_set', @set_args)
end

#createObject

Create one router ospf area virtual-link instance


95
96
97
98
99
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 95

def create
  RouterOspfVrf.new(@router, @vrf)
  set_args_keys(state: '')
  config_set('ospf_area_vlink', 'virtual_links', @set_args)
end

#dead_intervalObject


253
254
255
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 253

def dead_interval
  config_get('ospf_area_vlink', 'dead_interval', @get_args)
end

#dead_interval=(val) ⇒ Object


257
258
259
260
261
262
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 257

def dead_interval=(val)
  state = val == default_dead_interval ? 'no' : ''
  interval = val == default_dead_interval ? '' : val
  set_args_keys(state: state, interval: interval)
  config_set('ospf_area_vlink', 'dead_interval', @set_args)
end

#default_auth_key_chainObject


161
162
163
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 161

def default_auth_key_chain
  config_get_default('ospf_area_vlink', 'auth_key_chain')
end

#default_authenticationObject


146
147
148
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 146

def default_authentication
  config_get_default('ospf_area_vlink', 'authentication')
end

#default_authentication_key_encryption_typeObject


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

def default_authentication_key_encryption_type
  Encryption.cli_to_symbol(
    config_get_default('ospf_area_vlink', 'authentication_key_enc_type'))
end

#default_authentication_key_passwordObject


179
180
181
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 179

def default_authentication_key_password
  config_get_default('ospf_area_vlink', 'authentication_key_password')
end

#default_dead_intervalObject


264
265
266
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 264

def default_dead_interval
  config_get_default('ospf_area_vlink', 'dead_interval')
end

#default_hello_intervalObject


279
280
281
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 279

def default_hello_interval
  config_get_default('ospf_area_vlink', 'hello_interval')
end

#default_message_digest_algorithm_typeObject


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

def default_message_digest_algorithm_type
  config_get_default('ospf_area_vlink',
                     'message_digest_key_alg_type').to_sym
end

#default_message_digest_encryption_typeObject


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

def default_message_digest_encryption_type
  Encryption.cli_to_symbol(
    config_get_default('ospf_area_vlink', 'message_digest_key_enc_type'))
end

#default_message_digest_key_idObject


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

def default_message_digest_key_id
  config_get_default('ospf_area_vlink', 'message_digest_key_id')
end

#default_message_digest_passwordObject


226
227
228
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 226

def default_message_digest_password
  config_get_default('ospf_area_vlink', 'message_digest_key_password')
end

#default_retransmit_intervalObject


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

def default_retransmit_interval
  config_get_default('ospf_area_vlink', 'retransmit_interval')
end

#default_transmit_delayObject


309
310
311
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 309

def default_transmit_delay
  config_get_default('ospf_area_vlink', 'transmit_delay')
end

#destroyObject


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

def destroy
  return unless Feature.ospf_enabled?
  set_args_keys(state: 'no')
  config_set('ospf_area_vlink', 'virtual_links', @set_args)
end

#hello_intervalObject


268
269
270
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 268

def hello_interval
  config_get('ospf_area_vlink', 'hello_interval', @get_args)
end

#hello_interval=(val) ⇒ Object


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

def hello_interval=(val)
  state = val == default_hello_interval ? 'no' : ''
  interval = val == default_hello_interval ? '' : val
  set_args_keys(state: state, interval: interval)
  config_set('ospf_area_vlink', 'hello_interval', @set_args)
end

#message_digest_algorithm_typeObject


194
195
196
197
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 194

def message_digest_algorithm_type
  config_get('ospf_area_vlink', 'message_digest_key_alg_type',
             @get_args).to_sym
end

#message_digest_encryption_typeObject


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

def message_digest_encryption_type
  Encryption.cli_to_symbol(
    config_get('ospf_area_vlink', 'message_digest_key_enc_type', @get_args))
end

#message_digest_key_idObject


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

def message_digest_key_id
  config_get('ospf_area_vlink', 'message_digest_key_id', @get_args)
end

#message_digest_key_set(keyid, algtype, enctype, pw) ⇒ Object

example CLI: message-digest-key 39 md5 7 046E1803362E595C260E0B240619050A2D To remove the message-digest-key altogether, set the password to empty string


234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 234

def message_digest_key_set(keyid, algtype, enctype, pw)
  return if pw.empty? && message_digest_password.empty?
  # To remove the configuration, the entire previous
  # configuration must be given with 'no' cmd
  state = pw.empty? ? 'no' : ''
  algtype = pw.empty? ? message_digest_algorithm_type : algtype.to_s
  if pw.empty?
    enctype = Encryption.symbol_to_cli(
      message_digest_encryption_type.to_sym)
  else
    enctype = Encryption.symbol_to_cli(enctype)
  end
  keyid = pw.empty? ? message_digest_key_id : keyid
  pw = pw.empty? ? message_digest_password : pw
  set_args_keys(state: state, keyid: keyid, algtype: algtype,
                enctype: enctype, password: pw)
  config_set('ospf_area_vlink', 'message_digest_key_set', @set_args)
end

#message_digest_passwordObject


222
223
224
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 222

def message_digest_password
  config_get('ospf_area_vlink', 'message_digest_key_password', @get_args)
end

#retransmit_intervalObject


283
284
285
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 283

def retransmit_interval
  config_get('ospf_area_vlink', 'retransmit_interval', @get_args)
end

#retransmit_interval=(val) ⇒ Object


287
288
289
290
291
292
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 287

def retransmit_interval=(val)
  state = val == default_retransmit_interval ? 'no' : ''
  interval = val == default_retransmit_interval ? '' : val
  set_args_keys(state: state, interval: interval)
  config_set('ospf_area_vlink', 'retransmit_interval', @set_args)
end

#set_args_keys(hash = {}) ⇒ Object

rubocop:disable Style/AccessorMethodName


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

def set_args_keys(hash={})
  set_args_keys_default
  @set_args = @get_args.merge!(hash) unless hash.empty?
end

#set_args_keys_defaultObject

Helper method to delete @set_args hash keys


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

def set_args_keys_default
  @set_args = { name: @router, area: @area_id, vl: @vl }
  @set_args[:vrf] = @vrf unless @vrf == 'default'
  @get_args = @set_args
end

#transmit_delayObject


298
299
300
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 298

def transmit_delay
  config_get('ospf_area_vlink', 'transmit_delay', @get_args)
end

#transmit_delay=(val) ⇒ Object


302
303
304
305
306
307
# File 'lib/cisco_node_utils/router_ospf_area_vlink.rb', line 302

def transmit_delay=(val)
  state = val == default_transmit_delay ? 'no' : ''
  delay = val == default_transmit_delay ? '' : val
  set_args_keys(state: state, delay: delay)
  config_set('ospf_area_vlink', 'transmit_delay', @set_args)
end