Class: Kitchen::Driver::Hyperv
- Inherits:
-
Base
- Object
- Base
- Kitchen::Driver::Hyperv
- Includes:
- PowerShellScripts
- Defined in:
- lib/kitchen/driver/hyperv.rb
Overview
Test Kitchen driver that builds instances as Hyper-V virtual machines.
The driver never talks to Hyper-V directly. It generates PowerShell that
calls the helper functions in support/hyperv.ps1 and runs that script
through a Train connection -- a local one on a Hyper-V host, or WinRM
when hyperv_server points at a remote host.
Each instance gets a differencing disk cloned from a shared parent VHD, so creating an instance costs a few seconds and very little disk.
Instance Method Summary collapse
-
#create(state) ⇒ void
Create the virtual machine and wait until it is reachable.
-
#destroy(state) ⇒ void
Destroy the virtual machine and the disks created alongside it.
Methods included from PowerShellScripts
#additional_disks, #copy_vm_file_ps, #delete_vm_ps, #encode_command, #ensure_vm_running_ps, #execute_command, #is_32bit?, #is_64bit?, #mount_vm_iso, #new_additional_disk_ps, #new_differencing_disk_ps, #new_vm_ps, #powershell_64_bit, #resize_vhd, #run_ps, #sanitize_stdout, #set_vm_ipaddress_ps, #set_vm_note, #vm_default_switch_ps, #vm_details_ps, #wrap_command
Instance Method Details
#create(state) ⇒ void
This method returns an undefined value.
Create the virtual machine and wait until it is reachable.
Runs the full bring-up in order: validate the configuration, clone the parent VHD into a differencing disk, create any additional data disks, create and start the VM, then block on the transport until the guest accepts connections.
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/kitchen/driver/hyperv.rb', line 103 def create(state) @state = state validate_vm_settings create_new_differencing_disk create_additional_disks create_virtual_machine set_virtual_machine_note update_state mount_virtual_machine_iso instance.transport.connection(@state).wait_until_ready copy_vm_files info("Hyper-V instance #{instance.to_str} created.") end |
#destroy(state) ⇒ void
This method returns an undefined value.
Destroy the virtual machine and the disks created alongside it.
Safe to call repeatedly and safe to call when the VM was removed out of band: a differencing disk left behind by a partial create is cleaned up even when no VM exists.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/kitchen/driver/hyperv.rb', line 125 def destroy(state) @state = state if differencing_disk_exists && !vm_exists_silent remove_differencing_disk end unless vm_exists # The VM is gone, but a stale id would make every later run believe # otherwise, so clear it rather than returning with it still in place. state.delete(:id) return end instance.transport.connection(state).close remove_virtual_machine remove_differencing_disk remove_additional_disks info("The Hyper-V instance #{instance.to_str} has been removed.") state.delete(:id) end |