Merge pull request #7108 from hashicorp/revert_hddorder_setting

Revert hddorder setting
This commit is contained in:
Megan Marsh 2018-12-13 16:27:31 -08:00 committed by GitHub
commit 2045390e74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 21 deletions

View File

@ -74,7 +74,7 @@ type Driver interface {
AddVirtualMachineHardDrive(string, string, string, int64, int64, string) error
CloneVirtualMachine(string, string, string, bool, string, string, string, int64, string) error
CloneVirtualMachine(string, string, string, bool, string, string, string, int64, string, bool) error
DeleteVirtualMachine(string) error

View File

@ -143,6 +143,7 @@ type DriverMock struct {
CloneVirtualMachine_HarddrivePath string
CloneVirtualMachine_Ram int64
CloneVirtualMachine_SwitchName string
CloneVirtualMachine_Copy bool
CloneVirtualMachine_Err error
DeleteVirtualMachine_Called bool
@ -425,7 +426,7 @@ func (d *DriverMock) CreateVirtualMachine(vmName string, path string, harddriveP
func (d *DriverMock) CloneVirtualMachine(cloneFromVmcxPath string, cloneFromVmName string,
cloneFromSnapshotName string, cloneAllSnapshots bool, vmName string, path string,
harddrivePath string, ram int64, switchName string) error {
harddrivePath string, ram int64, switchName string, copyTF bool) error {
d.CloneVirtualMachine_Called = true
d.CloneVirtualMachine_CloneFromVmcxPath = cloneFromVmcxPath
d.CloneVirtualMachine_CloneFromVmName = cloneFromVmName
@ -436,6 +437,8 @@ func (d *DriverMock) CloneVirtualMachine(cloneFromVmcxPath string, cloneFromVmNa
d.CloneVirtualMachine_HarddrivePath = harddrivePath
d.CloneVirtualMachine_Ram = ram
d.CloneVirtualMachine_SwitchName = switchName
d.CloneVirtualMachine_Copy = copyTF
return d.CloneVirtualMachine_Err
}

View File

@ -190,9 +190,9 @@ func (d *HypervPS4Driver) CreateVirtualMachine(vmName string, path string, hardd
func (d *HypervPS4Driver) CloneVirtualMachine(cloneFromVmcxPath string, cloneFromVmName string,
cloneFromSnapshotName string, cloneAllSnapshots bool, vmName string, path string, harddrivePath string,
ram int64, switchName string) error {
ram int64, switchName string, copyTF bool) error {
return hyperv.CloneVirtualMachine(cloneFromVmcxPath, cloneFromVmName, cloneFromSnapshotName,
cloneAllSnapshots, vmName, path, harddrivePath, ram, switchName)
cloneAllSnapshots, vmName, path, harddrivePath, ram, switchName, copyTF)
}
func (d *HypervPS4Driver) DeleteVirtualMachine(vmName string) error {

View File

@ -22,6 +22,7 @@ type StepCloneVM struct {
CloneAllSnapshots bool
VMName string
SwitchName string
CompareCopy bool
RamSize uint
Cpu uint
EnableMacSpoofing bool
@ -55,8 +56,9 @@ func (s *StepCloneVM) Run(_ context.Context, state multistep.StateBag) multistep
// convert the MB to bytes
ramSize := int64(s.RamSize * 1024 * 1024)
err := driver.CloneVirtualMachine(s.CloneFromVMCXPath, s.CloneFromVMName, s.CloneFromSnapshotName,
s.CloneAllSnapshots, s.VMName, path, harddrivePath, ramSize, s.SwitchName)
err := driver.CloneVirtualMachine(s.CloneFromVMCXPath, s.CloneFromVMName,
s.CloneFromSnapshotName, s.CloneAllSnapshots, s.VMName, path,
harddrivePath, ramSize, s.SwitchName, s.CompareCopy)
if err != nil {
err := fmt.Errorf("Error cloning virtual machine: %s", err)
state.Put("error", err)

View File

@ -81,6 +81,7 @@ type Config struct {
DifferencingDisk bool `mapstructure:"differencing_disk"`
SwitchName string `mapstructure:"switch_name"`
CompareCopy bool `mapstructure:"copy_in_compare"`
SwitchVlanId string `mapstructure:"switch_vlan_id"`
MacAddress string `mapstructure:"mac_address"`
VlanId string `mapstructure:"vlan_id"`
@ -430,6 +431,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
CloneAllSnapshots: b.config.CloneAllSnapshots,
VMName: b.config.VMName,
SwitchName: b.config.SwitchName,
CompareCopy: b.config.CompareCopy,
RamSize: b.config.RamSize,
Cpu: b.config.Cpu,
EnableMacSpoofing: b.config.EnableMacSpoofing,

View File

@ -24,8 +24,6 @@ type vmxTemplateData struct {
CpuCount string
MemorySize string
HDD_BootOrder string
SCSI_Present string
SCSI_diskAdapterType string
SATA_Present string
@ -166,7 +164,6 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
NVME_Present: "FALSE",
DiskType: "scsi",
HDD_BootOrder: "scsi0:0",
CDROMType: "ide",
CDROMType_PrimarySecondary: "0",
@ -189,20 +186,17 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
templateData.DiskType = "ide"
templateData.CDROMType = "ide"
templateData.CDROMType_PrimarySecondary = "1"
templateData.HDD_BootOrder = "ide0:0"
case "sata":
templateData.SATA_Present = "TRUE"
templateData.DiskType = "sata"
templateData.CDROMType = "sata"
templateData.CDROMType_PrimarySecondary = "1"
templateData.HDD_BootOrder = "sata0:0"
case "nvme":
templateData.NVME_Present = "TRUE"
templateData.DiskType = "nvme"
templateData.SATA_Present = "TRUE"
templateData.CDROMType = "sata"
templateData.CDROMType_PrimarySecondary = "0"
templateData.HDD_BootOrder = "nvme0:0"
case "scsi":
diskAdapterType = "lsilogic"
fallthrough
@ -212,7 +206,6 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
templateData.DiskType = "scsi"
templateData.CDROMType = "ide"
templateData.CDROMType_PrimarySecondary = "0"
templateData.HDD_BootOrder = "scsi0:0"
}
/// Handle the cdrom adapter type. If the disk adapter type and the
@ -476,7 +469,6 @@ nvram = "{{ .Name }}.nvram"
floppy0.present = "FALSE"
bios.bootOrder = "hdd,cdrom"
bios.hddOrder = "{{ .HDD_BootOrder }}"
// Configuration
extendedConfigFile = "{{ .Name }}.vmxf"

View File

@ -366,10 +366,10 @@ Hyper-V\Set-VMNetworkAdapter $vmName -staticmacaddress $mac
}
func ImportVmcxVirtualMachine(importPath string, vmName string, harddrivePath string,
ram int64, switchName string) error {
ram int64, switchName string, copyTF bool) error {
var script = `
param([string]$importPath, [string]$vmName, [string]$harddrivePath, [long]$memoryStartupBytes, [string]$switchName)
param([string]$importPath, [string]$vmName, [string]$harddrivePath, [long]$memoryStartupBytes, [string]$switchName, [string]$copy)
$VirtualHarddisksPath = Join-Path -Path $importPath -ChildPath 'Virtual Hard Disks'
if (!(Test-Path $VirtualHarddisksPath)) {
@ -395,7 +395,13 @@ if (!$VirtualMachinePath){
$VirtualMachinePath = Get-ChildItem -Path $importPath -Filter *.xml -Recurse -ErrorAction SilentlyContinue | select -First 1 | %{$_.FullName}
}
$compatibilityReport = Hyper-V\Compare-VM -Path $VirtualMachinePath -VirtualMachinePath $importPath -SmartPagingFilePath $importPath -SnapshotFilePath $importPath -VhdDestinationPath $VirtualHarddisksPath -GenerateNewId
$copyBool = $false
switch($copy) {
"true" { $copyBool = $true }
default { $copyBool = $false }
}
$compatibilityReport = Hyper-V\Compare-VM -Path $VirtualMachinePath -VirtualMachinePath $importPath -SmartPagingFilePath $importPath -SnapshotFilePath $importPath -VhdDestinationPath $VirtualHarddisksPath -GenerateNewId -Copy:$false
if ($vhdPath){
Copy-Item -Path $harddrivePath -Destination $vhdPath
$existingFirstHarddrive = $compatibilityReport.VM.HardDrives | Select -First 1
@ -415,16 +421,15 @@ if ($vm) {
$result = Hyper-V\Rename-VM -VM $vm -NewName $VMName
}
`
var ps powershell.PowerShellCmd
err := ps.Run(script, importPath, vmName, harddrivePath, strconv.FormatInt(ram, 10), switchName)
err := ps.Run(script, importPath, vmName, harddrivePath, strconv.FormatInt(ram, 10), switchName, strconv.FormatBool(copyTF))
return err
}
func CloneVirtualMachine(cloneFromVmcxPath string, cloneFromVmName string,
cloneFromSnapshotName string, cloneAllSnapshots bool, vmName string,
path string, harddrivePath string, ram int64, switchName string) error {
path string, harddrivePath string, ram int64, switchName string, copyTF bool) error {
if cloneFromVmName != "" {
if err := ExportVmcxVirtualMachine(path, cloneFromVmName,
@ -439,7 +444,7 @@ func CloneVirtualMachine(cloneFromVmcxPath string, cloneFromVmName string,
}
}
if err := ImportVmcxVirtualMachine(path, vmName, harddrivePath, ram, switchName); err != nil {
if err := ImportVmcxVirtualMachine(path, vmName, harddrivePath, ram, switchName, copyTF); err != nil {
return err
}

View File

@ -116,6 +116,15 @@ builder.
This setting only has an effect if using `clone_from_vm_name` and is
ignored otherwise.
- `copy_in_compare` - (bool) When cloning a vm to build from, we run a powershell
Compare-VM command, which, depending on your version of Windows, may need
the "Copy" flag to be set to true or false. Defaults to "false". Command:
`$compatibilityReport = Hyper-V\Compare-VM -Path $VirtualMachinePath -VirtualMachinePath $importPath -SmartPagingFilePath $importPath -SnapshotFilePath $importPath -VhdDestinationPath $VirtualHarddisksPath -GenerateNewId -Copy:$copy`
Where $copy is replaced with either true or false depending on the value of
"copy_in_compare".
- `cpu` (number) - The number of CPUs the virtual machine should use. If
this isn't specified, the default is 1 CPU.