From 0269a47f24e20ff8aab3313607fe79fe34442b42 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 22 May 2025 15:27:45 -0700 Subject: [PATCH] Add resource parameters for hyperv xml import The generic import cmdlet passes all received arguments to the specialized import cmdlets. The resource parameters for providing memory and cpu values were added to the vmcx based cmdlet but not the xml based cmdlet. This adds the to the xml based cmdlet and includes configuration adjustment if set. --- .../scripts/utils/VagrantVM/VagrantVM.psm1 | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1 b/plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1 index e3886efcc..c473a3ee8 100644 --- a/plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1 +++ b/plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1 @@ -224,6 +224,12 @@ function New-VagrantVMXML { [string] $SourcePath, [parameter (Mandatory=$false)] [bool] $LinkedClone = $false, + [parameter (Mandatory=$false)] + [int] $Memory = $null, + [parameter (Mandatory=$false)] + [int] $MaxMemory = $null, + [parameter (Mandatory=$false)] + [int] $CPUCount = $null, [parameter(Mandatory=$false)] [string] $VMName ) @@ -327,7 +333,11 @@ function New-VagrantVMXML { # Apply original VM configuration to new VM instance - $processors = $VMConfig.configuration.settings.processors.count."#text" + if($CPUCount -ne $null) { + $processors = $CPUCount + } else { + $processors = $VMConfig.configuration.settings.processors.count."#text" + } $notes = (Select-Xml -XML $VMConfig -XPath "//notes").node."#text" $memory = (Select-Xml -XML $VMConfig -XPath "//memory").node.Bank if ($memory.dynamic_memory_enabled."#text" -eq "True") { @@ -336,10 +346,22 @@ function New-VagrantVMXML { else { $dynamicmemory = $False } - # Memory values need to be in bytes - $MemoryMaximumBytes = ($memory.limit."#text" -as [int]) * 1MB - $MemoryStartupBytes = ($memory.size."#text" -as [int]) * 1MB - $MemoryMinimumBytes = ($memory.reservation."#text" -as [int]) * 1MB + + + if($Memory -ne $null) { + $MemoryMaximumBytes = $Memory * 1MB + $MemoryStartupBytes = $Memory * 1MB + $MemoryMinimumBytes = $Memory * 1MB + } else { + $MemoryMaximumBytes = ($memory.limit."#text" -as [int]) * 1MB + $MemoryStartupBytes = ($memory.size."#text" -as [int]) * 1MB + $MemoryMinimumBytes = ($memory.reservation."#text" -as [int]) * 1MB + } + + if($MaxMemory -ne $null) { + $dynamicmemory = $true + $MemoryMaximumBytes = $MaxMemory * 1MB + } $Config = @{ ProcessorCount = $processors;