Setting boot drive is generation specific

This commit is contained in:
Taliesin Sisson 2015-11-07 13:42:26 +00:00
parent 93a2615f7a
commit 18241e5215
4 changed files with 29 additions and 19 deletions

View File

@ -89,14 +89,14 @@ type Driver interface {
CreateDvdDrive(string, uint) (uint, uint, error)
MountDvdDrive(string, string, uint, uint) error
SetBootDvdDrive(string, uint, uint) error
SetBootDvdDrive(string, uint, uint, uint) error
UnmountDvdDrive(string, uint, uint) error
DeleteDvdDrive(string, uint, uint) error
MountFloppyDrive(string, string) error
UnmountFloppyDrive(string) error
}

View File

@ -213,8 +213,8 @@ func (d *HypervPS4Driver) MountDvdDrive(vmName string, path string, controllerNu
return hyperv.MountDvdDrive(vmName, path, controllerNumber, controllerLocation)
}
func (d *HypervPS4Driver) SetBootDvdDrive(vmName string, controllerNumber uint, controllerLocation uint) error {
return hyperv.SetBootDvdDrive(vmName, controllerNumber, controllerLocation)
func (d *HypervPS4Driver) SetBootDvdDrive(vmName string, controllerNumber uint, controllerLocation uint, generation uint) error {
return hyperv.SetBootDvdDrive(vmName, controllerNumber, controllerLocation, generation)
}
func (d *HypervPS4Driver) UnmountDvdDrive(vmName string, controllerNumber uint, controllerLocation uint) error {

View File

@ -12,7 +12,7 @@ import (
)
type StepMountDvdDrive struct {
Generation uint
Generation uint
}
func (s *StepMountDvdDrive) Run(state multistep.StateBag) multistep.StepAction {
@ -40,11 +40,11 @@ func (s *StepMountDvdDrive) Run(state multistep.StateBag) multistep.StepAction {
dvdControllerProperties.ControllerNumber = controllerNumber
dvdControllerProperties.ControllerLocation = controllerLocation
dvdControllerProperties.Existing = false
state.Put("os.dvd.properties", dvdControllerProperties)
ui.Say(fmt.Sprintf("Setting boot drive to os dvd drive %s ...", isoPath))
err = driver.SetBootDvdDrive(vmName, controllerNumber, controllerLocation)
err = driver.SetBootDvdDrive(vmName, controllerNumber, controllerLocation, s.Generation)
if err != nil {
err := fmt.Errorf(errorMsg, err)
state.Put("error", err)
@ -64,14 +64,14 @@ func (s *StepMountDvdDrive) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue
}
func (s *StepMountDvdDrive) Cleanup(state multistep.StateBag) {
func (s *StepMountDvdDrive) Cleanup(state multistep.StateBag) {
dvdControllerState := state.Get("os.dvd.properties")
if dvdControllerState == nil {
return
}
dvdController := dvdControllerState.(DvdControllerProperties)
dvdController := dvdControllerState.(DvdControllerProperties)
driver := state.Get("driver").(Driver)
vmName := state.Get("vmName").(string)
ui := state.Get("ui").(packer.Ui)

View File

@ -135,17 +135,27 @@ Set-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -ControllerLo
return err
}
func SetBootDvdDrive(vmName string, controllerNumber uint, controllerLocation uint) error {
var script = `
func SetBootDvdDrive(vmName string, controllerNumber uint, controllerLocation uint, generation uint) error {
if generation < 2 {
script := `
param([string]$vmName)
Set-VMBios -VMName $vmName -StartupOrder @("CD", "IDE","LegacyNetworkAdapter","Floppy")
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName)
return err
} else {
script := `
param([string]$vmName,[int]$controllerNumber,[int]$controllerLocation)
$vmDvdDrive = Get-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -ControllerLocation $controllerLocation
if (!$vmDvdDrive) {throw 'unable to find dvd drive'}
Set-VMFirmware -VMName $vmName -FirstBootDevice $vmDvdDrive
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, strconv.FormatInt(int64(controllerNumber), 10), strconv.FormatInt(int64(controllerLocation), 10))
return err
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, strconv.FormatInt(int64(controllerNumber), 10), strconv.FormatInt(int64(controllerLocation), 10))
return err
}
}
func DeleteDvdDrive(vmName string, controllerNumber uint, controllerLocation uint) error {