Class: Cisco::RouterOspf

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

Overview

RouterOspf - node utility class for process-level OSPF config management

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

config_get, #config_get, config_get_default, #config_get_default, #config_set, config_set, #node, node, #show

Constructor Details

#initialize(name, instantiate = true) ⇒ RouterOspf

Returns a new instance of RouterOspf.



24
25
26
27
28
29
# File 'lib/cisco_node_utils/router_ospf.rb', line 24

def initialize(name, instantiate=true)
  fail ArgumentError unless name.length > 0
  @name = name

  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/cisco_node_utils/router_ospf.rb', line 22

def name
  @name
end

Class Method Details

.enable(state = '') ⇒ Object



56
57
58
# File 'lib/cisco_node_utils/router_ospf.rb', line 56

def self.enable(state='')
  config_set('ospf', 'feature', state)
end

.enabledObject



47
48
49
50
51
52
53
54
# File 'lib/cisco_node_utils/router_ospf.rb', line 47

def self.enabled
  feat = config_get('ospf', 'feature')
  return (!feat.nil? && !feat.empty?)
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled
  raise unless e.clierror =~ /Syntax error/
  return false
end

.routersObject

Create a hash of all router ospf instances



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cisco_node_utils/router_ospf.rb', line 32

def self.routers
  ospf_ids = config_get('ospf', 'router')
  return {} if ospf_ids.nil?

  hash = {}
  ospf_ids.each do |name|
    hash[name] = RouterOspf.new(name, false)
  end
  return hash
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled
  raise unless e.clierror =~ /Syntax error/
  return {}
end

Instance Method Details

#createObject

Create one router ospf instance



70
71
72
73
74
75
76
# File 'lib/cisco_node_utils/router_ospf.rb', line 70

def create
  if RouterOspf.enabled
    ospf_router(name)
  else
    enable_create_router_ospf(name)
  end
end

#destroyObject

Destroy one router ospf instance



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cisco_node_utils/router_ospf.rb', line 79

def destroy
  ospf_ids = config_get('ospf', 'router')
  return if ospf_ids.nil?
  if ospf_ids.size == 1
    RouterOspf.enable('no')
  else
    ospf_router(name, 'no')
  end
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled
  raise unless e.clierror =~ /Syntax error/
end

#enable_create_router_ospf(name) ⇒ Object



64
65
66
67
# File 'lib/cisco_node_utils/router_ospf.rb', line 64

def enable_create_router_ospf(name)
  RouterOspf.enable
  ospf_router(name)
end

#ospf_router(name, state = '') ⇒ Object



60
61
62
# File 'lib/cisco_node_utils/router_ospf.rb', line 60

def ospf_router(name, state='')
  config_set('ospf', 'router', state, name)
end