Class: Cisco::Platform

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/platform.rb

Overview

Platform - class for gathering platform hardware and software information

Class Method Summary collapse

Methods inherited from NodeUtil

client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?

Class Method Details

.boardObject

Ex: ‘Processor Board ID FOC15430TEY’



73
74
75
76
77
78
79
# File 'lib/cisco_node_utils/platform.rb', line 73

def self.board
  config_get('show_version', 'board')
rescue RuntimeError => e
  # Some Nexus platforms may fail to report this value.
  return nil if /No key/ =~ e.message
  raise
end

.chassisObject

Returns chassis hash with keys “descr”, “pid”, “vid”, “sn” Ex: { ‘descr’ => ‘Nexus9000 C9396PX Chassis’,

'pid'   => 'N9K-C9396PX',
'vid'   => 'V02',
'sn'    => 'SAL1812NTBP' }


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/cisco_node_utils/platform.rb', line 107

def self.chassis
  # node.cache_flush # TODO: investigate why this is needed
  all = config_get('inventory', 'chassis')
  return nil if all.nil?

  # item['name'] value is "\"Chassis\"" on most platforms,
  # but n5k/n6k use "Chassis" so make the quotes optional.
  chas = all.find { |item| item['name'][/^"?Chassis"?$/] }
  return nil if chas.nil?
  {
    'descr' => chas['desc'].tr('"', ''),
    'pid'   => chas['productid'],
    'vid'   => chas['vendorid'],
    'sn'    => chas['serialnum'],
  }
end

.cpuObject

Ex: ‘Intel® Celeron® CPU P450’



56
57
58
# File 'lib/cisco_node_utils/platform.rb', line 56

def self.cpu
  config_get('show_version', 'cpu')
end

.fansObject

Returns array of hashes with keys “name”, “descr”, “pid”, “vid”, “sn”



158
159
160
# File 'lib/cisco_node_utils/platform.rb', line 158

def self.fans
  Platform.inventory_of('Fan')
end

.hardware_typeObject

Ex: ‘Cisco Nexus3064 Chassis (“48x10GE + 16x10G/4x40G Supervisor”)’



51
52
53
# File 'lib/cisco_node_utils/platform.rb', line 51

def self.hardware_type
  config_get('show_version', 'description')
end

.image_versionObject

NX: 7.0(3)I2(3) [build 7.0(3)I2(2.118)] XR: 6.1.1.04I



25
26
27
# File 'lib/cisco_node_utils/platform.rb', line 25

def self.image_version
  config_get('show_version', 'version')
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' => { ... }}


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/cisco_node_utils/platform.rb', line 130

def self.inventory_of(type)
  inv = config_get('inventory', 'all')
  inv_hsh = {}
  return inv_hsh if inv.nil?
  # Nexus gets structured output
  inv_copy = inv.select { |x| x['name'].include? type }
  return inv_hsh if inv_copy.empty?
  # match desired output format
  inv_copy.each do |s|
    inv_hsh[s['name'].tr('"', '')] = { 'descr' => s['desc'].tr('"', ''),
                                       'pid'   => s['productid'],
                                       'vid'   => s['vendorid'],
                                       'sn'    => s['serialnum'] }
  end
  inv_hsh
end

.last_resetObject

Ex: ‘23113 usecs after Mon Jul 1 15:24:29 2013’



89
90
91
92
93
94
95
# File 'lib/cisco_node_utils/platform.rb', line 89

def self.last_reset
  config_get('show_version', 'last_reset_time')
rescue RuntimeError => e
  # Some Nexus platforms may fail to report this value.
  return nil if /No key/ =~ e.message
  raise
end

.memoryObject

Return hash with keys “total”, “used”, “free” Ex: { ‘total’ => ‘16402252K’,

'used'  => '5909004K',
'free'  => '10493248K' }


64
65
66
67
68
69
70
# File 'lib/cisco_node_utils/platform.rb', line 64

def self.memory
  {
    'total' => config_get('memory', 'total'),
    'used'  => config_get('memory', 'used'),
    'free'  => config_get('memory', 'free'),
  }
end

.packagesObject

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', }


37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cisco_node_utils/platform.rb', line 37

def self.packages
  pkgs = []
  pkg_hsh = {}
  begin
    pkgs = config_get('images', 'packages')
  rescue RuntimeError => e
    raise unless e.message[/Invalid command/]
  end
  return {} if pkgs.nil?
  pkgs.each { |p| pkg_hsh[p[0]] = p[1].downcase }
  pkg_hsh
end

.power_suppliesObject

Returns array of hashes with keys “name”, “descr”, “pid”, “vid”, “sn”



153
154
155
# File 'lib/cisco_node_utils/platform.rb', line 153

def self.power_supplies
  Platform.inventory_of('Power Supply')
end

.reset_reasonObject

Ex: ‘Reset Requested by CLI command reload’



98
99
100
# File 'lib/cisco_node_utils/platform.rb', line 98

def self.reset_reason
  config_get('show_version', 'last_reset_reason')
end

.slotsObject

Returns array of hashes with keys “name”, “descr”, “pid”, “vid”, “sn”



148
149
150
# File 'lib/cisco_node_utils/platform.rb', line 148

def self.slots
  Platform.inventory_of('Slot')
end

.system_imageObject

ex: ‘n3500-uk9.6.0.2.A3.0.40.bin’



30
31
32
# File 'lib/cisco_node_utils/platform.rb', line 30

def self.system_image
  config_get('show_version', 'system_image')
end

.uptimeObject

Ex: ‘1 day(s), 21 hour(s), 46 minute(s), 54 second(s)’



82
83
84
85
86
# File 'lib/cisco_node_utils/platform.rb', line 82

def self.uptime
  u = config_get('show_version', 'uptime')
  fail 'failed to retrieve platform uptime' if u.nil?
  u
end

.virtual_servicesObject

Returns hash of hashes with inner keys “state”, “application”, … Ex: { ‘chef’ => {

  'package_info' => { 'name'     => 'n3k_chef.ova',
                      'path'     => 'bootflash:/n3k_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' }},
{ ... }}


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/cisco_node_utils/platform.rb', line 177

def self.virtual_services
  # If no virtual-services are installed, this will result
  # in a RuntimeError.  We need to rescue this specific case.
  begin
    virts = config_get('virtual_service', 'services')
  rescue RuntimeError => e
    return {} if e.message[/No key \"TABLE_detail\"/]
    raise
  end
  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 do |serv|
    # rubocop:disable Style/AlignHash
    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'],
      },
    }
    # rubocop:enable Style/AlignHash
  end
  virts_hsh
end