initial support for gen2 and fix driver_mock

This commit is contained in:
William Brooks 2020-02-21 01:30:59 -06:00
parent 5e1e4ec701
commit dd8f4370c6
2 changed files with 33 additions and 11 deletions

View File

@ -234,9 +234,16 @@ type DriverMock struct {
SetBootDvdDrive_ControllerNumber uint
SetBootDvdDrive_ControllerLocation uint
SetBootDvdDrive_Generation uint
SetBootDvdDrive_LegacyGen1BootOrder bool
SetBootDvdDrive_Err error
SetFirstBootDevice_Called bool
SetFirstBootDevice_VmName string
SetFirstBootDevice_ControllerType string
SetFirstBootDevice_ControllerNumber uint
SetFirstBootDevice_ControllerLocation uint
SetFirstBootDevice_Generation uint
SetFirstBootDevice_Err error
UnmountDvdDrive_Called bool
UnmountDvdDrive_VmName string
UnmountDvdDrive_ControllerNumber uint

View File

@ -205,18 +205,33 @@ param([string] $vmName, [string] $controllerType)
func SetFirstBootDeviceGen2(vmName string, controllerType string, controllerNumber uint, controllerLocation uint) error {
// script := `
// param([string]$vmName,[int]$controllerNumber,[int]$controllerLocation)
// $vmDvdDrive = Hyper-V\Get-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -ControllerLocation $controllerLocation
// if (!$vmDvdDrive) {throw 'unable to find dvd drive'}
// Hyper-V\Set-VMFirmware -VMName $vmName -FirstBootDevice $vmDvdDrive -ErrorAction SilentlyContinue
// `
script := `
param ([string] $vmName, [string] $controllerType, [int] $controllerNumber, [int] $controllerLocation)
`
// script := `
// param([string] $vmName, [string] $controllerType, )
//`
switch {
return nil
case controllerType == "CD":
// for CDs we have to use Get-VMDvdDrive to find the device
script += `$bootDevice = Hyper-V\Get-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -ControllerLocation $controllerLocation -ErrorAction SilentlyContinue`
case controllerType == "NET":
// for "NET" device, we select the first network adapter on the VM
script += `$bootDevice = Hyper-V\Get-VMNetworkAdapter -VMName $vmName -ErrorAction SilentlyContinue | Select-Object -First 1`
default:
script += `$bootDevice = Hyper-V\Get-VMHardDiskDrive -VMName $vmName -ControllerType $controllerType -ControllerNumber $controllerNumber -ControllerLocation controllerLocation -ErrorAction SilentlyContinue`
}
script += `
if ($bootDevice -ne $null) { throw 'unable to find boot device' }
Hyper-V\Set-VMFirmware -VMName $vmName -FirstBootDevice $bootDevice
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, controllerType, strconv.FormatInt(int64(controllerNumber), 10), strconv.FormatInt(int64(controllerLocation), 10))
return err
}
func SetFirstBootDevice(vmName string, controllerType string, controllerNumber uint, controllerLocation uint, generation uint) error {