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

config_get, #config_get, config_get_default, #config_get_default, #config_set, config_set, #node, node, #show

Class Method Details

.board ⇒ Object

Ex: 'Processor Board ID FOC15430TEY'



68
69
70
# File 'lib/cisco_node_utils/platform.rb', line 68

def self.board
  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' }



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cisco_node_utils/platform.rb', line 94

def self.chassis
  node.cache_flush # TODO: investigate why this is needed
  chas = 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(R) Celeron(R) CPU P450'



44
45
46
# File 'lib/cisco_node_utils/platform.rb', line 44

def self.cpu
  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 self.fans
  Platform.inventory_of('Fan')
end

.hardware_type ⇒ Object

Ex: 'Cisco Nexus3064 Chassis ("48x10GE + 16x10G/4x40G Supervisor")'



39
40
41
# File 'lib/cisco_node_utils/platform.rb', line 39

def self.hardware_type
  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 self.inventory_of(type)
  node.cache_flush # TODO: investigate why this is needed
  inv = 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 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_reset ⇒ Object

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



80
81
82
# File 'lib/cisco_node_utils/platform.rb', line 80

def self.last_reset
  config_get('show_version', 'last_reset_time')
end

.memory ⇒ Object

Return hash with keys "total", "used", "free" Ex: { 'total' => '16402252K', 'used' => '5909004K', 'free' => '10493248K' }



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cisco_node_utils/platform.rb', line 52

def self.memory
  total = config_get('memory', 'total')
  used = config_get('memory', 'used')
  free = config_get('memory', 'free')

  fail 'failed to retrieve platform memory information' if
    total.nil? || used.nil? || free.nil?

  {
    'total' => total,
    'used'  => used,
    'free'  => free,
  }
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', }



30
31
32
33
34
35
36
# File 'lib/cisco_node_utils/platform.rb', line 30

def self.packages
  pkgs = 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 self.power_supplies
  Platform.inventory_of('Power Supply')
end

.reset_reason ⇒ Object

Ex: 'Reset Requested by CLI command reload'



85
86
87
# File 'lib/cisco_node_utils/platform.rb', line 85

def self.reset_reason
  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 self.slots
  Platform.inventory_of('Slot')
end

.system_image ⇒ Object

ex: 'n3500-uk9.6.0.2.A3.0.40.bin'



23
24
25
# File 'lib/cisco_node_utils/platform.rb', line 23

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

.uptime ⇒ Object

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



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

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

.virtual_services ⇒ Object

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



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
184
185
186
187
188
189
190
# File 'lib/cisco_node_utils/platform.rb', line 159

def self.virtual_services
  virts = 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 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