Forgot to check in these files.
This commit is contained in:
parent
010d171bec
commit
50a8d1b6b4
|
@ -0,0 +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
|
||||
cleanup bool
|
||||
dvdProperties DvdControllerProperties
|
||||
}
|
||||
|
||||
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
|
||||
s.cleanup = true
|
||||
s.dvdProperties = dvdControllerProperties
|
||||
|
||||
ui.Say(fmt.Sprintf("Mounting Integration Services dvd drive %s ...", s.GuestAdditionsPath))
|
||||
err = driver.MountDvdDriveByLocation(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))
|
||||
|
||||
state.Put("guest.dvd.properties", dvdControllerProperties)
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepMountGuestAdditions) Cleanup(state multistep.StateBag) {
|
||||
if !s.cleanup || s.GuestAdditionsMode != "attach" {
|
||||
return
|
||||
}
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui.Say("Cleanup Integration Services dvd drive...")
|
||||
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
dvdControllerProperties := s.dvdProperties
|
||||
|
||||
errorMsg := "Error unmounting Integration Services dvd drive: %s"
|
||||
|
||||
if dvdControllerProperties.Existing {
|
||||
err := driver.UnmountDvdDrive(vmName)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
} else {
|
||||
err := driver.DeleteDvdDrive(vmName, dvdControllerProperties.ControllerNumber, dvdControllerProperties.ControllerLocation)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
// 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
|
||||
cleanup bool
|
||||
dvdProperties []DvdControllerProperties
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
s.cleanup = true
|
||||
dvdProperties = append(dvdProperties, properties)
|
||||
s.dvdProperties = dvdProperties
|
||||
|
||||
ui.Say(fmt.Sprintf("Mounting secondary dvd drive %s ...", isoPath))
|
||||
err = driver.MountDvdDriveByLocation(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))
|
||||
}
|
||||
|
||||
state.Put("secondary.dvd.properties", dvdProperties)
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepMountSecondaryDvdImages) Cleanup(state multistep.StateBag) {
|
||||
if (!s.cleanup){
|
||||
return
|
||||
}
|
||||
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
ui.Say("Clean up secondary dvd drives...")
|
||||
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
errorMsg := "Error unmounting secondary dvd drive: %s"
|
||||
|
||||
for _, dvdControllerProperties := range s.dvdProperties {
|
||||
|
||||
if dvdControllerProperties.Existing {
|
||||
err := driver.UnmountDvdDrive(vmName)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
} else {
|
||||
err := driver.DeleteDvdDrive(vmName, dvdControllerProperties.ControllerNumber, dvdControllerProperties.ControllerLocation)
|
||||
if err != nil {
|
||||
log.Print(fmt.Sprintf(errorMsg, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
// 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"
|
||||
)
|
||||
|
||||
type StepUnmountGuestAdditions struct {
|
||||
}
|
||||
|
||||
func (s *StepUnmountGuestAdditions) Run(state multistep.StateBag) multistep.StepAction {
|
||||
driver := state.Get("driver").(Driver)
|
||||
vmName := state.Get("vmName").(string)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
ui.Say("Unmounting Integration Services dvd drive...")
|
||||
|
||||
dvdController := state.Get("guest.dvd.properties").(DvdControllerProperties)
|
||||
|
||||
if dvdController.Existing {
|
||||
err := driver.UnmountDvdDrive(vmName)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error unmounting Integration Services dvd drive: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
} else {
|
||||
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error deleting Integration Services dvd drive: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepUnmountGuestAdditions) Cleanup(state multistep.StateBag) {
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
// 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"
|
||||
)
|
||||
|
||||
type StepUnmountSecondaryDvdImages struct {
|
||||
}
|
||||
|
||||
func (s *StepUnmountSecondaryDvdImages) Run(state multistep.StateBag) multistep.StepAction {
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
ui.Say("Unmounting secondary dvd drives...")
|
||||
|
||||
dvdControllers := state.Get("secondary.dvd.properties").([]DvdControllerProperties)
|
||||
|
||||
for _, dvdController := range dvdControllers {
|
||||
if dvdController.Existing {
|
||||
err := driver.UnmountDvdDrive(vmName)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error unmounting secondary dvd drive: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
} else {
|
||||
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error deleting secondary dvd drive: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepUnmountSecondaryDvdImages) Cleanup(state multistep.StateBag) {
|
||||
}
|
Loading…
Reference in New Issue