Class: Cisco::InterfaceOspf
- Defined in:
- lib/cisco_node_utils/interface_ospf.rb
Overview
InterfaceOspf - node utility class for per-interface OSPF config management
Instance Attribute Summary collapse
-
#interface ⇒ Object
readonly
Returns the value of attribute interface.
-
#ospf_name ⇒ Object
readonly
Returns the value of attribute ospf_name.
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
- #area ⇒ Object
- #area=(a) ⇒ Object
- #cost ⇒ Object
-
#cost=(c) ⇒ Object
interface %s ip ospf cost %d.
- #dead_interval ⇒ Object
-
#dead_interval=(interval) ⇒ Object
interface %s ip ospf dead-interval %d.
- #default_cost ⇒ Object
- #default_dead_interval ⇒ Object
- #default_hello_interval ⇒ Object
- #default_message_digest ⇒ Object
- #default_message_digest_algorithm_type ⇒ Object
- #default_message_digest_encryption_type ⇒ Object
- #default_message_digest_key_id ⇒ Object
- #default_passive_interface ⇒ Object
- #destroy ⇒ Object
- #hello_interval ⇒ Object
-
#hello_interval=(interval) ⇒ Object
interface %s ip ospf hello-interval %d.
-
#initialize(int_name, ospf_name, area, create = true) ⇒ InterfaceOspf
constructor
A new instance of InterfaceOspf.
- #message_digest ⇒ Object
-
#message_digest=(enable) ⇒ Object
interface %s %s ip ospf authentication message-digest.
- #message_digest_algorithm_type ⇒ Object
- #message_digest_encryption_type ⇒ Object
- #message_digest_key_id ⇒ Object
-
#message_digest_key_set(keyid, algtype, enctype, enc) ⇒ Object
interface %s %s ip ospf message-digest-key %d %s %d %s.
- #message_digest_password ⇒ Object
- #passive_interface ⇒ Object
-
#passive_interface=(enable) ⇒ Object
interface %s %s ip ospf passive-interface.
Methods inherited from NodeUtil
config_get, #config_get, config_get_default, #config_get_default, #config_set, config_set, #node, node, #show
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 49 |
# 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 # normalize 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 # enable feature ospf if it isn't RouterOspf.enable unless RouterOspf.enabled config_set('interface_ospf', 'area', @interface.name, '', @ospf_name, area) end |
Instance Attribute Details
#interface ⇒ Object (readonly)
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 (readonly)
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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 53 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? # ip router ospf <name> area <area> 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
72 73 74 75 76 77 78 79 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 72 def area match = config_get('interface_ospf', 'area', @interface.name) return nil if match.nil? val = match[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
81 82 83 84 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 81 def area=(a) config_set('interface_ospf', 'area', @interface.name, '', @ospf_name, a) end |
#cost ⇒ Object
165 166 167 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 165 def cost config_get('interface_ospf', 'cost', @interface.name) end |
#cost=(c) ⇒ Object
interface %s
ip ospf cost %d
175 176 177 178 179 180 181 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 175 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
198 199 200 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 198 def dead_interval config_get('interface_ospf', 'dead_interval', @interface.name) end |
#dead_interval=(interval) ⇒ Object
interface %s
ip ospf dead-interval %d
208 209 210 211 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 208 def dead_interval=(interval) config_set('interface_ospf', 'dead_interval', @interface.name, '', interval.to_i) end |
#default_cost ⇒ Object
169 170 171 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 169 def default_cost config_get_default('interface_ospf', 'cost') end |
#default_dead_interval ⇒ Object
202 203 204 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 202 def default_dead_interval config_get_default('interface_ospf', 'dead_interval') end |
#default_hello_interval ⇒ Object
187 188 189 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 187 def default_hello_interval config_get_default('interface_ospf', 'hello_interval') end |
#default_message_digest ⇒ Object
99 100 101 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 99 def config_get_default('interface_ospf', 'message_digest') end |
#default_message_digest_algorithm_type ⇒ Object
122 123 124 125 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 122 def config_get_default('interface_ospf', 'message_digest_alg_type').to_sym end |
#default_message_digest_encryption_type ⇒ Object
133 134 135 136 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 133 def Encryption.cli_to_symbol( config_get_default('interface_ospf', 'message_digest_enc_type')) end |
#default_message_digest_key_id ⇒ Object
114 115 116 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 114 def config_get_default('interface_ospf', 'message_digest_key_id') end |
#default_passive_interface ⇒ Object
213 214 215 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 213 def default_passive_interface config_get_default('interface_ospf', 'passive_interface') end |
#destroy ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 86 def destroy config_set('interface_ospf', 'area', @interface.name, 'no', @ospf_name, area) # Reset everything else back to default as well: self. = (, '', '', '') 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
183 184 185 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 183 def hello_interval config_get('interface_ospf', 'hello_interval', @interface.name) end |
#hello_interval=(interval) ⇒ Object
interface %s
ip ospf hello-interval %d
193 194 195 196 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 193 def hello_interval=(interval) config_set('interface_ospf', 'hello_interval', @interface.name, '', interval.to_i) end |
#message_digest ⇒ Object
103 104 105 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 103 def config_get('interface_ospf', 'message_digest', @interface.name) end |
#message_digest=(enable) ⇒ Object
interface %s
%s ip ospf authentication message-digest
109 110 111 112 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 109 def (enable) config_set('interface_ospf', 'message_digest', @interface.name, enable ? '' : 'no') end |
#message_digest_algorithm_type ⇒ Object
127 128 129 130 131 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 127 def match = config_get('interface_ospf', 'message_digest_alg_type', @interface.name) match.to_sym end |
#message_digest_encryption_type ⇒ Object
138 139 140 141 142 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 138 def match = config_get('interface_ospf', 'message_digest_enc_type', @interface.name) Encryption.cli_to_symbol(match) end |
#message_digest_key_id ⇒ Object
118 119 120 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 118 def 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
150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 150 def (keyid, algtype, enctype, enc) current_keyid = if keyid == && current_keyid != keyid config_set('interface_ospf', 'message_digest_key_set', @interface.name, 'no', current_keyid, '', '', '') elsif keyid != 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
144 145 146 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 144 def config_get('interface_ospf', 'message_digest_password', @interface.name) end |
#passive_interface ⇒ Object
217 218 219 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 217 def passive_interface config_get('interface_ospf', 'passive_interface', @interface.name) end |
#passive_interface=(enable) ⇒ Object
interface %s
%s ip ospf passive-interface
223 224 225 226 227 |
# File 'lib/cisco_node_utils/interface_ospf.rb', line 223 def passive_interface=(enable) fail TypeError unless enable == true || enable == false config_set('interface_ospf', 'passive_interface', @interface.name, enable ? '' : 'no') end |