2015-06-21 07:36:07 -04:00
|
|
|
// 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"
|
|
|
|
powershell "github.com/mitchellh/packer/powershell"
|
2015-06-24 14:52:42 -04:00
|
|
|
"log"
|
2015-06-21 07:36:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepUnmountSecondaryDvdImages struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepUnmountSecondaryDvdImages) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
ui.Say("Unmounting Integration Services Setup Disk...")
|
|
|
|
|
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
|
|
|
|
// todo: should this message say removing the dvd?
|
|
|
|
|
|
|
|
dvdProperties := state.Get("secondary.dvd.properties").([]DvdControllerProperties)
|
|
|
|
|
2015-10-18 09:01:18 -04:00
|
|
|
log.Println(fmt.Sprintf("Found DVD properties %d", len(dvdProperties)))
|
2015-06-21 07:36:07 -04:00
|
|
|
|
|
|
|
for _, dvdProperty := range dvdProperties {
|
|
|
|
controllerNumber := dvdProperty.ControllerNumber
|
|
|
|
controllerLocation := dvdProperty.ControllerLocation
|
|
|
|
|
|
|
|
var script powershell.ScriptBuilder
|
|
|
|
powershell := new(powershell.PowerShellCmd)
|
|
|
|
|
|
|
|
script.WriteLine("param([string]$vmName,[int]$controllerNumber,[int]$controllerLocation)")
|
2015-06-24 14:52:42 -04:00
|
|
|
script.WriteLine("$vmDvdDrive = Get-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -ControllerLocation $controllerLocation")
|
|
|
|
script.WriteLine("if (!$vmDvdDrive) {throw 'unable to find dvd drive'}")
|
2015-06-21 07:36:07 -04:00
|
|
|
script.WriteLine("Remove-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -ControllerLocation $controllerLocation")
|
|
|
|
err := powershell.Run(script.String(), vmName, controllerNumber, controllerLocation)
|
|
|
|
if err != nil {
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepUnmountSecondaryDvdImages) Cleanup(state multistep.StateBag) {
|
|
|
|
}
|