Class: Cisco::InterfaceOspf
Overview
InterfaceOspf - node utility class for per-interface OSPF config management
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(int_name, ospf_name, area, create = true) ⇒ InterfaceOspf
Returns a new instance of InterfaceOspf.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 28
def initialize(int_name, ospf_name, area, create=true)
fail TypeError unless int_name.is_a? String
fail TypeError unless ospf_name.is_a? String
fail TypeError unless area.is_a? String
fail ArgumentError unless int_name.length > 0
fail ArgumentError unless ospf_name.length > 0
fail ArgumentError unless area.length > 0
int_name = int_name.downcase
@interface = Interface.interfaces[int_name]
fail "interface #{int_name} does not exist" if @interface.nil?
@ospf_name = ospf_name
return unless create
Feature.ospf_enable
config_set('interface_ospf', 'area', @interface.name,
'', @ospf_name, area)
end
|
Instance Attribute Details
#interface ⇒ Object
Returns the value of attribute interface.
26
27
28
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 26
def interface
@interface
end
|
#ospf_name ⇒ Object
Returns the value of attribute ospf_name.
26
27
28
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 26
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 52
def self.interfaces(ospf_name=nil)
fail TypeError unless ospf_name.is_a?(String) || ospf_name.nil?
ints = {}
intf_list = config_get('interface', 'all_interfaces')
return ints if intf_list.nil?
intf_list.each do |name|
match = config_get('interface_ospf', 'area', name)
next if match.nil?
ospf = match[0]
area = match[1]
next unless ospf_name.nil? || ospf == ospf_name
int = name.downcase
ints[int] = InterfaceOspf.new(int, ospf, area, false)
end
ints
end
|
Instance Method Details
#area ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 71
def area
match = config_get('interface_ospf', 'area', @interface.name)
return nil if match.nil?
val = match[1]
val = IPAddr.new(val.to_i, Socket::AF_INET).to_s unless val.match(/\./)
val
end
|
#area=(a) ⇒ Object
80
81
82
83
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 80
def area=(a)
config_set('interface_ospf', 'area', @interface.name,
'', @ospf_name, a)
end
|
#cost ⇒ Object
164
165
166
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 164
def cost
config_get('interface_ospf', 'cost', @interface.name)
end
|
#cost=(c) ⇒ Object
interface %s
ip ospf cost %d
174
175
176
177
178
179
180
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 174
def cost=(c)
if c == default_cost
config_set('interface_ospf', 'cost', @interface.name, 'no', '')
else
config_set('interface_ospf', 'cost', @interface.name, '', c)
end
end
|
#dead_interval ⇒ Object
197
198
199
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 197
def dead_interval
config_get('interface_ospf', 'dead_interval', @interface.name)
end
|
#dead_interval=(interval) ⇒ Object
interface %s
ip ospf dead-interval %d
207
208
209
210
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 207
def dead_interval=(interval)
config_set('interface_ospf', 'dead_interval',
@interface.name, '', interval.to_i)
end
|
#default_cost ⇒ Object
168
169
170
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 168
def default_cost
config_get_default('interface_ospf', 'cost')
end
|
#default_dead_interval ⇒ Object
201
202
203
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 201
def default_dead_interval
config_get_default('interface_ospf', 'dead_interval')
end
|
#default_hello_interval ⇒ Object
186
187
188
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 186
def default_hello_interval
config_get_default('interface_ospf', 'hello_interval')
end
|
#default_message_digest ⇒ Object
98
99
100
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 98
def default_message_digest
config_get_default('interface_ospf', 'message_digest')
end
|
#default_message_digest_algorithm_type ⇒ Object
121
122
123
124
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 121
def default_message_digest_algorithm_type
config_get_default('interface_ospf',
'message_digest_alg_type').to_sym
end
|
#default_message_digest_encryption_type ⇒ Object
132
133
134
135
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 132
def default_message_digest_encryption_type
Encryption.cli_to_symbol(
config_get_default('interface_ospf', 'message_digest_enc_type'))
end
|
#default_message_digest_key_id ⇒ Object
113
114
115
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 113
def default_message_digest_key_id
config_get_default('interface_ospf', 'message_digest_key_id')
end
|
#default_passive_interface ⇒ Object
212
213
214
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 212
def default_passive_interface
config_get_default('interface_ospf', 'passive_interface')
end
|
#destroy ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 85
def destroy
config_set('interface_ospf', 'area', @interface.name,
'no', @ospf_name, area)
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
config_set('interface_ospf', 'dead_interval',
@interface.name, 'no', '')
self.passive_interface = default_passive_interface if passive_interface
end
|
#hello_interval ⇒ Object
182
183
184
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 182
def hello_interval
config_get('interface_ospf', 'hello_interval', @interface.name)
end
|
#hello_interval=(interval) ⇒ Object
interface %s
ip ospf hello-interval %d
192
193
194
195
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 192
def hello_interval=(interval)
config_set('interface_ospf', 'hello_interval',
@interface.name, '', interval.to_i)
end
|
#message_digest ⇒ Object
102
103
104
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 102
def message_digest
config_get('interface_ospf', 'message_digest', @interface.name)
end
|
#message_digest=(enable) ⇒ Object
interface %s
%s ip ospf authentication message-digest
108
109
110
111
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 108
def message_digest=(enable)
config_set('interface_ospf', 'message_digest', @interface.name,
enable ? '' : 'no')
end
|
#message_digest_algorithm_type ⇒ Object
126
127
128
129
130
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 126
def message_digest_algorithm_type
match = config_get('interface_ospf', 'message_digest_alg_type',
@interface.name)
match.to_sym
end
|
#message_digest_encryption_type ⇒ Object
137
138
139
140
141
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 137
def message_digest_encryption_type
match = config_get('interface_ospf', 'message_digest_enc_type',
@interface.name)
Encryption.cli_to_symbol(match)
end
|
#message_digest_key_id ⇒ Object
117
118
119
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 117
def message_digest_key_id
config_get('interface_ospf', 'message_digest_key_id', @interface.name)
end
|
#message_digest_key_set(keyid, algtype, enctype, enc) ⇒ Object
interface %s
%s ip ospf message-digest-key %d %s %d %s
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 149
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
config_set('interface_ospf', 'message_digest_key_set',
@interface.name, 'no', current_keyid,
'', '', '')
elsif keyid != default_message_digest_key_id
fail TypeError unless enc.is_a?(String)
fail ArgumentError unless enc.length > 0
enctype = Encryption.symbol_to_cli(enctype)
config_set('interface_ospf', 'message_digest_key_set',
@interface.name, '', keyid, algtype, enctype, enc)
end
end
|
#message_digest_password ⇒ Object
143
144
145
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 143
def message_digest_password
config_get('interface_ospf', 'message_digest_password', @interface.name)
end
|
#passive_interface ⇒ Object
216
217
218
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 216
def passive_interface
config_get('interface_ospf', 'passive_interface', @interface.name)
end
|
#passive_interface=(enable) ⇒ Object
interface %s
%s ip ospf passive-interface
222
223
224
225
226
|
# File 'lib/cisco_node_utils/interface_ospf.rb', line 222
def passive_interface=(enable)
fail TypeError unless enable == true || enable == false
config_set('interface_ospf', 'passive_interface', @interface.name,
enable ? '' : 'no')
end
|