Class: RbVmomi::VIM::HostSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/rvc/extensions/HostSystem.rb

Overview

Copyright © 2011 VMware, Inc. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ls_propertiesObject



22
23
24
25
26
# File 'lib/rvc/extensions/HostSystem.rb', line 22

def self.ls_properties
  %w(name summary.hardware.memorySize summary.hardware.cpuModel
     summary.hardware.cpuMhz summary.hardware.numCpuPkgs
     summary.hardware.numCpuCores summary.hardware.numCpuThreads)
end

Instance Method Details

#childrenObject



147
148
149
150
151
152
153
# File 'lib/rvc/extensions/HostSystem.rb', line 147

def children
  {
    'vms' => RVC::FakeFolder.new(self, :ls_vms),
    'datastores' => RVC::FakeFolder.new(self, :ls_datastores),
    'networks' => RVC::FakeFolder.new(self, :ls_networks),
  }
end

#display_infoObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/rvc/extensions/HostSystem.rb', line 123

def display_info
  super
  summary = self.summary
  runtime = summary.runtime
  stats = summary.quickStats
  hw = summary.hardware
  puts "connection state: #{runtime.connectionState}"
  puts "power state: #{runtime.powerState}"
  puts "uptime: #{"%0.2f" % ((Time.now - runtime.bootTime)/(24*3600))} days" if runtime.bootTime
  puts "in maintenance mode: #{runtime.inMaintenanceMode}"
  puts "standby mode: #{runtime.standbyMode}" if runtime.standbyMode
  if about = summary.config.product
    puts "product: #{about.fullName}"
    puts "license: #{about.licenseProductName} #{about.licenseProductVersion}" if about.licenseProductName
  end
  if runtime.connectionState == 'connected' and runtime.powerState == 'poweredOn'
    overallCpu = hw.numCpuPkgs * hw.numCpuCores * hw.cpuMhz
    puts "cpu: %d*%d*%.2f GHz = %.2f GHz" % [hw.numCpuPkgs, hw.numCpuCores, hw.cpuMhz/1e3, overallCpu/1e3]
    puts "cpu usage: %.2f GHz (%.1f%%)" % [stats.overallCpuUsage/1e3, 100*stats.overallCpuUsage/overallCpu]
    puts "memory: %.2f GB" % [hw.memorySize/1e9]
    puts "memory usage: %.2f GB (%.1f%%)" % [stats.overallMemoryUsage/1e3, 100*1e6*stats.overallMemoryUsage/hw.memorySize]
  end
end

#ls_datastoresObject



159
160
161
# File 'lib/rvc/extensions/HostSystem.rb', line 159

def ls_datastores
  RVC::Util.collect_children self, :datastore
end

#ls_networksObject



163
164
165
# File 'lib/rvc/extensions/HostSystem.rb', line 163

def ls_networks
  RVC::Util.collect_children self, :network
end

#ls_text(r) ⇒ Object



28
29
30
31
32
# File 'lib/rvc/extensions/HostSystem.rb', line 28

def ls_text r
  memorySize, cpuModel, cpuMhz, numCpuPkgs, numCpuCores =
    %w(memorySize cpuModel cpuMhz numCpuPkgs numCpuCores).map { |x| r["summary.hardware.#{x}"] }
  " (host): cpu #{numCpuPkgs}*#{numCpuCores}*#{"%.2f" % (cpuMhz.to_f/1000)} GHz, memory #{"%.2f" % (memorySize/10**9)} GB"
end

#ls_vmsObject



155
156
157
# File 'lib/rvc/extensions/HostSystem.rb', line 155

def ls_vms
  RVC::Util.collect_children self, :vm
end