packer-plugin-xenserver/builder/xenserver/step_find_vdi.go
Cheng Sun e308c0759f VDI upload, floppy and tools support
This commit add new VDI steps named step_{attach,detach,find,upload}_vdi
  - attach/detach are self-explanatory; can specify CD or Floppy
  - find finds a VDI by name-label and stores the uuid
  - upload uploads a VDI from a local disk image and stores the uuid

In order to demonstrate the new VDI code, this commit trivially adds:
  - support for uploading ISOs again (dependent on unmerged XAPI patch)
  - initial floppy upload/attach support (dependent on currently-broken
    XAPI patch)
  - initial XenServer Tools support
2014-12-19 12:46:36 +00:00

43 lines
1.0 KiB
Go

package xenserver
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
type stepFindVdi struct {
VdiName string
ImagePathFunc func() string
VdiUuidKey string
}
func (self *stepFindVdi) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
client := state.Get("client").(XenAPIClient)
vdis, err := client.GetVdiByNameLabel(self.VdiName)
switch {
case len(vdis) == 0:
ui.Error(fmt.Sprintf("Couldn't find a VDI named '%s'", self.VdiName))
return multistep.ActionHalt
case len(vdis) > 1:
ui.Error(fmt.Sprintf("Found more than one VDI with name '%s'. Name must be unique", self.VdiName))
return multistep.ActionHalt
}
vdi := vdis[0]
vdiUuid, err := vdi.GetUuid()
if err != nil {
ui.Error(fmt.Sprintf("Unable to get UUID of VDI '%s': %s", self.VdiName, err.Error()))
return multistep.ActionHalt
}
state.Put(self.VdiUuidKey, vdiUuid)
return multistep.ActionContinue
}
func (self *stepFindVdi) Cleanup(state multistep.StateBag) {}