packer-plugin-xenserver/builder/xenserver/common/step_remove_devices.go
Cheng Sun 152bdee7f2 Initial work on splitting ISO and XVA builders
Compiles -- but xva create_instance is incomplete

Several changes were rolled into this commit, including:

- "export_format" is now "format", and "keep_instance" is "keep_vm"
- gox is used for building (with the intention of allowing
  cross-compilation in the future)
2014-12-31 16:09:23 +00:00

41 lines
972 B
Go

package common
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
type StepRemoveDevices struct{}
func (self *StepRemoveDevices) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
client := state.Get("client").(XenAPIClient)
ui.Say("Step: Remove devices from VM")
instance_id := state.Get("instance_uuid").(string)
instance, err := client.GetVMByUuid(instance_id)
if err != nil {
ui.Error(fmt.Sprintf("Could not get VM from UUID %s", instance_id))
ui.Error(err.Error())
return multistep.ActionHalt
}
// Destroy all connected VIFs
vifs, err := instance.GetVIFs()
if err != nil {
ui.Error(fmt.Sprintf("Could not get VIFs"))
ui.Error(err.Error())
return multistep.ActionHalt
}
for _, vif := range vifs {
ui.Message("Destroying VIF " + vif.Ref)
vif.Destroy()
}
return multistep.ActionContinue
}
func (self *StepRemoveDevices) Cleanup(state multistep.StateBag) {}