Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/kitchen/driver/hyperv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Hyperv < Kitchen::Driver::Base
default_config :processor_count, 2
default_config :ip_address
default_config :vm_switch
default_config :iso_path

include Kitchen::Driver::PowerShellScripts

Expand All @@ -49,6 +50,7 @@ def create(state)
create_new_differencing_disk
create_virtual_machine
update_state
mount_virtual_machine_iso
instance.transport.connection(@state).wait_until_ready
info("Hyper-V instance #{instance.to_str} created.")
end
Expand All @@ -65,6 +67,12 @@ def destroy(state)

private

def mount_virtual_machine_iso
return unless config[:iso_path]
info("Mounting #{config[:iso_path]}")
run_ps mount_vm_iso
end

def validate_vm_settings
return if config[:vm_switch]
config[:vm_switch] = (run_ps vm_default_switch_ps)['Name']
Expand Down
6 changes: 6 additions & 0 deletions lib/kitchen/driver/powershell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ def vm_default_switch_ps
Get-DefaultVMSwitch | ConvertTo-Json
VMSWITCH
end

def mount_vm_iso
<<-MOUNTISO
mount-vmiso -id "#{@state[:id]}" -Path #{config[:iso_path]}
MOUNTISO
end
end
end
end
8 changes: 8 additions & 0 deletions support/hyperv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,12 @@ function Get-VmDetail
function Get-DefaultVMSwitch
{
Get-VMSwitch | Select -First 1
}

function Mount-VMISO {
[cmdletbinding()]
param($Id, $Path)

set-VMDvdDrive -VMName (get-vm -id $Id).Name -Path $Path

}