12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/beaker/hypervisor/vsphere.rb', line 12
def provision
vsphere_credentials = VsphereHelper.load_config(@options[:dot_fog])
@logger.notify "Connecting to vSphere at #{vsphere_credentials[:server]}" +
" with credentials for #{vsphere_credentials[:user]}"
vsphere_helper = VsphereHelper.new( vsphere_credentials )
vsphere_vms = {}
@hosts.each do |h|
name = h["vmname"] || h.name
vsphere_vms[name] = h["snapshot"]
end
vms = vsphere_helper.find_vms(vsphere_vms.keys)
vsphere_vms.each_pair do |name, snap|
unless vm = vms[name]
raise "Couldn't find VM #{name} in vSphere!"
end
if snap
snapshot = vsphere_helper.find_snapshot(vm, snap) or
raise "Could not find snapshot '#{snap}' for VM #{vm.name}!"
@logger.notify "Reverting #{vm.name} to snapshot '#{snap}'"
start = Time.now
snapshot.RevertToSnapshot_Task.wait_for_completion
time = Time.now - start
@logger.notify "Spent %.2f seconds reverting" % time
end
unless vm.runtime.powerState == "poweredOn"
@logger.notify "Booting #{vm.name}"
start = Time.now
vm.PowerOnVM_Task.wait_for_completion
@logger.notify "Spent %.2f seconds booting #{vm.name}" % (Time.now - start)
end
end
vsphere_helper.close
end
|