Class: RbVmomi::VIM::VirtualMachine
- Inherits:
-
Object
- Object
- RbVmomi::VIM::VirtualMachine
- Defined in:
- lib/rbvmomi/vim/VirtualMachine.rb
Overview
Copyright © 2011-2017 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: MIT
Instance Method Summary collapse
-
#add_delta_disk_layer_on_all_disks ⇒ Object
Add a layer of delta disks (redo logs) in front of every disk on the VM.
-
#disks ⇒ Array
Retrieve all virtual disk devices.
-
#guest_ip ⇒ String
Get the IP of the guest, but only if it is not stale.
-
#macs ⇒ Hash
Retrieve the MAC addresses for all virtual NICs.
-
#update_spec_add_delta_disk_layer_on_all_disks(spec = {}) ⇒ Object
Updates a passed in spec to perform the task of adding a delta disk layer on top of all disks.
Instance Method Details
#add_delta_disk_layer_on_all_disks ⇒ Object
Add a layer of delta disks (redo logs) in front of every disk on the VM. This is similar to taking a snapshot and makes the VM a valid target for creating a linked clone.
Background: The API for linked clones is quite strange. We can’t create a linked straight from any VM. The disks of the VM for which we can create a linked clone need to be read-only and thus VC demands that the VM we are cloning from uses delta-disks. Only then it will allow us to share the base disk.
38 39 40 41 |
# File 'lib/rbvmomi/vim/VirtualMachine.rb', line 38 def add_delta_disk_layer_on_all_disks spec = update_spec_add_delta_disk_layer_on_all_disks self.ReconfigVM_Task(spec: spec).wait_for_completion end |
#disks ⇒ Array
Retrieve all virtual disk devices.
14 15 16 |
# File 'lib/rbvmomi/vim/VirtualMachine.rb', line 14 def disks self.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk) end |
#guest_ip ⇒ String
Get the IP of the guest, but only if it is not stale
20 21 22 23 24 25 26 27 |
# File 'lib/rbvmomi/vim/VirtualMachine.rb', line 20 def guest_ip g = self.guest if g.ipAddress && (g.toolsStatus == 'toolsOk' || g.toolsStatus == 'toolsOld') g.ipAddress else nil end end |
#macs ⇒ Hash
Retrieve the MAC addresses for all virtual NICs.
8 9 10 |
# File 'lib/rbvmomi/vim/VirtualMachine.rb', line 8 def macs Hash[self.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard).map { |x| [x.deviceInfo.label, x.macAddress] }] end |
#update_spec_add_delta_disk_layer_on_all_disks(spec = {}) ⇒ Object
Updates a passed in spec to perform the task of adding a delta disk layer on top of all disks. Does the same as add_delta_disk_layer_on_all_disks but instead of issuing the ReconfigVM_Task, it just constructs the spec, so that the caller can batch a couple of updates into one ReconfigVM_Task.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rbvmomi/vim/VirtualMachine.rb', line 48 def update_spec_add_delta_disk_layer_on_all_disks spec = {} devices, = self.collect 'config.hardware.device' disks = devices.grep(RbVmomi::VIM::VirtualDisk) device_change = [] disks.each do |disk| device_change << { operation: :remove, device: disk } device_change << { operation: :add, fileOperation: :create, device: disk.dup.tap { |x| x.backing = x.backing.dup x.backing.fileName = "[#{disk.backing.datastore.name}]" x.backing.parent = disk.backing }, } end if spec.is_a?(RbVmomi::VIM::VirtualMachineConfigSpec) spec.deviceChange ||= [] spec.deviceChange += device_change else spec[:deviceChange] ||= [] spec[:deviceChange] += device_change end spec end |