Only attach dvd drive if there is one

Fix debug messages for cloning

Add hyperv-vmcx as a builder from command line
This commit is contained in:
Taliesin Sisson 2017-03-12 23:51:59 +00:00 committed by Vijaya Bhaskar Reddy Kondreddi
parent 429e1bc3ad
commit 452fcbd9a1
5 changed files with 34 additions and 14 deletions

View File

@ -28,7 +28,7 @@ type StepCloneVM struct {
func (s *StepCloneVM) Run(state multistep.StateBag) multistep.StepAction { func (s *StepCloneVM) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver) driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
ui.Say("Creating virtual machine...") ui.Say("Cloning virtual machine...")
path := state.Get("packerTempDir").(string) path := state.Get("packerTempDir").(string)

View File

@ -2,9 +2,9 @@ package common
import ( import (
"fmt" "fmt"
"log"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"log"
) )
type StepMountDvdDrive struct { type StepMountDvdDrive struct {
@ -17,7 +17,15 @@ func (s *StepMountDvdDrive) Run(state multistep.StateBag) multistep.StepAction {
errorMsg := "Error mounting dvd drive: %s" errorMsg := "Error mounting dvd drive: %s"
vmName := state.Get("vmName").(string) 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 // 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 // but Windows would only allow a max of 22 due to available drive letters

View File

@ -348,15 +348,23 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Force: b.config.PackerForce, Force: b.config.PackerForce,
Path: b.config.OutputDir, Path: b.config.OutputDir,
}, },
&common.StepDownload{ }
Checksum: b.config.ISOChecksum,
ChecksumType: b.config.ISOChecksumType, if b.config.RawSingleISOUrl != "" || len(b.config.ISOUrls) > 0 {
Description: "ISO", steps = append(steps,
ResultKey: "iso_path", &common.StepDownload{
Url: b.config.ISOUrls, Checksum: b.config.ISOChecksum,
Extension: b.config.TargetExtension, ChecksumType: b.config.ISOChecksumType,
TargetPath: b.config.TargetPath, Description: "ISO",
}, ResultKey: "iso_path",
Url: b.config.ISOUrls,
Extension: b.config.TargetExtension,
TargetPath: b.config.TargetPath,
},
)
}
steps = append(steps,
&common.StepCreateFloppy{ &common.StepCreateFloppy{
Files: b.config.FloppyFiles, 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 // the clean up actions for each step will be executed reverse order
} )
// Run the steps. // Run the steps.
if b.config.PackerDebug { if b.config.PackerDebug {

View File

@ -92,8 +92,12 @@ var Builders = map[string]packer.Builder{
"file": new(filebuilder.Builder), "file": new(filebuilder.Builder),
"googlecompute": new(googlecomputebuilder.Builder), "googlecompute": new(googlecomputebuilder.Builder),
"hyperv-iso": new(hypervisobuilder.Builder), "hyperv-iso": new(hypervisobuilder.Builder),
<<<<<<< HEAD
"lxc": new(lxcbuilder.Builder), "lxc": new(lxcbuilder.Builder),
"lxd": new(lxdbuilder.Builder), "lxd": new(lxdbuilder.Builder),
=======
"hyperv-vmcx": new(hypervvmcxbuilder.Builder),
>>>>>>> Only attach dvd drive if there is one
"null": new(nullbuilder.Builder), "null": new(nullbuilder.Builder),
"oneandone": new(oneandonebuilder.Builder), "oneandone": new(oneandonebuilder.Builder),
"openstack": new(openstackbuilder.Builder), "openstack": new(openstackbuilder.Builder),

View File

@ -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 { func CloneVirtualMachine(cloneFromVmName string, cloneFromSnapshotName string, cloneAllSnapshots bool, vmName string, path string, ram int64, switchName string) error {
var script = ` 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) $CloneAllSnapshots = [System.Boolean]::Parse($CloneAllSnapshotsString)