Class: RbVmomi::VIM::VirtualMachine
- Inherits:
-
Object
- Object
- RbVmomi::VIM::VirtualMachine
- Defined in:
- lib/rvc/extensions/VirtualMachine.rb,
lib/rvc/modules/spbm.rb,
lib/rvc/modules/spbm.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
- #all_pbmobjref(opts = {}) ⇒ Object
- #children ⇒ Object
- #disks_pbmobjref(opts = {}) ⇒ Object
- #display_info ⇒ Object
- #ls_text(r) ⇒ Object
- #rvc_children_datastores ⇒ Object
- #rvc_children_devices ⇒ Object
- #rvc_children_files ⇒ Object
- #rvc_children_networks ⇒ Object
- #rvc_children_vmprofiles ⇒ Object
- #rvc_list_children_vmprofiles ⇒ Object
Class Method Details
.ls_properties ⇒ Object
193 194 195 |
# File 'lib/rvc/extensions/VirtualMachine.rb', line 193 def self.ls_properties %w(name runtime.powerState runtime.connectionState) end |
Instance Method Details
#all_pbmobjref(opts = {}) ⇒ Object
223 224 225 |
# File 'lib/rvc/modules/spbm.rb', line 223 def all_pbmobjref(opts = {}) [to_pbmobjref] + disks_pbmobjref(opts) end |
#children ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/rvc/extensions/VirtualMachine.rb', line 205 def children host, resourcePool = collect *%w(runtime.host resourcePool) { 'host' => host, 'resourcePool' => resourcePool, 'datastores' => RVC::FakeFolder.new(self, :rvc_children_datastores), 'networks' => RVC::FakeFolder.new(self, :rvc_children_networks), 'files' => RVC::FakeFolder.new(self, :rvc_children_files), 'snapshots' => RVC::RootSnapshotFolder.new(self), 'devices' => RVC::FakeFolder.new(self, :rvc_children_devices), } end |
#disks_pbmobjref(opts = {}) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/rvc/modules/spbm.rb', line 206 def disks_pbmobjref(opts = {}) if opts[:vms_props] && opts[:vms_props][self] && opts[:vms_props][self]['config.hardware.device'] devices = opts[:vms_props][self]['config.hardware.device'] _disks = devices.select{|x| x.is_a?(VIM::VirtualDisk)} else _disks = disks end _disks.map do |disk| PBM::PbmServerObjectRef( :objectType => "virtualDiskId", :key => "#{self._ref}:#{disk.key}", :serverUuid => _connection.serviceContent.about.instanceUuid ) end end |
#display_info ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 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 191 |
# File 'lib/rvc/extensions/VirtualMachine.rb', line 147 def display_info config, runtime, guest = collect :config, :runtime, :guest RVC::Util.err "Information currently unavailable" unless config and runtime and guest puts "name: #{config.name}" puts "note: #{config.annotation}" if config.annotation and !config.annotation.empty? puts "host: #{runtime.host.path[1..-1].map { |x| x[1] } * '/'}" if runtime.host puts "tools: #{guest.toolsRunningStatus}" puts "hostname: #{guest.hostName} (#{guest.ipAddress})" if guest.hostName and guest.ipAddress puts "VC UUID: #{config.instanceUuid}" if config.instanceUuid and !config.instanceUuid.empty? puts "power: #{runtime.powerState}" puts "connectionState: #{runtime.connectionState}" if runtime.question puts "question: #{runtime.question.text.lines.to_a.join("> ")}" puts "choices: #{runtime.question.choice.choiceInfo.map(&:label) * ', '}" if i = runtime.question.choice.defaultIndex puts "default: #{runtime.question.choice.choiceInfo[i].label}" end end puts "cpus: #{config.hardware.numCPU}" puts "memory: #{config.hardware.memoryMB} MB" puts "nics:" config.hardware.device.grep RbVmomi::VIM::VirtualEthernetCard do |dev| backing_info = case dev.backing when RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo dev.backing.deviceName.inspect when RbVmomi::VIM::VirtualEthernetCardDistributedVirtualPortBackingInfo dev.backing.port.portgroupKey.inspect else dev.backing.class.name end guest_net = guest.net.find { |x| x.macAddress == dev.macAddress } puts " #{dev.name}: #{backing_info} #{dev.connectable.connected ? :connected : :disconnected} #{dev.macAddress} #{guest_net ? (guest_net.ipAddress * ' ') : ''}" end puts "storage:" storage.perDatastoreUsage.map do |usage| puts " #{usage.datastore.name}: committed=#{usage.committed.metric}B uncommitted=#{usage.uncommitted.metric}B unshared=#{usage.unshared.metric}B" end if runtime.dasVmProtection puts "HA protected: #{runtime.dasVmProtection.dasProtected ? 'yes' : 'no'}" end end |
#ls_text(r) ⇒ Object
197 198 199 200 201 202 203 |
# File 'lib/rvc/extensions/VirtualMachine.rb', line 197 def ls_text r out = ": #{r['runtime.powerState']}" if r['runtime.connectionState'] != 'connected' out = "#{out}, #{r['runtime.connectionState']}" end out end |
#rvc_children_datastores ⇒ Object
218 219 220 |
# File 'lib/rvc/extensions/VirtualMachine.rb', line 218 def rvc_children_datastores RVC::Util.collect_children self, :datastore end |
#rvc_children_devices ⇒ Object
240 241 242 243 244 |
# File 'lib/rvc/extensions/VirtualMachine.rb', line 240 def rvc_children_devices devices, = collect 'config.hardware.device' devices.each { |x| x.rvc_vm = self } Hash[devices.map { |x| [x.name, x] }] end |
#rvc_children_files ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/rvc/extensions/VirtualMachine.rb', line 226 def rvc_children_files files = layoutEx.file datastore_map = RVC::Util.collect_children self, :datastore Hash[files.map do |file| file.name =~ /^\[(.+)\] (.+)$/ or fail "invalid datastore path" ds = datastore_map[$1] or fail "datastore #{$1.inspect} not found" arcs, = RVC::Path.parse $2 arcs.unshift 'files' objs = $shell.fs.traverse ds, arcs fail unless objs.size == 1 [File.basename(file.name), objs.first] end] end |
#rvc_children_networks ⇒ Object
222 223 224 |
# File 'lib/rvc/extensions/VirtualMachine.rb', line 222 def rvc_children_networks RVC::Util.collect_children self, :network end |
#rvc_children_vmprofiles ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/rvc/modules/spbm.rb', line 156 def rvc_children_vmprofiles conn = _connection _catch_spbm_resets(conn) do pbm = _connection.pbm profiles = pbm_associated_profiles Hash[profiles.map do |x| x.instance_variable_set(:@connection, pbm) x.instance_variable_set(:@dc, self) [x.name, x] end] end end |
#rvc_list_children_vmprofiles ⇒ Object
150 151 152 153 154 |
# File 'lib/rvc/modules/spbm.rb', line 150 def rvc_list_children_vmprofiles { 'vmprofiles' => RVC::FakeFolder.new(self, :rvc_children_vmprofiles), } end |