Class: Cisco::InterfaceOspf

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

Constant Summary collapse

@@node =
Node.instance

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(int_name, ospf_name, area, create = true) ⇒ InterfaceOspf

Returns a new instance of InterfaceOspf.

Raises:

  • (TypeError)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cisco_node_utils/interface_ospf.rb', line 32

def initialize(int_name, ospf_name, area, create=true)
  raise TypeError unless int_name.is_a? String
  raise TypeError unless ospf_name.is_a? String
  raise TypeError unless area.is_a? String
  raise ArgumentError unless int_name.length > 0
  raise ArgumentError unless ospf_name.length > 0
  raise ArgumentError unless area.length > 0

  # normalize
  int_name = int_name.downcase
  @interface = Interface.interfaces[int_name]
  raise "interface #{int_name} does not exist" if @interface.nil?

  @ospf_name = ospf_name

  if create
    # enable feature ospf if it isn't
    RouterOspf.enable unless RouterOspf.enabled

    @@node.config_set("interface_ospf", "area", @interface.name,
      "", @ospf_name, area)
  end
end

Instance Attribute Details

#interfaceObject (readonly)

Returns the value of attribute interface.



28
29
30
# File 'lib/cisco_node_utils/interface_ospf.rb', line 28

def interface
  @interface
end

#ospf_nameObject (readonly)

Returns the value of attribute ospf_name.



28
29
30
# File 'lib/cisco_node_utils/interface_ospf.rb', line 28

def ospf_name
  @ospf_name
end

Class Method Details

.interfaces(ospf_name = nil) ⇒ Object

can’t re-use Interface.interfaces because we need to filter based on “ip router ospf <name>”, which Interface doesn’t retrieve

Raises:

  • (TypeError)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cisco_node_utils/interface_ospf.rb', line 58

def InterfaceOspf.interfaces(ospf_name=nil)
  raise TypeError unless ospf_name.is_a? String or ospf_name.nil?
  ints = {}

  intf_list = @@node.config_get("interface", "all_interfaces")
  return ints if intf_list.nil?
  intf_list.each do |name|
    match = @@node.config_get("interface_ospf", "area", name)
    next if match.nil?
    # should only be a single match under a given interface
    match = match.first
    # ip router ospf <name> area <area>
    ospf = match[0]
    area = match[1]
    next unless ospf_name.nil? or ospf == ospf_name
    int = name.downcase
    ints[int] = InterfaceOspf.new(int, ospf, area, false)
  end
  ints
end

Instance Method Details

#areaObject



79
80
81
82
83
84
85
86
# File 'lib/cisco_node_utils/interface_ospf.rb', line 79

def area
  match = @@node.config_get("interface_ospf", "area", @interface.name)
  return nil if match.nil?
  val = match[0][1]
  # Coerce numeric area to the expected dot-decimal format.
  val = IPAddr.new(val.to_i, Socket::AF_INET).to_s unless val.match(/\./)
  val
end

#area=(a) ⇒ Object



88
89
90
91
# File 'lib/cisco_node_utils/interface_ospf.rb', line 88

def area=(a)
  @@node.config_set("interface_ospf", "area", @interface.name,
    "", @ospf_name, a)
end

#costObject



182
183
184
185
186
# File 'lib/cisco_node_utils/interface_ospf.rb', line 182

def cost
  match = @@node.config_get("interface_ospf", "cost", @interface.name)
  # regex in yaml returns an array result, use .first to get match
  match.nil? ? default_cost : match.first.to_i
end

#cost=(c) ⇒ Object

interface %s

ip ospf cost %d


194
195
196
197
198
199
200
# File 'lib/cisco_node_utils/interface_ospf.rb', line 194

def cost=(c)
  if c == default_cost
    @@node.config_set("interface_ospf", "cost", @interface.name, "no", "")
  else
    @@node.config_set("interface_ospf", "cost", @interface.name, "", c)
  end
end

#dead_intervalObject



220
221
222
223
224
225
# File 'lib/cisco_node_utils/interface_ospf.rb', line 220

def dead_interval
  match = @@node.config_get("interface_ospf", "dead_interval",
                            @interface.name)
  # regex in yaml returns an array result, use .first to get match
  match.nil? ? default_dead_interval : match.first.to_i
end

#dead_interval=(interval) ⇒ Object

interface %s

ip ospf dead-interval d


233
234
235
236
# File 'lib/cisco_node_utils/interface_ospf.rb', line 233

def dead_interval=(interval)
  @@node.config_set("interface_ospf", "dead_interval",
                    @interface.name, "", interval.to_i)
end

#default_costObject



188
189
190
# File 'lib/cisco_node_utils/interface_ospf.rb', line 188

def default_cost
  @@node.config_get_default("interface_ospf", "cost")
end

#default_dead_intervalObject



227
228
229
# File 'lib/cisco_node_utils/interface_ospf.rb', line 227

def default_dead_interval
  @@node.config_get_default("interface_ospf", "dead_interval")
end

#default_hello_intervalObject



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

def default_hello_interval
  @@node.config_get_default("interface_ospf", "hello_interval")
end

#default_message_digestObject



106
107
108
# File 'lib/cisco_node_utils/interface_ospf.rb', line 106

def default_message_digest
  @@node.config_get_default("interface_ospf", "message_digest")
end

