From 452fcbd9a1be9f4c582e4757ea7b833839fc6d98 Mon Sep 17 00:00:00 2001 From: Taliesin Sisson Date: Sun, 12 Mar 2017 23:51:59 +0000 Subject: [PATCH] Only attach dvd drive if there is one Fix debug messages for cloning Add hyperv-vmcx as a builder from command line --- builder/hyperv/common/step_clone_vm.go | 2 +- builder/hyperv/common/step_mount_dvddrive.go | 12 +++++++-- builder/hyperv/vmcx/builder.go | 28 +++++++++++++------- command/plugin.go | 4 +++ common/powershell/hyperv/hyperv.go | 2 +- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/builder/hyperv/common/step_clone_vm.go b/builder/hyperv/common/step_clone_vm.go index 0159d2b9e..025a1bb06 100644 --- a/builder/hyperv/common/step_clone_vm.go +++ b/builder/hyperv/common/step_clone_vm.go @@ -28,7 +28,7 @@ type StepCloneVM struct { func (s *StepCloneVM) Run(state multistep.StateBag) multistep.StepAction { driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) - ui.Say("Creating virtual machine...") + ui.Say("Cloning virtual machine...") path := state.Get("packerTempDir").(string) diff --git a/builder/hyperv/common/step_mount_dvddrive.go b/builder/hyperv/common/step_mount_dvddrive.go index 632120053..d91be3a88 100644 --- a/builder/hyperv/common/step_mount_dvddrive.go +++ b/builder/hyperv/common/step_mount_dvddrive.go @@ -2,9 +2,9 @@ package common import ( "fmt" + "log" "github.com/hashicorp/packer/packer" "github.com/mitchellh/multistep" - "log" ) type StepMountDvdDrive struct { @@ -17,7 +17,15 @@ func (s *StepMountDvdDrive) Run(state multistep.StateBag) multistep.StepAction { errorMsg := "Error mounting dvd drive: %s" vmName := state.Get("vmName").(string) - isoPath := state.Get("iso_path").(string) + + // Determine if we even have a dvd disk to attach + var isoPath string + if isoPathRaw, ok := state.GetOk("iso_path"); ok { + isoPath = isoPathRaw.(string) + } else { + log.Println("No dvd disk, not attaching.") + return multistep.ActionContinue + } // 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 diff --git a/builder/hyperv/vmcx/builder.go b/builder/hyperv/vmcx/builder.go index 791c9ae46..0282d1f18 100644 --- a/builder/hyperv/vmcx/builder.go +++ b/builder/hyperv/vmcx/builder.go @@ -348,15 +348,23 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Force: b.config.PackerForce, Path: b.config.OutputDir, }, - &common.StepDownload{ - Checksum: b.config.ISOChecksum, - ChecksumType: b.config.ISOChecksumType, - Description: "ISO", - ResultKey: "iso_path", - Url: b.config.ISOUrls, - Extension: b.config.TargetExtension, - TargetPath: b.config.TargetPath, - }, + } + + if b.config.RawSingleISOUrl != "" || len(b.config.ISOUrls) > 0 { + steps = append(steps, + &common.StepDownload{ + Checksum: b.config.ISOChecksum, + ChecksumType: b.config.ISOChecksumType, + Description: "ISO", + ResultKey: "iso_path", + Url: b.config.ISOUrls, + Extension: b.config.TargetExtension, + TargetPath: b.config.TargetPath, + }, + ) + } + + steps = append(steps, &common.StepCreateFloppy{ Files: b.config.FloppyFiles, }, @@ -449,7 +457,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe }, // the clean up actions for each step will be executed reverse order - } + ) // Run the steps. if b.config.PackerDebug { diff --git a/command/plugin.go b/command/plugin.go index 11baf4729..373c7320f 100644 --- a/command/plugin.go +++ b/command/plugin.go @@ -92,8 +92,12 @@ var Builders = map[string]packer.Builder{ "file": new(filebuilder.Builder), "googlecompute": new(googlecomputebuilder.Builder), "hyperv-iso": new(hypervisobuilder.Builder), +<<<<<<< HEAD "lxc": new(lxcbuilder.Builder), "lxd": new(lxdbuilder.Builder), +======= + "hyperv-vmcx": new(hypervvmcxbuilder.Builder), +>>>>>>> Only attach dvd drive if there is one "null": new(nullbuilder.Builder), "oneandone": new(oneandonebuilder.Builder), "openstack": new(openstackbuilder.Builder), diff --git a/common/powershell/hyperv/hyperv.go b/common/powershell/hyperv/hyperv.go index 461d4120a..9937ed3b7 100644 --- a/common/powershell/hyperv/hyperv.go +++ b/common/powershell/hyperv/hyperv.go @@ -248,7 +248,7 @@ if ((Get-Command Set-Vm).Parameters["AutomaticCheckpointsEnabled"]) { func CloneVirtualMachine(cloneFromVmName string, cloneFromSnapshotName string, cloneAllSnapshots bool, vmName string, path string, ram int64, switchName string) error { var script = ` -param([string]$CloneFromVMName, [string]$CloneFromSnapshotName, [string]CloneAllSnapshotsString, [string]$vmName, [string]$path, [long]$memoryStartupBytes, [string]$switchName) +param([string]$CloneFromVMName, [string]$CloneFromSnapshotName, [string]$CloneAllSnapshotsString, [string]$vmName, [string]$path, [long]$memoryStartupBytes, [string]$switchName) $CloneAllSnapshots = [System.Boolean]::Parse($CloneAllSnapshotsString)