cisco_node_utils 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +293 -0
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +31 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.md +113 -0
- data/Rakefile +4 -0
- data/cisco_node_utils.gemspec +30 -0
- data/lib/cisco_node_utils.rb +33 -0
- data/lib/cisco_node_utils/README_YAML.md +333 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +92 -0
- data/lib/cisco_node_utils/command_reference.rb +415 -0
- data/lib/cisco_node_utils/command_reference_common.yaml +845 -0
- data/lib/cisco_node_utils/command_reference_n3064.yaml +13 -0
- data/lib/cisco_node_utils/command_reference_n7k.yaml +48 -0
- data/lib/cisco_node_utils/command_reference_n9k.yaml +35 -0
- data/lib/cisco_node_utils/configparser_lib.rb +196 -0
- data/lib/cisco_node_utils/interface.rb +501 -0
- data/lib/cisco_node_utils/interface_ospf.rb +241 -0
- data/lib/cisco_node_utils/node.rb +673 -0
- data/lib/cisco_node_utils/platform.rb +184 -0
- data/lib/cisco_node_utils/platform_info.rb +58 -0
- data/lib/cisco_node_utils/platform_info.yaml +10 -0
- data/lib/cisco_node_utils/router_ospf.rb +96 -0
- data/lib/cisco_node_utils/router_ospf_vrf.rb +258 -0
- data/lib/cisco_node_utils/snmpcommunity.rb +91 -0
- data/lib/cisco_node_utils/snmpgroup.rb +55 -0
- data/lib/cisco_node_utils/snmpserver.rb +150 -0
- data/lib/cisco_node_utils/snmpuser.rb +342 -0
- data/lib/cisco_node_utils/tacacs_server.rb +175 -0
- data/lib/cisco_node_utils/tacacs_server_host.rb +128 -0
- data/lib/cisco_node_utils/version.rb +17 -0
- data/lib/cisco_node_utils/vlan.rb +153 -0
- data/lib/cisco_node_utils/vtp.rb +127 -0
- data/lib/cisco_node_utils/yum.rb +84 -0
- data/tests/basetest.rb +93 -0
- data/tests/ciscotest.rb +136 -0
- data/tests/cmd_config.yaml +51 -0
- data/tests/cmd_config_invalid.yaml +16 -0
- data/tests/test_all_cisco.rb +46 -0
- data/tests/test_command_config.rb +192 -0
- data/tests/test_command_reference.rb +222 -0
- data/tests/test_interface.rb +1017 -0
- data/tests/test_interface_ospf.rb +763 -0
- data/tests/test_interface_svi.rb +267 -0
- data/tests/test_interface_switchport.rb +722 -0
- data/tests/test_node.rb +108 -0
- data/tests/test_node_ext.rb +450 -0
- data/tests/test_platform.rb +188 -0
- data/tests/test_router_ospf.rb +164 -0
- data/tests/test_router_ospf_vrf.rb +753 -0
- data/tests/test_snmpcommunity.rb +344 -0
- data/tests/test_snmpgroup.rb +71 -0
- data/tests/test_snmpserver.rb +443 -0
- data/tests/test_snmpuser.rb +803 -0
- data/tests/test_tacacs_server.rb +388 -0
- data/tests/test_tacacs_server_host.rb +391 -0
- data/tests/test_vlan.rb +264 -0
- data/tests/test_vtp.rb +319 -0
- data/tests/test_yum.rb +106 -0
- metadata +188 -0
@@ -0,0 +1,184 @@
|
|
1
|
+
# Platform provider class
|
2
|
+
#
|
3
|
+
# Alex Hunsberger, Mar 2015
|
4
|
+
#
|
5
|
+
# Copyright (c) 2015 Cisco and/or its affiliates.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require File.join(File.dirname(__FILE__), 'node')
|
20
|
+
|
21
|
+
class Platform
|
22
|
+
@@node = Cisco::Node.instance
|
23
|
+
|
24
|
+
# ex: 'n3500-uk9.6.0.2.A3.0.40.bin'
|
25
|
+
def Platform.system_image
|
26
|
+
@@node.config_get("show_version", "boot_image")
|
27
|
+
end
|
28
|
+
|
29
|
+
# returns package hash with state values
|
30
|
+
# ex: { 'n3000-uk9.6.0.2.U1.1.CSCaa12345.bin' => 'inactive committed',
|
31
|
+
# 'n3000-uk9.6.0.2.U1.1.CSCaa12346.bin' => 'active', }
|
32
|
+
def Platform.packages
|
33
|
+
pkgs = @@node.config_get("images", "packages")
|
34
|
+
return {} if pkgs.nil?
|
35
|
+
pkg_hsh = {}
|
36
|
+
pkgs.each { |p|
|
37
|
+
pkg_hsh[p[0]] = p[1].downcase
|
38
|
+
}
|
39
|
+
pkg_hsh
|
40
|
+
end
|
41
|
+
|
42
|
+
# ex: 'Cisco Nexus3064 Chassis ("48x10GE + 16x10G/4x40G Supervisor")'
|
43
|
+
def Platform.hardware_type
|
44
|
+
@@node.config_get("show_version", "description")
|
45
|
+
end
|
46
|
+
|
47
|
+
# ex: 'Intel(R) Celeron(R) CPU P450'
|
48
|
+
def Platform.cpu
|
49
|
+
@@node.config_get("show_version", "cpu")
|
50
|
+
end
|
51
|
+
|
52
|
+
# return hash with keys "total", "used", "free"
|
53
|
+
# ex: { 'total' => '16402252K',
|
54
|
+
# 'used' => '5909004K',
|
55
|
+
# 'free' => '10493248K' }
|
56
|
+
def Platform.memory
|
57
|
+
total = @@node.config_get("memory", "total")
|
58
|
+
used = @@node.config_get("memory", "used")
|
59
|
+
free = @@node.config_get("memory", "free")
|
60
|
+
|
61
|
+
raise "failed to retrieve platform memory information" if
|
62
|
+
total.nil? or used.nil? or free.nil?
|
63
|
+
|
64
|
+
{ 'total' => total.first,
|
65
|
+
'used' => used.first,
|
66
|
+
'free' => free.first, }
|
67
|
+
end
|
68
|
+
|
69
|
+
# ex: 'Processor Board ID FOC15430TEY'
|
70
|
+
def Platform.board
|
71
|
+
@@node.config_get("show_version", "board")
|
72
|
+
end
|
73
|
+
|
74
|
+
# ex: '1 day(s), 21 hour(s), 46 minute(s), 54 second(s)'
|
75
|
+
def Platform.uptime
|
76
|
+
u = @@node.config_get("show_version", "uptime")
|
77
|
+
raise "failed to retrieve platform uptime" if u.nil?
|
78
|
+
u.first
|
79
|
+
end
|
80
|
+
|
81
|
+
# ex: '23113 usecs after Mon Jul 1 15:24:29 2013'
|
82
|
+
def Platform.last_reset
|
83
|
+
r = @@node.config_get("show_version", "last_reset_time")
|
84
|
+
r.nil? ? nil : r.strip
|
85
|
+
end
|
86
|
+
|
87
|
+
# ex: 'Reset Requested by CLI command reload'
|
88
|
+
def Platform.reset_reason
|
89
|
+
@@node.config_get("show_version", "last_reset_reason")
|
90
|
+
end
|
91
|
+
|
92
|
+
# returns chassis hash with keys "descr", "pid", "vid", "sn"
|
93
|
+
# ex: { 'descr' => 'Nexus9000 C9396PX Chassis',
|
94
|
+
# 'pid' => 'N9K-C9396PX',
|
95
|
+
# 'vid' => 'V02',
|
96
|
+
# 'sn' => 'SAL1812NTBP' }
|
97
|
+
def Platform.chassis
|
98
|
+
chas = @@node.config_get("inventory", "chassis")
|
99
|
+
return nil if chas.nil?
|
100
|
+
{ 'descr' => chas['desc'].tr('"', ''),
|
101
|
+
'pid' => chas['productid'],
|
102
|
+
'vid' => chas['vendorid'],
|
103
|
+
'sn' => chas['serialnum'], }
|
104
|
+
end
|
105
|
+
|
106
|
+
# returns hash of hashes with inner keys "name", "descr", "pid", "vid", "sn"
|
107
|
+
# ex: { 'Slot 1' => { 'descr' => '1/10G SFP+ Ethernet Module',
|
108
|
+
# 'pid' => 'N9K-C9396PX',
|
109
|
+
# 'vid' => 'V02',
|
110
|
+
# 'sn' => 'SAL1812NTBP' },
|
111
|
+
# 'Slot 2' => { ... }}
|
112
|
+
def Platform.inventory_of(type)
|
113
|
+
@@node.cache_flush # TODO: investigate why this is needed
|
114
|
+
inv = @@node.config_get("inventory", "all")
|
115
|
+
return {} if inv.nil?
|
116
|
+
inv.select! { |x| x['name'].include? type }
|
117
|
+
return {} if inv.empty?
|
118
|
+
# match desired output format
|
119
|
+
inv_hsh = {}
|
120
|
+
inv.each { |s|
|
121
|
+
inv_hsh[s['name'].tr('"', '')] = { 'descr' => s['desc'].tr('"', ''),
|
122
|
+
'pid' => s['productid'],
|
123
|
+
'vid' => s['vendorid'],
|
124
|
+
'sn' => s['serialnum'] }
|
125
|
+
}
|
126
|
+
inv_hsh
|
127
|
+
end
|
128
|
+
|
129
|
+
# returns array of hashes with keys "name", "descr", "pid", "vid", "sn"
|
130
|
+
def Platform.slots
|
131
|
+
Platform.inventory_of('Slot')
|
132
|
+
end
|
133
|
+
|
134
|
+
# returns array of hashes with keys "name", "descr", "pid", "vid", "sn"
|
135
|
+
def Platform.power_supplies
|
136
|
+
Platform.inventory_of('Power Supply')
|
137
|
+
end
|
138
|
+
|
139
|
+
# returns array of hashes with keys "name", "descr", "pid", "vid", "sn"
|
140
|
+
def Platform.fans
|
141
|
+
Platform.inventory_of('Fan')
|
142
|
+
end
|
143
|
+
|
144
|
+
# returns hash of hashes with inner keys "state", "application", ...
|
145
|
+
# ex: { 'chef' => {
|
146
|
+
# 'package_info' => { 'name' => 'n3k_chanm_chef.ova',
|
147
|
+
# 'path' => 'bootflash:/n3k_chanm_chef.ova' },
|
148
|
+
# 'application' => { 'name' => 'ChefAgent',
|
149
|
+
# 'version' => '0.1',
|
150
|
+
# 'descr' => 'Cisco Chef Agent' },
|
151
|
+
# 'signing' => { 'key_type' => 'Cisco development key',
|
152
|
+
# 'method' => 'SHA-1' }
|
153
|
+
# 'licensing' => { 'name' => 'none',
|
154
|
+
# 'version' => 'none' }
|
155
|
+
# 'reservation' => { 'disk' => '111 MB',
|
156
|
+
# 'memory' => '0 MB',
|
157
|
+
# 'cpu' => '0% system CPU' }},
|
158
|
+
# { ... }}
|
159
|
+
def Platform.virtual_services
|
160
|
+
virts = @@node.config_get("virtual_service", "services")
|
161
|
+
return [] if virts.nil?
|
162
|
+
# NXAPI returns hash instead of array if there's only 1
|
163
|
+
virts = [virts] if virts.is_a? Hash
|
164
|
+
# convert to expected format
|
165
|
+
virts_hsh = {}
|
166
|
+
virts.each { |serv|
|
167
|
+
virts_hsh[serv['name']] = {
|
168
|
+
'package_info' => { 'name' => serv['package_name'],
|
169
|
+
'path' => serv['ova_path'], },
|
170
|
+
'application' => { 'name' => serv['application_name'],
|
171
|
+
'version' => serv['application_version'],
|
172
|
+
'descr' => serv['application_description'], },
|
173
|
+
'signing' => { 'key_type' => serv['key_type'],
|
174
|
+
'method' => serv['signing_method'], },
|
175
|
+
'licensing' => { 'name' => serv['licensing_name'],
|
176
|
+
'version' => serv['licensing_version'], },
|
177
|
+
'reservation' => { 'disk' => serv['disk_reservation'],
|
178
|
+
'memory' => serv['memory_reservation'],
|
179
|
+
'cpu' => serv['cpu_reservation'], },
|
180
|
+
}
|
181
|
+
}
|
182
|
+
virts_hsh
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (c) 2013-2015 Cisco and/or its affiliates.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'yaml'
|
16
|
+
|
17
|
+
# Class: PlatformInfo
|
18
|
+
# This class reads device specific details from the yaml file - platform_info.yaml
|
19
|
+
# These details can be used to customize unit tests for a device
|
20
|
+
class PlatformInfo
|
21
|
+
# Default constructor for the PlatformInfo class. This class
|
22
|
+
# requires the hostname of the device on which UTs are to run
|
23
|
+
# to be passed in. The constructor reads platform_info.yaml
|
24
|
+
# and stores info for this device in the instance variable
|
25
|
+
# @platform_info_hash
|
26
|
+
#
|
27
|
+
# @param[in] device_name hostname of device on which
|
28
|
+
# UTs are to be run
|
29
|
+
#
|
30
|
+
def initialize(device_name)
|
31
|
+
raise "device name must be specified in PlatformInfo constructor." if device_name.nil? or device_name.empty?
|
32
|
+
@platform_info_hash = {}
|
33
|
+
|
34
|
+
begin
|
35
|
+
project_info_hash = YAML.load_file(File.join(File.dirname(__FILE__), "platform_info.yaml"))
|
36
|
+
rescue Exception => e
|
37
|
+
raise "Error - could not open platform file - platform_info.yaml"
|
38
|
+
end
|
39
|
+
|
40
|
+
@platform_info_hash = project_info_hash[device_name]
|
41
|
+
raise "Error - could not find #{device_name} device specific information in platform_info.yaml" if @platform_info_hash.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
# The following instance method will return the value associated with
|
45
|
+
# the specified key from the instance variable @platform_info_hash.
|
46
|
+
#
|
47
|
+
# @param[in] key String value indicating the key to be searched for
|
48
|
+
# in @platform_info_hash
|
49
|
+
#
|
50
|
+
def get_value_from_key(key)
|
51
|
+
raise "key must be specified in the method get_value_from_key" if key.nil?
|
52
|
+
|
53
|
+
value = @platform_info_hash[key]
|
54
|
+
raise "no value exists for the key #{key}" if value.nil?
|
55
|
+
|
56
|
+
value
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
---
|
2
|
+
# This yaml file is read by ciscotest.rb to read
|
3
|
+
# device specific information before running unit tests
|
4
|
+
|
5
|
+
# Currently the only device specific info we support is
|
6
|
+
# an array of ethernet interfaces. More device specific
|
7
|
+
# attributes can be added in future.
|
8
|
+
|
9
|
+
example_node:
|
10
|
+
interfaces: [Ethernet1/1, Ethernet1/10, Ethernet1/20]
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#
|
2
|
+
# NXAPI implementation of RouterOspf class
|
3
|
+
#
|
4
|
+
# November 2014, Chris Van Heuveln
|
5
|
+
#
|
6
|
+
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
|
20
|
+
require File.join(File.dirname(__FILE__), 'node')
|
21
|
+
|
22
|
+
module Cisco
|
23
|
+
class RouterOspf
|
24
|
+
attr_reader :name
|
25
|
+
|
26
|
+
@@node = Cisco::Node.instance
|
27
|
+
|
28
|
+
def initialize(name, instantiate=true)
|
29
|
+
raise ArgumentError unless name.length > 0
|
30
|
+
@name = name
|
31
|
+
|
32
|
+
create if instantiate
|
33
|
+
end
|
34
|
+
|
35
|
+
# Create a hash of all router ospf instances
|
36
|
+
def RouterOspf.routers
|
37
|
+
ospf_ids = @@node.config_get("ospf", "router")
|
38
|
+
return {} if ospf_ids.nil?
|
39
|
+
|
40
|
+
hash = {}
|
41
|
+
ospf_ids.each do |name|
|
42
|
+
hash[name] = RouterOspf.new(name, false)
|
43
|
+
end
|
44
|
+
return hash
|
45
|
+
rescue Cisco::CliError => e
|
46
|
+
# cmd will syntax reject when feature is not enabled
|
47
|
+
raise unless e.clierror =~ /Syntax error/
|
48
|
+
return {}
|
49
|
+
end
|
50
|
+
|
51
|
+
def RouterOspf.enabled
|
52
|
+
feat = @@node.config_get("ospf", "feature")
|
53
|
+
return (!feat.nil? and !feat.empty?)
|
54
|
+
rescue Cisco::CliError => e
|
55
|
+
# cmd will syntax reject when feature is not enabled
|
56
|
+
raise unless e.clierror =~ /Syntax error/
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
|
60
|
+
def RouterOspf.enable(state="")
|
61
|
+
@@node.config_set("ospf", "feature", state)
|
62
|
+
end
|
63
|
+
|
64
|
+
def ospf_router(name, state="")
|
65
|
+
@@node.config_set("ospf", "router", state, name)
|
66
|
+
end
|
67
|
+
|
68
|
+
def enable_create_router_ospf(name)
|
69
|
+
RouterOspf.enable
|
70
|
+
ospf_router(name)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Create one router ospf instance
|
74
|
+
def create
|
75
|
+
if RouterOspf.enabled
|
76
|
+
ospf_router(name)
|
77
|
+
else
|
78
|
+
enable_create_router_ospf(name)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Destroy one router ospf instance
|
83
|
+
def destroy
|
84
|
+
ospf_ids = @@node.config_get("ospf", "router")
|
85
|
+
return if ospf_ids.nil?
|
86
|
+
if ospf_ids.size == 1
|
87
|
+
RouterOspf.enable("no")
|
88
|
+
else
|
89
|
+
ospf_router(name, "no")
|
90
|
+
end
|
91
|
+
rescue Cisco::CliError => e
|
92
|
+
# cmd will syntax reject when feature is not enabled
|
93
|
+
raise unless e.clierror =~ /Syntax error/
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,258 @@
|
|
1
|
+
#
|
2
|
+
# NXAPI implementation of RouterOspfVrf class
|
3
|
+
#
|
4
|
+
# Mike Wiebe, March 2015
|
5
|
+
#
|
6
|
+
# Copyright (c) 2015 Cisco and/or its affiliates.
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
|
20
|
+
require File.join(File.dirname(__FILE__), 'node')
|
21
|
+
require File.join(File.dirname(__FILE__), 'router_ospf')
|
22
|
+
|
23
|
+
module Cisco
|
24
|
+
class RouterOspfVrf
|
25
|
+
attr_reader :name, :parent
|
26
|
+
|
27
|
+
OSPF_AUTO_COST = {
|
28
|
+
:mbps => "Mbps",
|
29
|
+
:gbps => "Gbps",
|
30
|
+
}
|
31
|
+
|
32
|
+
OSPF_LOG_ADJACENCY = {
|
33
|
+
:none => "none",
|
34
|
+
:log => "",
|
35
|
+
:detail => "detail",
|
36
|
+
}
|
37
|
+
|
38
|
+
@@node = Cisco::Node.instance
|
39
|
+
|
40
|
+
def initialize(router, name, instantiate=true)
|
41
|
+
raise TypeError if router.nil?
|
42
|
+
raise TypeError if name.nil?
|
43
|
+
raise ArgumentError unless router.length > 0
|
44
|
+
raise ArgumentError unless name.length > 0
|
45
|
+
@router = router
|
46
|
+
@name = name
|
47
|
+
@parent = {}
|
48
|
+
@get_args = @set_args = (@name == "default") ?
|
49
|
+
{ :name => @router } : { :name => @router, :vrf => @name }
|
50
|
+
|
51
|
+
create if instantiate
|
52
|
+
end
|
53
|
+
|
54
|
+
# Create a hash of all router ospf vrf instances
|
55
|
+
def RouterOspfVrf.vrfs
|
56
|
+
hash_final = {}
|
57
|
+
RouterOspf.routers.each do |instance|
|
58
|
+
name = instance[0]
|
59
|
+
vrf_ids = @@node.config_get("ospf", "vrf", { :name => name })
|
60
|
+
hash_tmp = { name =>
|
61
|
+
{ 'default' => RouterOspfVrf.new(name, 'default', false) } }
|
62
|
+
unless vrf_ids.nil?
|
63
|
+
vrf_ids.each do |vrf|
|
64
|
+
hash_tmp[name][vrf] = RouterOspfVrf.new(name, vrf, false)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
hash_final.merge!(hash_tmp)
|
68
|
+
end
|
69
|
+
hash_final
|
70
|
+
end
|
71
|
+
|
72
|
+
# Create one router ospf vrf instance
|
73
|
+
def create
|
74
|
+
@parent = RouterOspf.new(@router)
|
75
|
+
@@node.config_set("ospf", "vrf", { :name => @router,
|
76
|
+
:state => "",
|
77
|
+
:vrf => @name }) if
|
78
|
+
@name != "default"
|
79
|
+
end
|
80
|
+
|
81
|
+
# Destroy one router ospf vrf instance
|
82
|
+
def destroy
|
83
|
+
raise RuntimeError if @name == "default"
|
84
|
+
@@node.config_set("ospf", "vrf", { :name => @router,
|
85
|
+
:state => "no",
|
86
|
+
:vrf => @name })
|
87
|
+
end
|
88
|
+
|
89
|
+
# Helper method to delete @set_args hash keys
|
90
|
+
def set_args_keys_delete(list)
|
91
|
+
list.each { |key| @set_args.delete(key) }
|
92
|
+
end
|
93
|
+
|
94
|
+
def auto_cost
|
95
|
+
match = @@node.config_get("ospf", "auto_cost", @get_args)
|
96
|
+
return default_auto_cost if match.nil?
|
97
|
+
# Multiple matches are possible but the first match is used.
|
98
|
+
# This can be removed when rally defect DE3614 is resolved.
|
99
|
+
match[0].last.nil? ?
|
100
|
+
[match[0].first.to_i, OSPF_AUTO_COST[:mbps]] :
|
101
|
+
[match[0].first.to_i, match[0].last]
|
102
|
+
end
|
103
|
+
|
104
|
+
def auto_cost_set(cost, type)
|
105
|
+
@set_args[:cost], @set_args[:type] = cost, OSPF_AUTO_COST[type]
|
106
|
+
@@node.config_set("ospf", "auto_cost", @set_args)
|
107
|
+
set_args_keys_delete([:cost, :type])
|
108
|
+
end
|
109
|
+
|
110
|
+
def default_auto_cost
|
111
|
+
@@node.config_get_default("ospf", "auto_cost")
|
112
|
+
end
|
113
|
+
|
114
|
+
def default_metric
|
115
|
+
match = @@node.config_get("ospf", "default_metric", @get_args)
|
116
|
+
match.nil? ? default_default_metric : match.first.to_i
|
117
|
+
end
|
118
|
+
|
119
|
+
def default_metric=(metric)
|
120
|
+
if metric == default_default_metric
|
121
|
+
@set_args[:state], @set_args[:metric] = "no", ""
|
122
|
+
else
|
123
|
+
@set_args[:state], @set_args[:metric] = "", metric
|
124
|
+
end
|
125
|
+
@@node.config_set("ospf", "default_metric", @set_args)
|
126
|
+
set_args_keys_delete([:state, :metric])
|
127
|
+
end
|
128
|
+
|
129
|
+
def default_default_metric
|
130
|
+
@@node.config_get_default("ospf", "default_metric")
|
131
|
+
end
|
132
|
+
|
133
|
+
def log_adjacency
|
134
|
+
match = @@node.config_get("ospf", "log_adjacency", @get_args)
|
135
|
+
return default_log_adjacency if match.nil?
|
136
|
+
# Multiple matches are possible but the first match is used.
|
137
|
+
# This can be removed when rally defect DE3614 is resolved.
|
138
|
+
match[0].flatten.last.nil? ? :log : :detail
|
139
|
+
end
|
140
|
+
|
141
|
+
def log_adjacency=(type)
|
142
|
+
case type
|
143
|
+
when :none
|
144
|
+
@set_args[:state], @set_args[:type] = "no", ""
|
145
|
+
when :log, :detail
|
146
|
+
@set_args[:state], @set_args[:type] = "", OSPF_LOG_ADJACENCY[type]
|
147
|
+
end
|
148
|
+
@@node.config_set("ospf", "log_adjacency", @set_args)
|
149
|
+
set_args_keys_delete([:state, :type])
|
150
|
+
end
|
151
|
+
|
152
|
+
def default_log_adjacency
|
153
|
+
@@node.config_get_default("ospf", "log_adjacency")
|
154
|
+
end
|
155
|
+
|
156
|
+
def router_id
|
157
|
+
match = @@node.config_get("ospf", "router_id", @get_args)
|
158
|
+
match.nil? ? default_router_id : match.first
|
159
|
+
end
|
160
|
+
|
161
|
+
def router_id=(router_id)
|
162
|
+
router_id == default_router_id ?
|
163
|
+
(@set_args[:state], @set_args[:router_id] = "no", "") :
|
164
|
+
(@set_args[:state], @set_args[:router_id] = "", router_id)
|
165
|
+
|
166
|
+
@@node.config_set("ospf", "router_id", @set_args)
|
167
|
+
set_args_keys_delete([:state, :router_id])
|
168
|
+
end
|
169
|
+
|
170
|
+
def default_router_id
|
171
|
+
@@node.config_get_default("ospf", "router_id")
|
172
|
+
end
|
173
|
+
|
174
|
+
def timer_throttle_lsa
|
175
|
+
match = @@node.config_get("ospf", "timer_throttle_lsa", @get_args)
|
176
|
+
(match.nil? or match.first.nil?) ? default_timer_throttle_lsa :
|
177
|
+
match.first.collect(&:to_i)
|
178
|
+
end
|
179
|
+
|
180
|
+
def timer_throttle_lsa_start
|
181
|
+
start, hold, max = timer_throttle_lsa
|
182
|
+
return default_timer_throttle_lsa_start if start.nil?
|
183
|
+
start
|
184
|
+
end
|
185
|
+
|
186
|
+
def timer_throttle_lsa_hold
|
187
|
+
start, hold, max = timer_throttle_lsa
|
188
|
+
return default_timer_throttle_lsa_hold if hold.nil?
|
189
|
+
hold
|
190
|
+
end
|
191
|
+
|
192
|
+
def timer_throttle_lsa_max
|
193
|
+
start, hold, max = timer_throttle_lsa
|
194
|
+
return default_timer_throttle_lsa_max if max.nil?
|
195
|
+
max
|
196
|
+
end
|
197
|
+
|
198
|
+
def timer_throttle_lsa_set(start, hold, max)
|
199
|
+
@set_args[:start], @set_args[:hold], @set_args[:max] = start, hold, max
|
200
|
+
@@node.config_set("ospf", "timer_throttle_lsa", @set_args)
|
201
|
+
set_args_keys_delete([:start, :hold, :max])
|
202
|
+
end
|
203
|
+
|
204
|
+
def default_timer_throttle_lsa_start
|
205
|
+
@@node.config_get_default("ospf", "timer_throttle_lsa_start")
|
206
|
+
end
|
207
|
+
|
208
|
+
def default_timer_throttle_lsa_hold
|
209
|
+
@@node.config_get_default("ospf", "timer_throttle_lsa_hold")
|
210
|
+
end
|
211
|
+
|
212
|
+
def default_timer_throttle_lsa_max
|
213
|
+
@@node.config_get_default("ospf", "timer_throttle_lsa_max")
|
214
|
+
end
|
215
|
+
|
216
|
+
def timer_throttle_spf
|
217
|
+
match = @@node.config_get("ospf", "timer_throttle_spf", @get_args)
|
218
|
+
(match.nil? or match.first.nil?) ? default_timer_throttle_spf :
|
219
|
+
match.first.collect(&:to_i)
|
220
|
+
end
|
221
|
+
|
222
|
+
def timer_throttle_spf_start
|
223
|
+
start, hold, max = timer_throttle_spf
|
224
|
+
return default_timer_throttle_spf_start if start.nil?
|
225
|
+
start
|
226
|
+
end
|
227
|
+
|
228
|
+
def timer_throttle_spf_hold
|
229
|
+
start, hold, max = timer_throttle_spf
|
230
|
+
return default_timer_throttle_spf_hold if hold.nil?
|
231
|
+
hold
|
232
|
+
end
|
233
|
+
|
234
|
+
def timer_throttle_spf_max
|
235
|
+
start, hold, max = timer_throttle_spf
|
236
|
+
return default_timer_throttle_spf_max if max.nil?
|
237
|
+
max
|
238
|
+
end
|
239
|
+
|
240
|
+
def timer_throttle_spf_set(start, hold, max)
|
241
|
+
@set_args[:start], @set_args[:hold], @set_args[:max] = start, hold, max
|
242
|
+
@@node.config_set("ospf", "timer_throttle_spf", @set_args)
|
243
|
+
set_args_keys_delete([:start, :hold, :max])
|
244
|
+
end
|
245
|
+
|
246
|
+
def default_timer_throttle_spf_start
|
247
|
+
@@node.config_get_default("ospf", "timer_throttle_spf_start")
|
248
|
+
end
|
249
|
+
|
250
|
+
def default_timer_throttle_spf_hold
|
251
|
+
@@node.config_get_default("ospf", "timer_throttle_spf_hold")
|
252
|
+
end
|
253
|
+
|
254
|
+
def default_timer_throttle_spf_max
|
255
|
+
@@node.config_get_default("ospf", "timer_throttle_spf_max")
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|