Class: Platform
- Inherits:
-
Object
- Object
- Platform
- Defined in:
- lib/cisco_node_utils/platform.rb
Constant Summary collapse
- @@node =
Cisco::Node.instance
Class Method Summary collapse
-
.board ⇒ Object
ex: ‘Processor Board ID FOC15430TEY’.
-
.chassis ⇒ Object
returns chassis hash with keys “descr”, “pid”, “vid”, “sn” ex: { ‘descr’ => ‘Nexus9000 C9396PX Chassis’, ‘pid’ => ‘N9K-C9396PX’, ‘vid’ => ‘V02’, ‘sn’ => ‘SAL1812NTBP’ }.
-
.cpu ⇒ Object
ex: ‘Intel® Celeron® CPU P450’.
-
.fans ⇒ Object
returns array of hashes with keys “name”, “descr”, “pid”, “vid”, “sn”.
-
.hardware_type ⇒ Object
ex: ‘Cisco Nexus3064 Chassis (“48x10GE + 16x10G/4x40G Supervisor”)’.
-
.inventory_of(type) ⇒ Object
returns hash of hashes with inner keys “name”, “descr”, “pid”, “vid”, “sn” ex: { ‘Slot 1’ => { ‘descr’ => ‘1/10G SFP+ Ethernet Module’, ‘pid’ => ‘N9K-C9396PX’, ‘vid’ => ‘V02’, ‘sn’ => ‘SAL1812NTBP’ }, ‘Slot 2’ => { … }}.
-
.last_reset ⇒ Object
ex: ‘23113 usecs after Mon Jul 1 15:24:29 2013’.
-
.memory ⇒ Object
return hash with keys “total”, “used”, “free” ex: { ‘total’ => ‘16402252K’, ‘used’ => ‘5909004K’, ‘free’ => ‘10493248K’ }.
-
.packages ⇒ Object
returns package hash with state values ex: { ‘n3000-uk9.6.0.2.U1.1.CSCaa12345.bin’ => ‘inactive committed’, ‘n3000-uk9.6.0.2.U1.1.CSCaa12346.bin’ => ‘active’, }.
-
.power_supplies ⇒ Object
returns array of hashes with keys “name”, “descr”, “pid”, “vid”, “sn”.
-
.reset_reason ⇒ Object
ex: ‘Reset Requested by CLI command reload’.
-
.slots ⇒ Object
returns array of hashes with keys “name”, “descr”, “pid”, “vid”, “sn”.
-
.system_image ⇒ Object
ex: ‘n3500-uk9.6.0.2.A3.0.40.bin’.
-
.uptime ⇒ Object
ex: ‘1 day(s), 21 hour(s), 46 minute(s), 54 second(s)’.
-
.virtual_services ⇒ Object
returns hash of hashes with inner keys “state”, “application”, …
Class Method Details
.board ⇒ Object
ex: ‘Processor Board ID FOC15430TEY’
70 71 72 |
# File 'lib/cisco_node_utils/platform.rb', line 70 def Platform.board @@node.config_get("show_version", "board") end |
.chassis ⇒ Object
returns chassis hash with keys “descr”, “pid”, “vid”, “sn” ex: { ‘descr’ => ‘Nexus9000 C9396PX Chassis’,
'pid' => 'N9K-C9396PX',
'vid' => 'V02',
'sn' => 'SAL1812NTBP' }
97 98 99 100 101 102 103 104 |
# File 'lib/cisco_node_utils/platform.rb', line 97 def Platform.chassis chas = @@node.config_get("inventory", "chassis") return nil if chas.nil? { 'descr' => chas['desc'].tr('"', ''), 'pid' => chas['productid'], 'vid' => chas['vendorid'], 'sn' => chas['serialnum'], } end |
.cpu ⇒ Object
ex: ‘Intel® Celeron® CPU P450’
48 49 50 |
# File 'lib/cisco_node_utils/platform.rb', line 48 def Platform.cpu @@node.config_get("show_version", "cpu") end |
.fans ⇒ Object
returns array of hashes with keys “name”, “descr”, “pid”, “vid”, “sn”
140 141 142 |
# File 'lib/cisco_node_utils/platform.rb', line 140 def Platform.fans Platform.inventory_of('Fan') end |
.hardware_type ⇒ Object
ex: ‘Cisco Nexus3064 Chassis (“48x10GE + 16x10G/4x40G Supervisor”)’
43 44 45 |
# File 'lib/cisco_node_utils/platform.rb', line 43 def Platform.hardware_type @@node.config_get("show_version", "description") end |
.inventory_of(type) ⇒ Object
returns hash of hashes with inner keys “name”, “descr”, “pid”, “vid”, “sn” ex: { ‘Slot 1’ => { ‘descr’ => ‘1/10G SFP+ Ethernet Module’,
'pid' => 'N9K-C9396PX',
'vid' => 'V02',
'sn' => 'SAL1812NTBP' },
'Slot 2' => { ... }}
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/cisco_node_utils/platform.rb', line 112 def Platform.inventory_of(type) @@node.cache_flush # TODO: investigate why this is needed inv = @@node.config_get("inventory", "all") return {} if inv.nil? inv.select! { |x| x['name'].include? type } return {} if inv.empty? # match desired output format inv_hsh = {} inv.each { |s| inv_hsh[s['name'].tr('"', '')] = { 'descr' => s['desc'].tr('"', ''), 'pid' => s['productid'], 'vid' => s['vendorid'], 'sn' => s['serialnum'] } } inv_hsh end |
.last_reset ⇒ Object
ex: ‘23113 usecs after Mon Jul 1 15:24:29 2013’
82 83 84 85 |
# File 'lib/cisco_node_utils/platform.rb', line 82 def Platform.last_reset r = @@node.config_get("show_version", "last_reset_time") r.nil? ? nil : r.strip end |
.memory ⇒ Object
return hash with keys “total”, “used”, “free” ex: { ‘total’ => ‘16402252K’,
'used' => '5909004K',
'free' => '10493248K' }
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cisco_node_utils/platform.rb', line 56 def Platform.memory total = @@node.config_get("memory", "total") used = @@node.config_get("memory", "used") free = @@node.config_get("memory", "free") raise "failed to retrieve platform memory information" if total.nil? or used.nil? or free.nil? { 'total' => total.first, 'used' => used.first, 'free' => free.first, } end |
.packages ⇒ Object
returns package hash with state values ex: { ‘n3000-uk9.6.0.2.U1.1.CSCaa12345.bin’ => ‘inactive committed’,
'n3000-uk9.6.0.2.U1.1.CSCaa12346.bin' => 'active', }
32 33 34 35 36 37 38 39 40 |
# File 'lib/cisco_node_utils/platform.rb', line 32 def Platform.packages pkgs = @@node.config_get("images", "packages") return {} if pkgs.nil? pkg_hsh = {} pkgs.each { |p| pkg_hsh[p[0]] = p[1].downcase } pkg_hsh end |
.power_supplies ⇒ Object
returns array of hashes with keys “name”, “descr”, “pid”, “vid”, “sn”
135 136 137 |
# File 'lib/cisco_node_utils/platform.rb', line 135 def Platform.power_supplies Platform.inventory_of('Power Supply') end |
.reset_reason ⇒ Object
ex: ‘Reset Requested by CLI command reload’
88 89 90 |
# File 'lib/cisco_node_utils/platform.rb', line 88 def Platform.reset_reason @@node.config_get("show_version", "last_reset_reason") end |
.slots ⇒ Object
returns array of hashes with keys “name”, “descr”, “pid”, “vid”, “sn”
130 131 132 |
# File 'lib/cisco_node_utils/platform.rb', line 130 def Platform.slots Platform.inventory_of('Slot') end |
.system_image ⇒ Object
ex: ‘n3500-uk9.6.0.2.A3.0.40.bin’
25 26 27 |
# File 'lib/cisco_node_utils/platform.rb', line 25 def Platform.system_image @@node.config_get("show_version", "boot_image") end |
.uptime ⇒ Object
ex: ‘1 day(s), 21 hour(s), 46 minute(s), 54 second(s)’
75 76 77 78 79 |
# File 'lib/cisco_node_utils/platform.rb', line 75 def Platform.uptime u = @@node.config_get("show_version", "uptime") raise "failed to retrieve platform uptime" if u.nil? u.first end |
.virtual_services ⇒ Object
returns hash of hashes with inner keys “state”, “application”, … ex: { ‘chef’ => {
'package_info' => { 'name' => 'n3k_chanm_chef.ova',
'path' => 'bootflash:/n3k_chanm_chef.ova' },
'application' => { 'name' => 'ChefAgent',
'version' => '0.1',
'descr' => 'Cisco Chef Agent' },
'signing' => { 'key_type' => 'Cisco development key',
'method' => 'SHA-1' }
'licensing' => { 'name' => 'none',
'version' => 'none' }
'reservation' => { 'disk' => '111 MB',
'memory' => '0 MB',
'cpu' => '0% system CPU' }},
{ ... }}
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/cisco_node_utils/platform.rb', line 159 def Platform.virtual_services virts = @@node.config_get("virtual_service", "services") return [] if virts.nil? # NXAPI returns hash instead of array if there's only 1 virts = [virts] if virts.is_a? Hash # convert to expected format virts_hsh = {} virts.each { |serv| virts_hsh[serv['name']] = { 'package_info' => { 'name' => serv['package_name'], 'path' => serv['ova_path'], }, 'application' => { 'name' => serv['application_name'], 'version' => serv['application_version'], 'descr' => serv['application_description'], }, 'signing' => { 'key_type' => serv['key_type'], 'method' => serv['signing_method'], }, 'licensing' => { 'name' => serv['licensing_name'], 'version' => serv['licensing_version'], }, 'reservation' => { 'disk' => serv['disk_reservation'], 'memory' => serv['memory_reservation'], 'cpu' => serv['cpu_reservation'], }, } } virts_hsh end |