A workaround for bug in Windows 10 and Windows 2016 where you have to specify a path when creating a dvd drive
This commit is contained in:
parent
4ab2e8b252
commit
d878f4dd8e
|
@ -86,7 +86,7 @@ type Driver interface {
|
|||
|
||||
RestartVirtualMachine(string) error
|
||||
|
||||
CreateDvdDrive(string, uint) (uint, uint, error)
|
||||
CreateDvdDrive(string, string, uint) (uint, uint, error)
|
||||
|
||||
MountDvdDrive(string, string, uint, uint) error
|
||||
|
||||
|
|
|
@ -205,8 +205,8 @@ func (d *HypervPS4Driver) RestartVirtualMachine(vmName string) error {
|
|||
return hyperv.RestartVirtualMachine(vmName)
|
||||
}
|
||||
|
||||
func (d *HypervPS4Driver) CreateDvdDrive(vmName string, generation uint) (uint, uint, error) {
|
||||
return hyperv.CreateDvdDrive(vmName, generation)
|
||||
func (d *HypervPS4Driver) CreateDvdDrive(vmName string, isoPath string, generation uint) (uint, uint, error) {
|
||||
return hyperv.CreateDvdDrive(vmName, isoPath, generation)
|
||||
}
|
||||
|
||||
func (d *HypervPS4Driver) MountDvdDrive(vmName string, path string, controllerNumber uint, controllerLocation uint) error {
|
||||
|
|
|
@ -30,7 +30,7 @@ func (s *StepMountDvdDrive) Run(state multistep.StateBag) multistep.StepAction {
|
|||
// For IDE, there are only 2 controllers (0,1) with 2 locations each (0,1)
|
||||
|
||||
var dvdControllerProperties DvdControllerProperties
|
||||
controllerNumber, controllerLocation, err := driver.CreateDvdDrive(vmName, s.Generation)
|
||||
controllerNumber, controllerLocation, err := driver.CreateDvdDrive(vmName, isoPath, s.Generation)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
|
|
|
@ -1,96 +1,96 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc.
|
||||
// All Rights Reserved.
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
// See License.txt in the project root for license information.
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
)
|
||||
|
||||
type StepMountGuestAdditions struct {
|
||||
GuestAdditionsMode string
|
||||
GuestAdditionsPath string
|
||||
Generation uint
|
||||
}
|
||||
|
||||
func (s *StepMountGuestAdditions) Run(state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
if s.GuestAdditionsMode != "attach" {
|
||||
ui.Say("Skipping mounting Integration Services Setup Disk...")
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui.Say("Mounting Integration Services Setup Disk...")
|
||||
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
// should be able to mount up to 60 additional iso images using SCSI
|
||||
// but Windows would only allow a max of 22 due to available drive letters
|
||||
// Will Windows assign DVD drives to A: and B: ?
|
||||
|
||||
// For IDE, there are only 2 controllers (0,1) with 2 locations each (0,1)
|
||||
|
||||
var dvdControllerProperties DvdControllerProperties
|
||||
|
||||
controllerNumber, controllerLocation, err := driver.CreateDvdDrive(vmName, s.Generation)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
dvdControllerProperties.ControllerNumber = controllerNumber
|
||||
dvdControllerProperties.ControllerLocation = controllerLocation
|
||||
dvdControllerProperties.Existing = false
|
||||
state.Put("guest.dvd.properties", dvdControllerProperties)
|
||||
|
||||
ui.Say(fmt.Sprintf("Mounting Integration Services dvd drive %s ...", s.GuestAdditionsPath))
|
||||
err = driver.MountDvdDrive(vmName, s.GuestAdditionsPath, controllerNumber, controllerLocation)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
log.Println(fmt.Sprintf("ISO %s mounted on DVD controller %v, location %v", s.GuestAdditionsPath, controllerNumber, controllerLocation))
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepMountGuestAdditions) Cleanup(state multistep.StateBag) {
|
||||
if s.GuestAdditionsMode != "attach" {
|
||||
return
|
||||
}
|
||||
|
||||
dvdControllerState := state.Get("guest.dvd.properties")
|
||||
|
||||
if dvdControllerState == nil {
|
||||
return
|
||||
}
|
||||
|
||||
dvdController := dvdControllerState.(DvdControllerProperties)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
driver := state.Get("driver").(Driver)
|
||||
vmName := state.Get("vmName").(string)
|
||||
errorMsg := "Error unmounting Integration Services dvd drive: %s"
|
||||
|
||||
ui.Say("Cleanup Integration Services dvd drive...")
|
||||
|
||||
if dvdController.Existing {
|
||||
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
} else {
|
||||
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Open Technologies, Inc.
|
||||
// All Rights Reserved.
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
// See License.txt in the project root for license information.
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
)
|
||||
|
||||
type StepMountGuestAdditions struct {
|
||||
GuestAdditionsMode string
|
||||
GuestAdditionsPath string
|
||||
Generation uint
|
||||
}
|
||||
|
||||
func (s *StepMountGuestAdditions) Run(state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
if s.GuestAdditionsMode != "attach" {
|
||||
ui.Say("Skipping mounting Integration Services Setup Disk...")
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui.Say("Mounting Integration Services Setup Disk...")
|
||||
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
// should be able to mount up to 60 additional iso images using SCSI
|
||||
// but Windows would only allow a max of 22 due to available drive letters
|
||||
// Will Windows assign DVD drives to A: and B: ?
|
||||
|
||||
// For IDE, there are only 2 controllers (0,1) with 2 locations each (0,1)
|
||||
|
||||
var dvdControllerProperties DvdControllerProperties
|
||||
|
||||
controllerNumber, controllerLocation, err := driver.CreateDvdDrive(vmName, s.GuestAdditionsPath, s.Generation)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
dvdControllerProperties.ControllerNumber = controllerNumber
|
||||
dvdControllerProperties.ControllerLocation = controllerLocation
|
||||
dvdControllerProperties.Existing = false
|
||||
state.Put("guest.dvd.properties", dvdControllerProperties)
|
||||
|
||||
ui.Say(fmt.Sprintf("Mounting Integration Services dvd drive %s ...", s.GuestAdditionsPath))
|
||||
err = driver.MountDvdDrive(vmName, s.GuestAdditionsPath, controllerNumber, controllerLocation)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
log.Println(fmt.Sprintf("ISO %s mounted on DVD controller %v, location %v", s.GuestAdditionsPath, controllerNumber, controllerLocation))
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepMountGuestAdditions) Cleanup(state multistep.StateBag) {
|
||||
if s.GuestAdditionsMode != "attach" {
|
||||
return
|
||||
}
|
||||
|
||||
dvdControllerState := state.Get("guest.dvd.properties")
|
||||
|
||||
if dvdControllerState == nil {
|
||||
return
|
||||
}
|
||||
|
||||
dvdController := dvdControllerState.(DvdControllerProperties)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
driver := state.Get("driver").(Driver)
|
||||
vmName := state.Get("vmName").(string)
|
||||
errorMsg := "Error unmounting Integration Services dvd drive: %s"
|
||||
|
||||
ui.Say("Cleanup Integration Services dvd drive...")
|
||||
|
||||
if dvdController.Existing {
|
||||
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
} else {
|
||||
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,98 +1,98 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc.
|
||||
// All Rights Reserved.
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
// See License.txt in the project root for license information.
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
)
|
||||
|
||||
type StepMountSecondaryDvdImages struct {
|
||||
IsoPaths []string
|
||||
Generation uint
|
||||
}
|
||||
|
||||
type DvdControllerProperties struct {
|
||||
ControllerNumber uint
|
||||
ControllerLocation uint
|
||||
Existing bool
|
||||
}
|
||||
|
||||
func (s *StepMountSecondaryDvdImages) Run(state multistep.StateBag) multistep.StepAction {
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
ui.Say("Mounting secondary DVD images...")
|
||||
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
// should be able to mount up to 60 additional iso images using SCSI
|
||||
// but Windows would only allow a max of 22 due to available drive letters
|
||||
// Will Windows assign DVD drives to A: and B: ?
|
||||
|
||||
// For IDE, there are only 2 controllers (0,1) with 2 locations each (0,1)
|
||||
var dvdProperties []DvdControllerProperties
|
||||
|
||||
for _, isoPath := range s.IsoPaths {
|
||||
var properties DvdControllerProperties
|
||||
|
||||
controllerNumber, controllerLocation, err := driver.CreateDvdDrive(vmName, s.Generation)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
properties.ControllerNumber = controllerNumber
|
||||
properties.ControllerLocation = controllerLocation
|
||||
properties.Existing = false
|
||||
dvdProperties = append(dvdProperties, properties)
|
||||
state.Put("secondary.dvd.properties", dvdProperties)
|
||||
|
||||
ui.Say(fmt.Sprintf("Mounting secondary dvd drive %s ...", isoPath))
|
||||
err = driver.MountDvdDrive(vmName, isoPath, controllerNumber, controllerLocation)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
log.Println(fmt.Sprintf("ISO %s mounted on DVD controller %v, location %v", isoPath, controllerNumber, controllerLocation))
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepMountSecondaryDvdImages) Cleanup(state multistep.StateBag) {
|
||||
dvdControllersState := state.Get("secondary.dvd.properties")
|
||||
|
||||
if dvdControllersState == nil {
|
||||
return
|
||||
}
|
||||
|
||||
dvdControllers := dvdControllersState.([]DvdControllerProperties)
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vmName := state.Get("vmName").(string)
|
||||
errorMsg := "Error unmounting secondary dvd drive: %s"
|
||||
|
||||
ui.Say("Clean up secondary dvd drives...")
|
||||
|
||||
for _, dvdController := range dvdControllers {
|
||||
|
||||
if dvdController.Existing {
|
||||
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
} else {
|
||||
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Open Technologies, Inc.
|
||||
// All Rights Reserved.
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
// See License.txt in the project root for license information.
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
)
|
||||
|
||||
type StepMountSecondaryDvdImages struct {
|
||||
IsoPaths []string
|
||||
Generation uint
|
||||
}
|
||||
|
||||
type DvdControllerProperties struct {
|
||||
ControllerNumber uint
|
||||
ControllerLocation uint
|
||||
Existing bool
|
||||
}
|
||||
|
||||
func (s *StepMountSecondaryDvdImages) Run(state multistep.StateBag) multistep.StepAction {
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
ui.Say("Mounting secondary DVD images...")
|
||||
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
// should be able to mount up to 60 additional iso images using SCSI
|
||||
// but Windows would only allow a max of 22 due to available drive letters
|
||||
// Will Windows assign DVD drives to A: and B: ?
|
||||
|
||||
// For IDE, there are only 2 controllers (0,1) with 2 locations each (0,1)
|
||||
var dvdProperties []DvdControllerProperties
|
||||
|
||||
for _, isoPath := range s.IsoPaths {
|
||||
var properties DvdControllerProperties
|
||||
|
||||
controllerNumber, controllerLocation, err := driver.CreateDvdDrive(vmName, isoPath, s.Generation)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
properties.ControllerNumber = controllerNumber
|
||||
properties.ControllerLocation = controllerLocation
|
||||
properties.Existing = false
|
||||
dvdProperties = append(dvdProperties, properties)
|
||||
state.Put("secondary.dvd.properties", dvdProperties)
|
||||
|
||||
ui.Say(fmt.Sprintf("Mounting secondary dvd drive %s ...", isoPath))
|
||||
err = driver.MountDvdDrive(vmName, isoPath, controllerNumber, controllerLocation)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
log.Println(fmt.Sprintf("ISO %s mounted on DVD controller %v, location %v", isoPath, controllerNumber, controllerLocation))
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepMountSecondaryDvdImages) Cleanup(state multistep.StateBag) {
|
||||
dvdControllersState := state.Get("secondary.dvd.properties")
|
||||
|
||||
if dvdControllersState == nil {
|
||||
return
|
||||
}
|
||||
|
||||
dvdControllers := dvdControllersState.([]DvdControllerProperties)
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vmName := state.Get("vmName").(string)
|
||||
errorMsg := "Error unmounting secondary dvd drive: %s"
|
||||
|
||||
ui.Say("Clean up secondary dvd drives...")
|
||||
|
||||
for _, dvdController := range dvdControllers {
|
||||
|
||||
if dvdController.Existing {
|
||||
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
} else {
|
||||
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ $ip
|
|||
return cmdOut, err
|
||||
}
|
||||
|
||||
func CreateDvdDrive(vmName string, generation uint) (uint, uint, error) {
|
||||
func CreateDvdDrive(vmName string, isoPath string, generation uint) (uint, uint, error) {
|
||||
var ps powershell.PowerShellCmd
|
||||
var script string
|
||||
var controllerNumber uint
|
||||
|
@ -89,12 +89,13 @@ $lastControllerNumber
|
|||
}
|
||||
|
||||
script = `
|
||||
param([string]$vmName,[int]$controllerNumber)
|
||||
$dvdController = Add-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -Passthru
|
||||
param([string]$vmName, [string]$isoPath, [int]$controllerNumber)
|
||||
$dvdController = Add-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -path $isoPath -Passthru
|
||||
Set-VMDvdDrive -path $null
|
||||
$dvdController.ControllerLocation
|
||||
`
|
||||
|
||||
cmdOut, err := ps.Output(script, vmName, strconv.FormatInt(int64(controllerNumber), 10))
|
||||
cmdOut, err := ps.Output(script, vmName, isoPath, strconv.FormatInt(int64(controllerNumber), 10))
|
||||
if err != nil {
|
||||
return controllerNumber, 0, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue