From 1d8db2734039dc35e0436cbf74238ea6fd297ea7 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 21 Apr 2020 14:07:11 -0700 Subject: [PATCH] Fixup handling parameters for hyper-v powershell disk scripts --- plugins/providers/hyperv/driver.rb | 6 ++++-- .../hyperv/scripts/attach_disk_drive.ps1 | 19 +++++++++++++------ plugins/providers/hyperv/scripts/new_vhd.ps1 | 5 ++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/plugins/providers/hyperv/driver.rb b/plugins/providers/hyperv/driver.rb index 79a35b1bd..ecd1a9d5d 100644 --- a/plugins/providers/hyperv/driver.rb +++ b/plugins/providers/hyperv/driver.rb @@ -37,7 +37,7 @@ module VagrantPlugins # @param [String] controller_location # @param [Hash] opts def attach_disk(disk_file_path, **opts) - execute(:attach_disk_drive, VmId: @vm_id, DiskFilePath: disk_file_path, ControllerType: opts[:ControllerType], + execute(:attach_disk_drive, VmId: @vm_id, Path: disk_file_path, ControllerType: opts[:ControllerType], ControllerNumber: opts[:ControllerNumber], ControllerLocation: opts[:ControllerLocation]) end @@ -48,7 +48,9 @@ module VagrantPlugins # ensure size_bytes is a uint64 execute(:new_vhd, Path: path, SizeBytes: size_bytes, Fixed: opts[:Fixed], BlockSizeBytes: opts[:BlockSizeBytes], LogicalSectorSizeBytes: opts[:LogicalSectorSizeBytes], - PhysicalSectorSizeBytes: opts[:PhsyicalSectorSizeBytes]) + PhysicalSectorSizeBytes: opts[:PhysicalSectorSizeBytes], + SourceDisk: opts[:SourceDisk], Differencing: opts[:Differencing], + ParentPath: opts[:ParentPath]) end # @param [String] controller_type diff --git a/plugins/providers/hyperv/scripts/attach_disk_drive.ps1 b/plugins/providers/hyperv/scripts/attach_disk_drive.ps1 index 10213c359..64ee1ab27 100644 --- a/plugins/providers/hyperv/scripts/attach_disk_drive.ps1 +++ b/plugins/providers/hyperv/scripts/attach_disk_drive.ps1 @@ -3,18 +3,25 @@ param( [Parameter(Mandatory=$true)] [string]$VmId, + [Parameter(Mandatory=$true)] + [string]$Path, [string]$ControllerType, [string]$ControllerNumber, - [string]$ControllerLocation, - [Parameter(Mandatory=$true)] - [string]$DiskFilePath + [string]$ControllerLocation ) +$Params = @{} + +foreach ($key in $MyInvocation.BoundParameters.keys) { + $value = (Get-Variable -Exclude "ErrorAction" $key).Value + if (($key -ne "VmId") -and ($key -ne "ErrorAction")) { + $Params.Add($key, $value) + } +} + try { $VM = Hyper-V\Get-VM -Id $VmId - #Hyper-V\Add-VMHardDiskDrive -VMName $vm -ControllerType $ControllerType -ControllerNumber $ControllerNumber -ControllerLocation $ControllerLocation -Path $DiskFilePath - # Add logic to support missing params. Below is the simple case for attaching a disk - Hyper-V\Add-VMHardDiskDrive -VMName $VM.Name -Path $DiskFilePath + Hyper-V\Add-VMHardDiskDrive -VMName $VM.Name @Params } catch { Write-ErrorMessage "Failed to attach disk ${DiskFilePath} to VM ${VM}: ${PSItem}" exit 1 diff --git a/plugins/providers/hyperv/scripts/new_vhd.ps1 b/plugins/providers/hyperv/scripts/new_vhd.ps1 index ded00f2f5..c1be12c5f 100644 --- a/plugins/providers/hyperv/scripts/new_vhd.ps1 +++ b/plugins/providers/hyperv/scripts/new_vhd.ps1 @@ -6,9 +6,12 @@ param( [Parameter(Mandatory=$true)] [UInt64]$SizeBytes, [switch]$Fixed, + [switch]$Differencing, + [string]$ParentPath, [string]$BlockSizeBytes, [string]$LogicalSectorSizeBytes, - [string]$PhysicalSectorSizeBytes + [string]$PhysicalSectorSizeBytes, + [UInt64]$SourceDisk ) $Params = @{}