cisco_node_utils 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +81 -1
- data/.travis.yml +9 -0
- data/CHANGELOG.md +72 -6
- data/CONTRIBUTING.md +32 -7
- data/README.md +70 -7
- data/Rakefile +17 -0
- data/bin/check_metric_limits.rb +109 -0
- data/bin/git/hooks/commit-msg/enforce_style +81 -0
- data/bin/git/hooks/hook_lib +108 -0
- data/bin/git/hooks/hooks-wrapper +38 -0
- data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
- data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
- data/bin/git/hooks/post-flow-release-start/update-version +19 -0
- data/bin/git/hooks/post-merge/update-hooks +6 -0
- data/bin/git/hooks/post-rewrite/update-hooks +6 -0
- data/bin/git/hooks/pre-commit/rubocop +20 -0
- data/bin/git/hooks/pre-commit/validate-diffs +31 -0
- data/bin/git/hooks/pre-push/check-changelog +24 -0
- data/bin/git/hooks/pre-push/rubocop +7 -0
- data/bin/git/update-hooks +65 -0
- data/cisco_node_utils.gemspec +9 -3
- data/docs/README-develop-best-practices.md +404 -0
- data/docs/README-develop-node-utils-APIs.md +215 -365
- data/docs/README-maintainers.md +33 -3
- data/docs/template-router.rb +89 -91
- data/docs/template-test_router.rb +52 -55
- data/lib/.rubocop.yml +18 -0
- data/lib/cisco_node_utils.rb +2 -19
- data/lib/cisco_node_utils/README_YAML.md +1 -9
- data/lib/cisco_node_utils/bgp.rb +664 -0
- data/lib/cisco_node_utils/bgp_af.rb +530 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
- data/lib/cisco_node_utils/command_reference.rb +72 -74
- data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
- data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
- data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
- data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
- data/lib/cisco_node_utils/configparser_lib.rb +152 -147
- data/lib/cisco_node_utils/dns_domain.rb +79 -0
- data/lib/cisco_node_utils/domain_name.rb +71 -0
- data/lib/cisco_node_utils/interface.rb +167 -161
- data/lib/cisco_node_utils/interface_ospf.rb +78 -81
- data/lib/cisco_node_utils/name_server.rb +64 -0
- data/lib/cisco_node_utils/node.rb +154 -198
- data/lib/cisco_node_utils/node_util.rb +61 -0
- data/lib/cisco_node_utils/ntp_config.rb +65 -0
- data/lib/cisco_node_utils/ntp_server.rb +76 -0
- data/lib/cisco_node_utils/platform.rb +174 -165
- data/lib/cisco_node_utils/radius_global.rb +146 -0
- data/lib/cisco_node_utils/radius_server.rb +295 -0
- data/lib/cisco_node_utils/router_ospf.rb +59 -63
- data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
- data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
- data/lib/cisco_node_utils/snmpgroup.rb +22 -23
- data/lib/cisco_node_utils/snmpserver.rb +99 -103
- data/lib/cisco_node_utils/snmpuser.rb +294 -274
- data/lib/cisco_node_utils/syslog_server.rb +92 -0
- data/lib/cisco_node_utils/syslog_settings.rb +69 -0
- data/lib/cisco_node_utils/tacacs_server.rb +137 -133
- data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
- data/lib/cisco_node_utils/version.rb +2 -1
- data/lib/cisco_node_utils/vlan.rb +28 -31
- data/lib/cisco_node_utils/vrf.rb +80 -0
- data/lib/cisco_node_utils/vtp.rb +100 -97
- data/lib/cisco_node_utils/yum.rb +15 -17
- data/tests/.rubocop.yml +15 -0
- data/tests/basetest.rb +81 -36
- data/tests/ciscotest.rb +38 -78
- data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
- data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
- data/tests/test_bgp_af.rb +920 -0
- data/tests/test_bgp_neighbor.rb +403 -0
- data/tests/test_bgp_neighbor_af.rb +589 -0
- data/tests/test_command_config.rb +65 -62
- data/tests/test_command_reference.rb +31 -45
- data/tests/test_dns_domain.rb +113 -0
- data/tests/test_domain_name.rb +86 -0
- data/tests/test_interface.rb +424 -548
- data/tests/test_interface_ospf.rb +248 -432
- data/tests/test_interface_svi.rb +56 -79
- data/tests/test_interface_switchport.rb +196 -272
- data/tests/test_name_server.rb +85 -0
- data/tests/test_node.rb +7 -6
- data/tests/test_node_ext.rb +133 -186
- data/tests/test_ntp_config.rb +49 -0
- data/tests/test_ntp_server.rb +74 -0
- data/tests/test_platform.rb +58 -37
- data/tests/test_radius_global.rb +78 -0
- data/tests/test_radius_server.rb +185 -0
- data/tests/test_router_bgp.rb +838 -0
- data/tests/test_router_ospf.rb +49 -80
- data/tests/test_router_ospf_vrf.rb +274 -392
- data/tests/test_snmpcommunity.rb +128 -172
- data/tests/test_snmpgroup.rb +12 -14
- data/tests/test_snmpserver.rb +160 -189
- data/tests/test_snmpuser.rb +568 -717
- data/tests/test_syslog_server.rb +88 -0
- data/tests/test_syslog_settings.rb +54 -0
- data/tests/test_tacacs_server.rb +113 -148
- data/tests/test_tacacs_server_host.rb +108 -161
- data/tests/test_vlan.rb +63 -79
- data/tests/test_vrf.rb +92 -0
- data/tests/test_vtp.rb +108 -126
- data/tests/test_yum.rb +47 -41
- metadata +92 -56
- data/.rubocop_todo.yml +0 -293
- data/docs/.rubocop.yml +0 -13
- data/docs/template-feature.rb +0 -45
- data/docs/template-test_feature.rb +0 -51
- data/tests/test_all_cisco.rb +0 -46
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# September 2015, Glenn F. Matthews
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
require_relative 'node'
|
|
18
|
+
|
|
19
|
+
module Cisco
|
|
20
|
+
# NodeUtil - generic functionality for node utility subclasses to use
|
|
21
|
+
class NodeUtil
|
|
22
|
+
# rubocop:disable Style/ClassVars
|
|
23
|
+
# We want this to be inherited to all child classes, it's a singleton.
|
|
24
|
+
@@node = nil
|
|
25
|
+
# rubocop:enable Style/ClassVars
|
|
26
|
+
|
|
27
|
+
def self.node
|
|
28
|
+
# rubocop:disable Style/ClassVars
|
|
29
|
+
@@node ||= Cisco::Node.instance
|
|
30
|
+
# rubocop:enable Style/ClassVars
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def node
|
|
34
|
+
self.class.node
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.config_get(*args)
|
|
38
|
+
node.config_get(*args)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def config_get(*args)
|
|
42
|
+
node.config_get(*args)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.config_get_default(*args)
|
|
46
|
+
node.config_get_default(*args)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def config_get_default(*args)
|
|
50
|
+
node.config_get_default(*args)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.config_set(*args)
|
|
54
|
+
node.config_set(*args)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def config_set(*args)
|
|
58
|
+
node.config_set(*args)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# NTP Config provider class
|
|
2
|
+
#
|
|
3
|
+
# Jonathan Tripathy et al., September 2015
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2014-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_relative 'node_util'
|
|
20
|
+
|
|
21
|
+
module Cisco
|
|
22
|
+
# NtpConfig - node utility class for NTP Config configuration management
|
|
23
|
+
class NtpConfig < NodeUtil
|
|
24
|
+
attr_reader :name
|
|
25
|
+
|
|
26
|
+
def initialize(name)
|
|
27
|
+
fail TypeError unless name.is_a?(String)
|
|
28
|
+
fail ArgumentError,
|
|
29
|
+
"This provider only accepts an id of 'default'" \
|
|
30
|
+
unless name.eql?('default')
|
|
31
|
+
@name = name
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.ntpconfigs
|
|
35
|
+
hash = {}
|
|
36
|
+
hash['default'] = NtpConfig.new('default')
|
|
37
|
+
hash
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def ==(other)
|
|
41
|
+
name == other.name
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def source_interface
|
|
45
|
+
source_interface = config_get('ntp_config', 'source_interface')
|
|
46
|
+
source_interface = source_interface[0].downcase \
|
|
47
|
+
unless source_interface.nil?
|
|
48
|
+
source_interface
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def source_interface=(val)
|
|
52
|
+
if val.nil? && !source_interface.nil?
|
|
53
|
+
config_set('ntp_config',
|
|
54
|
+
'source_interface',
|
|
55
|
+
state: 'no',
|
|
56
|
+
source_interface: source_interface)
|
|
57
|
+
elsif !val.nil?
|
|
58
|
+
config_set('ntp_config',
|
|
59
|
+
'source_interface',
|
|
60
|
+
state: '',
|
|
61
|
+
source_interface: val)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end # class
|
|
65
|
+
end # module
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# NTP Server provider class
|
|
2
|
+
#
|
|
3
|
+
# Jonathan Tripathy et al., September 2015
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2014-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_relative 'node'
|
|
20
|
+
require_relative 'interface'
|
|
21
|
+
|
|
22
|
+
module Cisco
|
|
23
|
+
# NtpServer - node utility class for NTP Server configuration management
|
|
24
|
+
class NtpServer < NodeUtil
|
|
25
|
+
def initialize(ntpserver_id, prefer, instantiate=true)
|
|
26
|
+
@ntpserver_id = ntpserver_id.to_s
|
|
27
|
+
@ntpserver_prefer = prefer
|
|
28
|
+
unless @ntpserver_id[/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/]
|
|
29
|
+
fail ArgumentError, 'Invalid value(IP is not an IP address)'
|
|
30
|
+
end
|
|
31
|
+
unless @ntpserver_prefer == true ||
|
|
32
|
+
@ntpserver_prefer == false ||
|
|
33
|
+
@ntpserver_prefer.nil?
|
|
34
|
+
fail ArgumentError, 'Invalid value(prefer must be true or false)'
|
|
35
|
+
end
|
|
36
|
+
create if instantiate
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.ntpservers
|
|
40
|
+
hash = {}
|
|
41
|
+
ntpservers_list = config_get('ntp_server', 'server')
|
|
42
|
+
return hash if ntpservers_list.nil?
|
|
43
|
+
|
|
44
|
+
preferred_servers = config_get('ntp_server', 'prefer')
|
|
45
|
+
preferred_servers = [] unless preferred_servers
|
|
46
|
+
|
|
47
|
+
ntpservers_list.each do |id|
|
|
48
|
+
hash[id] = NtpServer.new(id, preferred_servers.include?(id), false)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
hash
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def ==(other)
|
|
55
|
+
name == other.name && prefer == other.prefer
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def create
|
|
59
|
+
config_set('ntp_server', 'server', state: '', ip: @ntpserver_id,
|
|
60
|
+
prefer: @ntpserver_prefer ? 'prefer' : '')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def destroy
|
|
64
|
+
config_set('ntp_server', 'server',
|
|
65
|
+
state: 'no', ip: @ntpserver_id, prefer: '')
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def name
|
|
69
|
+
@ntpserver_id
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def prefer
|
|
73
|
+
@ntpserver_prefer
|
|
74
|
+
end
|
|
75
|
+
end # class
|
|
76
|
+
end # module
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# Platform provider class
|
|
2
|
-
#
|
|
3
1
|
# Alex Hunsberger, Mar 2015
|
|
4
2
|
#
|
|
5
3
|
# Copyright (c) 2015 Cisco and/or its affiliates.
|
|
@@ -16,169 +14,180 @@
|
|
|
16
14
|
# See the License for the specific language governing permissions and
|
|
17
15
|
# limitations under the License.
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
pkg_hsh
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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'], },
|
|
17
|
+
require_relative 'node_util'
|
|
18
|
+
|
|
19
|
+
module Cisco
|
|
20
|
+
# Platform - class for gathering platform hardware and software information
|
|
21
|
+
class Platform < NodeUtil
|
|
22
|
+
# ex: 'n3500-uk9.6.0.2.A3.0.40.bin'
|
|
23
|
+
def self.system_image
|
|
24
|
+
config_get('show_version', 'boot_image')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Returns package hash with state values
|
|
28
|
+
# Ex: { 'n3000-uk9.6.0.2.U1.1.CSCaa12345.bin' => 'inactive committed',
|
|
29
|
+
# 'n3000-uk9.6.0.2.U1.1.CSCaa12346.bin' => 'active', }
|
|
30
|
+
def self.packages
|
|
31
|
+
pkgs = config_get('images', 'packages')
|
|
32
|
+
return {} if pkgs.nil?
|
|
33
|
+
pkg_hsh = {}
|
|
34
|
+
pkgs.each { |p| pkg_hsh[p[0]] = p[1].downcase }
|
|
35
|
+
pkg_hsh
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Ex: 'Cisco Nexus3064 Chassis ("48x10GE + 16x10G/4x40G Supervisor")'
|
|
39
|
+
def self.hardware_type
|
|
40
|
+
config_get('show_version', 'description')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Ex: 'Intel(R) Celeron(R) CPU P450'
|
|
44
|
+
def self.cpu
|
|
45
|
+
config_get('show_version', 'cpu')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Return hash with keys "total", "used", "free"
|
|
49
|
+
# Ex: { 'total' => '16402252K',
|
|
50
|
+
# 'used' => '5909004K',
|
|
51
|
+
# 'free' => '10493248K' }
|
|
52
|
+
def self.memory
|
|
53
|
+
total = config_get('memory', 'total')
|
|
54
|
+
used = config_get('memory', 'used')
|
|
55
|
+
free = config_get('memory', 'free')
|
|
56
|
+
|
|
57
|
+
fail 'failed to retrieve platform memory information' if
|
|
58
|
+
total.nil? || used.nil? || free.nil?
|
|
59
|
+
|
|
60
|
+
{
|
|
61
|
+
'total' => total.first,
|
|
62
|
+
'used' => used.first,
|
|
63
|
+
'free' => free.first,
|
|
64
|
+
}
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Ex: 'Processor Board ID FOC15430TEY'
|
|
68
|
+
def self.board
|
|
69
|
+
config_get('show_version', 'board')
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Ex: '1 day(s), 21 hour(s), 46 minute(s), 54 second(s)'
|
|
73
|
+
def self.uptime
|
|
74
|
+
u = config_get('show_version', 'uptime')
|
|
75
|
+
fail 'failed to retrieve platform uptime' if u.nil?
|
|
76
|
+
u.first
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Ex: '23113 usecs after Mon Jul 1 15:24:29 2013'
|
|
80
|
+
def self.last_reset
|
|
81
|
+
r = config_get('show_version', 'last_reset_time')
|
|
82
|
+
r.nil? ? nil : r.strip
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Ex: 'Reset Requested by CLI command reload'
|
|
86
|
+
def self.reset_reason
|
|
87
|
+
config_get('show_version', 'last_reset_reason')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Returns chassis hash with keys "descr", "pid", "vid", "sn"
|
|
91
|
+
# Ex: { 'descr' => 'Nexus9000 C9396PX Chassis',
|
|
92
|
+
# 'pid' => 'N9K-C9396PX',
|
|
93
|
+
# 'vid' => 'V02',
|
|
94
|
+
# 'sn' => 'SAL1812NTBP' }
|
|
95
|
+
def self.chassis
|
|
96
|
+
node.cache_flush # TODO: investigate why this is needed
|
|
97
|
+
chas = config_get('inventory', 'chassis')
|
|
98
|
+
return nil if chas.nil?
|
|
99
|
+
{
|
|
100
|
+
'descr' => chas['desc'].tr('"', ''),
|
|
101
|
+
'pid' => chas['productid'],
|
|
102
|
+
'vid' => chas['vendorid'],
|
|
103
|
+
'sn' => chas['serialnum'],
|
|
180
104
|
}
|
|
181
|
-
|
|
182
|
-
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Returns hash of hashes with inner keys "name", "descr", "pid", "vid", "sn"
|
|
108
|
+
# Ex: { 'Slot 1' => { 'descr' => '1/10G SFP+ Ethernet Module',
|
|
109
|
+
# 'pid' => 'N9K-C9396PX',
|
|
110
|
+
# 'vid' => 'V02',
|
|
111
|
+
# 'sn' => 'SAL1812NTBP' },
|
|
112
|
+
# 'Slot 2' => { ... }}
|
|
113
|
+
def self.inventory_of(type)
|
|
114
|
+
node.cache_flush # TODO: investigate why this is needed
|
|
115
|
+
inv = config_get('inventory', 'all')
|
|
116
|
+
return {} if inv.nil?
|
|
117
|
+
inv.select! { |x| x['name'].include? type }
|
|
118
|
+
return {} if inv.empty?
|
|
119
|
+
# match desired output format
|
|
120
|
+
inv_hsh = {}
|
|
121
|
+
inv.each do |s|
|
|
122
|
+
inv_hsh[s['name'].tr('"', '')] = { 'descr' => s['desc'].tr('"', ''),
|
|
123
|
+
'pid' => s['productid'],
|
|
124
|
+
'vid' => s['vendorid'],
|
|
125
|
+
'sn' => s['serialnum'] }
|
|
126
|
+
end
|
|
127
|
+
inv_hsh
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Returns array of hashes with keys "name", "descr", "pid", "vid", "sn"
|
|
131
|
+
def self.slots
|
|
132
|
+
Platform.inventory_of('Slot')
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Returns array of hashes with keys "name", "descr", "pid", "vid", "sn"
|
|
136
|
+
def self.power_supplies
|
|
137
|
+
Platform.inventory_of('Power Supply')
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Returns array of hashes with keys "name", "descr", "pid", "vid", "sn"
|
|
141
|
+
def self.fans
|
|
142
|
+
Platform.inventory_of('Fan')
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Returns hash of hashes with inner keys "state", "application", ...
|
|
146
|
+
# Ex: { 'chef' => {
|
|
147
|
+
# 'package_info' => { 'name' => 'n3k_chef.ova',
|
|
148
|
+
# 'path' => 'bootflash:/n3k_chef.ova' },
|
|
149
|
+
# 'application' => { 'name' => 'ChefAgent',
|
|
150
|
+
# 'version' => '0.1',
|
|
151
|
+
# 'descr' => 'Cisco Chef Agent' },
|
|
152
|
+
# 'signing' => { 'key_type' => 'Cisco development key',
|
|
153
|
+
# 'method' => 'SHA-1' }
|
|
154
|
+
# 'licensing' => { 'name' => 'none',
|
|
155
|
+
# 'version' => 'none' }
|
|
156
|
+
# 'reservation' => { 'disk' => '111 MB',
|
|
157
|
+
# 'memory' => '0 MB',
|
|
158
|
+
# 'cpu' => '0% system CPU' }},
|
|
159
|
+
# { ... }}
|
|
160
|
+
def self.virtual_services
|
|
161
|
+
virts = config_get('virtual_service', 'services')
|
|
162
|
+
return [] if virts.nil?
|
|
163
|
+
# NXAPI returns hash instead of array if there's only 1
|
|
164
|
+
virts = [virts] if virts.is_a? Hash
|
|
165
|
+
# convert to expected format
|
|
166
|
+
virts_hsh = {}
|
|
167
|
+
virts.each do |serv|
|
|
168
|
+
# rubocop:disable Style/AlignHash, Style/ExtraSpacing
|
|
169
|
+
virts_hsh[serv['name']] = {
|
|
170
|
+
'package_info' => { 'name' => serv['package_name'],
|
|
171
|
+
'path' => serv['ova_path'],
|
|
172
|
+
},
|
|
173
|
+
'application' => { 'name' => serv['application_name'],
|
|
174
|
+
'version' => serv['application_version'],
|
|
175
|
+
'descr' => serv['application_description'],
|
|
176
|
+
},
|
|
177
|
+
'signing' => { 'key_type' => serv['key_type'],
|
|
178
|
+
'method' => serv['signing_method'],
|
|
179
|
+
},
|
|
180
|
+
'licensing' => { 'name' => serv['licensing_name'],
|
|
181
|
+
'version' => serv['licensing_version'],
|
|
182
|
+
},
|
|
183
|
+
'reservation' => { 'disk' => serv['disk_reservation'],
|
|
184
|
+
'memory' => serv['memory_reservation'],
|
|
185
|
+
'cpu' => serv['cpu_reservation'],
|
|
186
|
+
},
|
|
187
|
+
}
|
|
188
|
+
# rubocop:enable Style/AlignHash, Style/ExtraSpacing
|
|
189
|
+
end
|
|
190
|
+
virts_hsh
|
|
191
|
+
end
|
|
183
192
|
end
|
|
184
193
|
end
|