56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/beaker/hypervisor/vsphere.rb', line 56
def cleanup
@logger.notify "Destroying vsphere boxes"
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 )
vm_names = @hosts.map {|h| h['vmname'] || h.name }
vms = vsphere_helper.find_vms vm_names
vm_names.each do |name|
unless vm = vms[name]
raise "Couldn't find VM #{name} in vSphere!"
end
if vm.runtime.powerState == "poweredOn"
@logger.notify "Shutting down #{vm.name}"
start = Time.now
vm.PowerOffVM_Task.wait_for_completion
@logger.notify(
"Spent %.2f seconds halting #{vm.name}" % (Time.now - start) )
end
end
vsphere_helper.close
end
|