Class: Cisco::RouterOspf

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

Constant Summary collapse

@@node =
Cisco::Node.instance

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, instantiate = true) ⇒ RouterOspf

Returns a new instance of RouterOspf.

Raises:

  • (ArgumentError)


28
29
30
31
32
33
# File 'lib/cisco_node_utils/router_ospf.rb', line 28

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

  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.enable(state = "") ⇒ Object



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

def RouterOspf.enable(state="")
  @@node.config_set("ospf", "feature", state)
end

.enabledObject



51
52
53
54
55
56
57
58
# File 'lib/cisco_node_utils/router_ospf.rb', line 51

def RouterOspf.enabled
  feat =  @@node.config_get("ospf", "feature")
  return (!feat.nil? and !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



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

def RouterOspf.routers
  ospf_ids = @@node.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



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

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

#destroyObject

Destroy one router ospf instance



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cisco_node_utils/router_ospf.rb', line 83

def destroy
  ospf_ids = @@node.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



68
69
70
71
# File 'lib/cisco_node_utils/router_ospf.rb', line 68

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

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



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

def ospf_router(name, state="")
  @@node.config_set("ospf", "router", state, name)
end