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.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +81 -1
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.md +72 -6
  6. data/CONTRIBUTING.md +32 -7
  7. data/README.md +70 -7
  8. data/Rakefile +17 -0
  9. data/bin/check_metric_limits.rb +109 -0
  10. data/bin/git/hooks/commit-msg/enforce_style +81 -0
  11. data/bin/git/hooks/hook_lib +108 -0
  12. data/bin/git/hooks/hooks-wrapper +38 -0
  13. data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
  14. data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
  15. data/bin/git/hooks/post-flow-release-start/update-version +19 -0
  16. data/bin/git/hooks/post-merge/update-hooks +6 -0
  17. data/bin/git/hooks/post-rewrite/update-hooks +6 -0
  18. data/bin/git/hooks/pre-commit/rubocop +20 -0
  19. data/bin/git/hooks/pre-commit/validate-diffs +31 -0
  20. data/bin/git/hooks/pre-push/check-changelog +24 -0
  21. data/bin/git/hooks/pre-push/rubocop +7 -0
  22. data/bin/git/update-hooks +65 -0
  23. data/cisco_node_utils.gemspec +9 -3
  24. data/docs/README-develop-best-practices.md +404 -0
  25. data/docs/README-develop-node-utils-APIs.md +215 -365
  26. data/docs/README-maintainers.md +33 -3
  27. data/docs/template-router.rb +89 -91
  28. data/docs/template-test_router.rb +52 -55
  29. data/lib/.rubocop.yml +18 -0
  30. data/lib/cisco_node_utils.rb +2 -19
  31. data/lib/cisco_node_utils/README_YAML.md +1 -9
  32. data/lib/cisco_node_utils/bgp.rb +664 -0
  33. data/lib/cisco_node_utils/bgp_af.rb +530 -0
  34. data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
  35. data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
  36. data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
  37. data/lib/cisco_node_utils/command_reference.rb +72 -74
  38. data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
  39. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
  40. data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
  41. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
  42. data/lib/cisco_node_utils/configparser_lib.rb +152 -147
  43. data/lib/cisco_node_utils/dns_domain.rb +79 -0
  44. data/lib/cisco_node_utils/domain_name.rb +71 -0
  45. data/lib/cisco_node_utils/interface.rb +167 -161
  46. data/lib/cisco_node_utils/interface_ospf.rb +78 -81
  47. data/lib/cisco_node_utils/name_server.rb +64 -0
  48. data/lib/cisco_node_utils/node.rb +154 -198
  49. data/lib/cisco_node_utils/node_util.rb +61 -0
  50. data/lib/cisco_node_utils/ntp_config.rb +65 -0
  51. data/lib/cisco_node_utils/ntp_server.rb +76 -0
  52. data/lib/cisco_node_utils/platform.rb +174 -165
  53. data/lib/cisco_node_utils/radius_global.rb +146 -0
  54. data/lib/cisco_node_utils/radius_server.rb +295 -0
  55. data/lib/cisco_node_utils/router_ospf.rb +59 -63
  56. data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
  57. data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
  58. data/lib/cisco_node_utils/snmpgroup.rb +22 -23
  59. data/lib/cisco_node_utils/snmpserver.rb +99 -103
  60. data/lib/cisco_node_utils/snmpuser.rb +294 -274
  61. data/lib/cisco_node_utils/syslog_server.rb +92 -0
  62. data/lib/cisco_node_utils/syslog_settings.rb +69 -0
  63. data/lib/cisco_node_utils/tacacs_server.rb +137 -133
  64. data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
  65. data/lib/cisco_node_utils/version.rb +2 -1
  66. data/lib/cisco_node_utils/vlan.rb +28 -31
  67. data/lib/cisco_node_utils/vrf.rb +80 -0
  68. data/lib/cisco_node_utils/vtp.rb +100 -97
  69. data/lib/cisco_node_utils/yum.rb +15 -17
  70. data/tests/.rubocop.yml +15 -0
  71. data/tests/basetest.rb +81 -36
  72. data/tests/ciscotest.rb +38 -78
  73. data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
  74. data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
  75. data/tests/test_bgp_af.rb +920 -0
  76. data/tests/test_bgp_neighbor.rb +403 -0
  77. data/tests/test_bgp_neighbor_af.rb +589 -0
  78. data/tests/test_command_config.rb +65 -62
  79. data/tests/test_command_reference.rb +31 -45
  80. data/tests/test_dns_domain.rb +113 -0
  81. data/tests/test_domain_name.rb +86 -0
  82. data/tests/test_interface.rb +424 -548
  83. data/tests/test_interface_ospf.rb +248 -432
  84. data/tests/test_interface_svi.rb +56 -79
  85. data/tests/test_interface_switchport.rb +196 -272
  86. data/tests/test_name_server.rb +85 -0
  87. data/tests/test_node.rb +7 -6
  88. data/tests/test_node_ext.rb +133 -186
  89. data/tests/test_ntp_config.rb +49 -0
  90. data/tests/test_ntp_server.rb +74 -0
  91. data/tests/test_platform.rb +58 -37
  92. data/tests/test_radius_global.rb +78 -0
  93. data/tests/test_radius_server.rb +185 -0
  94. data/tests/test_router_bgp.rb +838 -0
  95. data/tests/test_router_ospf.rb +49 -80
  96. data/tests/test_router_ospf_vrf.rb +274 -392
  97. data/tests/test_snmpcommunity.rb +128 -172
  98. data/tests/test_snmpgroup.rb +12 -14
  99. data/tests/test_snmpserver.rb +160 -189
  100. data/tests/test_snmpuser.rb +568 -717
  101. data/tests/test_syslog_server.rb +88 -0
  102. data/tests/test_syslog_settings.rb +54 -0
  103. data/tests/test_tacacs_server.rb +113 -148
  104. data/tests/test_tacacs_server_host.rb +108 -161
  105. data/tests/test_vlan.rb +63 -79
  106. data/tests/test_vrf.rb +92 -0
  107. data/tests/test_vtp.rb +108 -126
  108. data/tests/test_yum.rb +47 -41
  109. metadata +92 -56
  110. data/.rubocop_todo.yml +0 -293
  111. data/docs/.rubocop.yml +0 -13
  112. data/docs/template-feature.rb +0 -45
  113. data/docs/template-test_feature.rb +0 -51
  114. 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
- 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'], },
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
- virts_hsh
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