Skip to content

Commit 1f09e4d

Browse files
authored
Merge pull request #13674 from hashicorp/hyperv-xml-import
Add resource parameters for hyperv xml import
2 parents c78c65b + 0269a47 commit 1f09e4d

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ function New-VagrantVMXML {
224224
[string] $SourcePath,
225225
[parameter (Mandatory=$false)]
226226
[bool] $LinkedClone = $false,
227+
[parameter (Mandatory=$false)]
228+
[int] $Memory = $null,
229+
[parameter (Mandatory=$false)]
230+
[int] $MaxMemory = $null,
231+
[parameter (Mandatory=$false)]
232+
[int] $CPUCount = $null,
227233
[parameter(Mandatory=$false)]
228234
[string] $VMName
229235
)
@@ -327,7 +333,11 @@ function New-VagrantVMXML {
327333

328334
# Apply original VM configuration to new VM instance
329335

330-
$processors = $VMConfig.configuration.settings.processors.count."#text"
336+
if($CPUCount -ne $null) {
337+
$processors = $CPUCount
338+
} else {
339+
$processors = $VMConfig.configuration.settings.processors.count."#text"
340+
}
331341
$notes = (Select-Xml -XML $VMConfig -XPath "//notes").node."#text"
332342
$memory = (Select-Xml -XML $VMConfig -XPath "//memory").node.Bank
333343
if ($memory.dynamic_memory_enabled."#text" -eq "True") {
@@ -336,10 +346,22 @@ function New-VagrantVMXML {
336346
else {
337347
$dynamicmemory = $False
338348
}
339-
# Memory values need to be in bytes
340-
$MemoryMaximumBytes = ($memory.limit."#text" -as [int]) * 1MB
341-
$MemoryStartupBytes = ($memory.size."#text" -as [int]) * 1MB
342-
$MemoryMinimumBytes = ($memory.reservation."#text" -as [int]) * 1MB
349+
350+
351+
if($Memory -ne $null) {
352+
$MemoryMaximumBytes = $Memory * 1MB
353+
$MemoryStartupBytes = $Memory * 1MB
354+
$MemoryMinimumBytes = $Memory * 1MB
355+
} else {
356+
$MemoryMaximumBytes = ($memory.limit."#text" -as [int]) * 1MB
357+
$MemoryStartupBytes = ($memory.size."#text" -as [int]) * 1MB
358+
$MemoryMinimumBytes = ($memory.reservation."#text" -as [int]) * 1MB
359+
}
360+
361+
if($MaxMemory -ne $null) {
362+
$dynamicmemory = $true
363+
$MemoryMaximumBytes = $MaxMemory * 1MB
364+
}
343365

344366
$Config = @{
345367
ProcessorCount = $processors;

0 commit comments

Comments
 (0)