Class: RbVmomi::VIM::VirtualMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/rbvmomi/vim/VirtualMachine.rb

Instance Method Summary collapse

Instance Method Details

#add_delta_disk_layer_on_all_disksObject

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.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rbvmomi/vim/VirtualMachine.rb', line 34

def add_delta_disk_layer_on_all_disks
  devices,  = self.collect 'config.hardware.device'
  disks = devices.grep(RbVmomi::VIM::VirtualDisk)
  # XXX: Should create a single reconfig spec instead of one per disk
  disks.each do |disk|
    spec = {
      :deviceChange => [
        {
          :operation => :remove,
          :device => disk
        },
        {
          :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
          },
        }
      ]
    }
    self.ReconfigVM_Task(:spec => spec).wait_for_completion
  end
end

#disksArray

Retrieve all virtual disk devices.

Returns:

  • (Array)

    Array of virtual disk devices.



10
11
12
# File 'lib/rbvmomi/vim/VirtualMachine.rb', line 10

def disks
  self.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
end

#guest_ipString

Get the IP of the guest, but only if it is not stale

Returns:

  • (String)

    Current IP reported (as per VMware Tools) or nil



16
17
18
19
20
21
22
23
# File 'lib/rbvmomi/vim/VirtualMachine.rb', line 16

def guest_ip 
  g = self.guest
  if g.ipAddress && (g.toolsStatus == "toolsOk" || g.toolsStatus == "toolsOld")
    g.ipAddress
  else
    nil
  end
end

#macsHash

Retrieve the MAC addresses for all virtual NICs.

Returns:

  • (Hash)

    Keyed by device label.



4
5
6
# File 'lib/rbvmomi/vim/VirtualMachine.rb', line 4

def macs
  Hash[self.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard).map { |x| [x.deviceInfo.label, x.macAddress] }]
end