Class: Beaker::Vsphere
- Inherits:
-
Hypervisor
- Object
- Hypervisor
- Beaker::Vsphere
- Defined in:
- lib/beaker/hypervisor/vsphere.rb
Constant Summary
Constants inherited from Hypervisor
Constants included from HostPrebuiltSteps
HostPrebuiltSteps::APT_CFG, HostPrebuiltSteps::CUMULUS_PACKAGES, HostPrebuiltSteps::DEBIAN_PACKAGES, HostPrebuiltSteps::ETC_HOSTS_PATH, HostPrebuiltSteps::ETC_HOSTS_PATH_SOLARIS, HostPrebuiltSteps::FREEBSD_PACKAGES, HostPrebuiltSteps::IPS_PKG_REPO, HostPrebuiltSteps::NTPSERVER, HostPrebuiltSteps::OPENBSD_PACKAGES, HostPrebuiltSteps::PSWINDOWS_PACKAGES, HostPrebuiltSteps::ROOT_KEYS_SCRIPT, HostPrebuiltSteps::ROOT_KEYS_SYNC_CMD, HostPrebuiltSteps::ROOT_KEYS_SYNC_CMD_AIX, HostPrebuiltSteps::SLEEPWAIT, HostPrebuiltSteps::SLES10_PACKAGES, HostPrebuiltSteps::SLES_PACKAGES, HostPrebuiltSteps::SOLARIS10_PACKAGES, HostPrebuiltSteps::TRIES, HostPrebuiltSteps::UNIX_PACKAGES, HostPrebuiltSteps::WINDOWS_PACKAGES
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize(vsphere_hosts, options) ⇒ Vsphere
constructor
A new instance of Vsphere.
- #provision ⇒ Object
Methods inherited from Hypervisor
#configure, create, #generate_host_name, #proxy_package_manager, #validate
Methods included from HostPrebuiltSteps
#add_el_extras, #additive_hash_merge, #apt_get_update, #check_and_install_packages_if_needed, #construct_env, #copy_file_to_remote, #copy_ssh_to_root, #disable_iptables, #disable_se_linux, #enable_root_login, #epel_info_for, #get_domain_name, #get_ip, #hack_etc_hosts, #package_proxy, #proxy_config, #set_env, #set_etc_hosts, #sync_root_keys, #timesync, #validate_host
Methods included from DSL::Patterns
Constructor Details
#initialize(vsphere_hosts, options) ⇒ Vsphere
Returns a new instance of Vsphere.
6 7 8 9 10 |
# File 'lib/beaker/hypervisor/vsphere.rb', line 6 def initialize(vsphere_hosts, ) @options = @logger = [:logger] @hosts = vsphere_hosts end |
Instance Method Details
#cleanup ⇒ Object
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 |
#provision ⇒ Object
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 # This will block for each snapshot... # The code to issue them all and then wait until they are all done sucks 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 |