diff --git a/src/PSProxmoxVE.Core/Models/Vms/PveVmConfig.cs b/src/PSProxmoxVE.Core/Models/Vms/PveVmConfig.cs index 1dd5ba3..b29fd3c 100644 --- a/src/PSProxmoxVE.Core/Models/Vms/PveVmConfig.cs +++ b/src/PSProxmoxVE.Core/Models/Vms/PveVmConfig.cs @@ -322,6 +322,8 @@ public class PveVmConfig [JsonExtensionData] private IDictionary? ExtensionData { get; set; } + private Dictionary? _additionalProperties; + /// /// Any VM config keys not surfaced as a typed property above (e.g. hostpci0, /// usb0, numa0, additional disk buses). Keys map to native .NET values so the @@ -329,7 +331,10 @@ public class PveVmConfig /// [JsonIgnore] public Dictionary AdditionalProperties => - ExtensionData == null + // Built once from the deserialized extension data (the model is effectively + // immutable after deserialization), avoiding a fresh allocation per access + // when iterating many configs in a pipeline. + _additionalProperties ??= ExtensionData == null ? new Dictionary() : ExtensionData.ToDictionary(kvp => kvp.Key, kvp => JsonHelper.ToNative(kvp.Value)); diff --git a/src/PSProxmoxVE/Cmdlets/Vms/NewPveVmCmdlet.cs b/src/PSProxmoxVE/Cmdlets/Vms/NewPveVmCmdlet.cs index 2f8f15e..af0d5b3 100644 --- a/src/PSProxmoxVE/Cmdlets/Vms/NewPveVmCmdlet.cs +++ b/src/PSProxmoxVE/Cmdlets/Vms/NewPveVmCmdlet.cs @@ -268,6 +268,7 @@ namespace PSProxmoxVE.Cmdlets.Vms private bool HasDiskOptions() => !string.IsNullOrEmpty(DiskBus) + || !string.IsNullOrEmpty(ScsiHardware) || DiskIoThread.IsPresent || !string.IsNullOrEmpty(DiskAio) || DiskSsd.IsPresent diff --git a/tests/PSProxmoxVE.Tests/Vms/New-PveVm.Tests.ps1 b/tests/PSProxmoxVE.Tests/Vms/New-PveVm.Tests.ps1 index f8d2cbe..af429ae 100644 --- a/tests/PSProxmoxVE.Tests/Vms/New-PveVm.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/Vms/New-PveVm.Tests.ps1 @@ -222,6 +222,11 @@ Describe 'New-PveVm' { Should -Throw '*virtio-scsi-single*' } + It 'Should reject -DiskIoThread on scsi with a wrong -ScsiHardware (virtio-scsi-pci)' { + { New-PveVm -Node 'pve-node1' -DiskStorage 'local-lvm' -DiskSize '32' -DiskBus scsi -ScsiHardware 'virtio-scsi-pci' -DiskIoThread -WhatIf -ErrorAction Stop } | + Should -Throw '*virtio-scsi-single*' + } + It 'Should accept -DiskIoThread on scsi with -ScsiHardware virtio-scsi-single' { { New-PveVm -Node 'pve-node1' -DiskStorage 'local-lvm' -DiskSize '32' -DiskBus scsi -ScsiHardware 'virtio-scsi-single' -DiskIoThread -WhatIf -ErrorAction Stop } | Should -Not -Throw