Merge pull request #22 from jonludlam/vhdexport

Add the ability to export VHD files
This commit is contained in:
Rob Dobson 2015-02-20 17:03:07 +00:00
commit 4b8ec79cad
2 changed files with 11 additions and 5 deletions

View File

@ -213,9 +213,9 @@ func (c *CommonConfig) Prepare(t *packer.ConfigTemplate, pc *common.PackerConfig
} }
switch c.Format { switch c.Format {
case "xva", "vdi_raw", "none": case "xva", "vdi_raw", "vdi_vhd", "none":
default: default:
errs = append(errs, errors.New("format must be one of 'xva', 'vdi_raw', 'none'")) errs = append(errs, errors.New("format must be one of 'xva', 'vdi_raw', 'vdi_vhd', 'none'"))
} }
switch c.KeepVM { switch c.KeepVM {

View File

@ -46,6 +46,8 @@ func (StepExport) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
client := state.Get("client").(XenAPIClient) client := state.Get("client").(XenAPIClient)
instance_uuid := state.Get("instance_uuid").(string) instance_uuid := state.Get("instance_uuid").(string)
suffix := ".vhd"
extrauri := "&format=vhd"
instance, err := client.GetVMByUuid(instance_uuid) instance, err := client.GetVMByUuid(instance_uuid)
if err != nil { if err != nil {
@ -79,6 +81,10 @@ func (StepExport) Run(state multistep.StateBag) multistep.StepAction {
} }
case "vdi_raw": case "vdi_raw":
suffix = ".raw"
extrauri = ""
fallthrough
case "vdi_vhd":
// export the disks // export the disks
disks, err := instance.GetDisks() disks, err := instance.GetDisks()
@ -96,14 +102,14 @@ func (StepExport) Run(state multistep.StateBag) multistep.StepAction {
// Basic auth in URL request is required as session token is not // Basic auth in URL request is required as session token is not
// accepted for some reason. // accepted for some reason.
// @todo: raise with XAPI team. // @todo: raise with XAPI team.
disk_export_url := fmt.Sprintf("https://%s:%s@%s/export_raw_vdi?vdi=%s", disk_export_url := fmt.Sprintf("https://%s:%s@%s/export_raw_vdi?vdi=%s%s",
client.Username, client.Username,
client.Password, client.Password,
client.Host, client.Host,
disk_uuid, disk_uuid,
) extrauri)
disk_export_filename := fmt.Sprintf("%s/%s.raw", config.OutputDir, disk_uuid) disk_export_filename := fmt.Sprintf("%s/%s%s", config.OutputDir, disk_uuid, suffix)
ui.Say("Getting VDI " + disk_export_url) ui.Say("Getting VDI " + disk_export_url)
err = downloadFile(disk_export_url, disk_export_filename) err = downloadFile(disk_export_url, disk_export_filename)