#default_message_digest_algorithm_typeObject



133
134
135
136
# File 'lib/cisco_node_utils/interface_ospf.rb', line 133

def default_message_digest_algorithm_type
  @@node.config_get_default("interface_ospf",
                            "message_digest_alg_type").to_sym
end

#default_message_digest_encryption_typeObject



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

def default_message_digest_encryption_type
  Encryption.cli_to_symbol(
    @@node.config_get_default("interface_ospf", "message_digest_enc_type"))
end

#default_message_digest_key_idObject



122
123
124
# File 'lib/cisco_node_utils/interface_ospf.rb', line 122

def default_message_digest_key_id
  @@node.config_get_default("interface_ospf", "message_digest_key_id")
end

#default_passive_interfaceObject



238
239
240
# File 'lib/cisco_node_utils/interface_ospf.rb', line 238

def default_passive_interface
  @@node.config_get_default("interface_ospf", "passive_interface")
end

#destroyObject



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cisco_node_utils/interface_ospf.rb', line 93

def destroy
  @@node.config_set("interface_ospf", "area", @interface.name,
    "no", @ospf_name, area)
  # Reset everything else back to default as well:
  self.message_digest = default_message_digest
  message_digest_key_set(default_message_digest_key_id, "", "", "")
  self.cost = default_cost
  self.hello_interval = default_hello_interval
  @@node.config_set("interface_ospf", "dead_interval",
                    @interface.name, "no", "")
  self.passive_interface = default_passive_interface if passive_interface
end

#hello_intervalObject



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

def hello_interval
  match = @@node.config_get("interface_ospf", "hello_interval",
                            @interface.name)
  # regex in yaml returns an array result, use .first to get match
  match.nil? ? default_hello_interval : match.first.to_i
end

#hello_interval=(interval) ⇒ Object

interface %s

ip ospf hello-interval d


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

def hello_interval=(interval)
  @@node.config_set("interface_ospf", "hello_interval",
                    @interface.name, "", interval.to_i)
end

#message_digestObject



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

def message_digest
  not @@node.config_get("interface_ospf", "message_digest",
                        @interface.name).nil?
end

#message_digest=(enable) ⇒ Object

interface %s

s ip ospf authentication message-digest


117
118
119
120
# File 'lib/cisco_node_utils/interface_ospf.rb', line 117

def message_digest=(enable)
  @@node.config_set("interface_ospf", "message_digest", @interface.name,
                    enable ? "" : "no")
end

#message_digest_algorithm_typeObject



138
139
140
141
142
143
144
# File 'lib/cisco_node_utils/interface_ospf.rb', line 138

def message_digest_algorithm_type
  match = @@node.config_get("interface_ospf", "message_digest_alg_type",
                            @interface.name)
  # regex in yaml returns an array result, use .first to get match
  match.nil? ? default_message_digest_algorithm_type :
    match.first.to_sym
end

#message_digest_encryption_typeObject



151
152
153
154
155
156
157
# File 'lib/cisco_node_utils/interface_ospf.rb', line 151

def message_digest_encryption_type
  match = @@node.config_get("interface_ospf", "message_digest_enc_type",
                            @interface.name)
  # regex in yaml returns an array result, use .first to get match
  match.nil? ? default_message_digest_encryption_type :
    Encryption.cli_to_symbol(match.first)
end

#message_digest_key_idObject



126
127
128
129
130
131
# File 'lib/cisco_node_utils/interface_ospf.rb', line 126

def message_digest_key_id
  match = @@node.config_get("interface_ospf", "message_digest_key_id",
                            @interface.name)
  # regex in yaml returns an array result, use .first to get match
  match.nil? ? default_message_digest_key_id : match.first.to_i
end

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

interface %s

s ip ospf message-digest-key d %s d %s


167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/cisco_node_utils/interface_ospf.rb', line 167

def message_digest_key_set(keyid, algtype, enctype, enc)
  current_keyid = message_digest_key_id
  if keyid == default_message_digest_key_id && current_keyid != keyid
    @@node.config_set("interface_ospf", "message_digest_key_set",
                      @interface.name, "no", current_keyid,
                      "", "", "")
  elsif keyid != default_message_digest_key_id
    raise TypeError unless enc.is_a?(String)
    raise ArgumentError unless enc.length > 0
    enctype = Encryption.symbol_to_cli(enctype)
    @@node.config_set("interface_ospf", "message_digest_key_set",
                      @interface.name, "", keyid, algtype, enctype, enc)
  end
end

#message_digest_passwordObject



159
160
161
162
163
# File 'lib/cisco_node_utils/interface_ospf.rb', line 159

def message_digest_password
  match = @@node.config_get("interface_ospf", "message_digest_password",
                            @interface.name)
  match.nil? ? nil : match.first
end

#passive_interfaceObject



242
243
244
245
# File 'lib/cisco_node_utils/interface_ospf.rb', line 242

def passive_interface
  not @@node.config_get("interface_ospf", "passive_interface",
                        @interface.name).nil?
end

#passive_interface=(enable) ⇒ Object

interface %s

s ip ospf passive-interface

Raises:

  • (TypeError)


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

def passive_interface=(enable)
  raise TypeError unless enable == true or enable == false
  @@node.config_set("interface_ospf", "passive_interface", @interface.name,
                    enable ? "" : "no")
end