diff --git a/src/PSProxmoxVE/Cmdlets/HA/SetPveHaRuleCmdlet.cs b/src/PSProxmoxVE/Cmdlets/HA/SetPveHaRuleCmdlet.cs index bb1d1d9..89d7e87 100644 --- a/src/PSProxmoxVE/Cmdlets/HA/SetPveHaRuleCmdlet.cs +++ b/src/PSProxmoxVE/Cmdlets/HA/SetPveHaRuleCmdlet.cs @@ -19,6 +19,11 @@ namespace PSProxmoxVE.Cmdlets.HA HelpMessage = "HA rule ID.")] public string Rule { get; set; } = string.Empty; + /// Rule type (required by PVE API on update). + [Parameter(Mandatory = true, Position = 1, HelpMessage = "HA rule type: node-affinity or resource-affinity.")] + [ValidateSet("node-affinity", "resource-affinity")] + public string Type { get; set; } = string.Empty; + /// Rule state. [Parameter(Mandatory = false, HelpMessage = "Rule state: enabled or disabled.")] [ValidateSet("enabled", "disabled")] @@ -42,7 +47,7 @@ namespace PSProxmoxVE.Cmdlets.HA var service = new HaService(); - var data = new Dictionary(); + var data = new Dictionary { ["type"] = Type }; if (State != null) data["state"] = State; if (Comment != null) data["comment"] = Comment; if (Properties != null) diff --git a/tests/PSProxmoxVE.Tests/HA/HaCmdlets.Tests.ps1 b/tests/PSProxmoxVE.Tests/HA/HaCmdlets.Tests.ps1 index 96fea4f..501cbf9 100644 --- a/tests/PSProxmoxVE.Tests/HA/HaCmdlets.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/HA/HaCmdlets.Tests.ps1 @@ -736,6 +736,15 @@ Describe 'Set-PveHaRule' -Tag 'Unit' { $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } $isMandatory | Should -Not -BeNullOrEmpty } + It 'Should have mandatory Type parameter with ValidateSet' { + Skip-IfMissing 'Set-PveHaRule' + $p = $script:Cmd.Parameters['Type'] + $p | Should -Not -BeNullOrEmpty + $isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory } + $isMandatory | Should -Not -BeNullOrEmpty + $vsAttr = $p.Attributes | Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] } + $vsAttr | Should -Not -BeNullOrEmpty + } It 'Should have optional State parameter with ValidateSet' { Skip-IfMissing 'Set-PveHaRule' $p = $script:Cmd.Parameters['State'] @@ -762,7 +771,7 @@ Describe 'Set-PveHaRule' -Tag 'Unit' { Context 'Without active session' { It 'Should throw when no session is active' { Skip-IfMissing 'Set-PveHaRule' - { Set-PveHaRule -Rule 'rule1' -ErrorAction Stop -Confirm:$false } | + { Set-PveHaRule -Rule 'rule1' -Type 'node-affinity' -ErrorAction Stop -Confirm:$false } | Should -Throw '*No active Proxmox VE session*' } } diff --git a/tests/PSProxmoxVE.Tests/Integration/16_Cluster.Tests.ps1 b/tests/PSProxmoxVE.Tests/Integration/16_Cluster.Tests.ps1 index e66e669..405ccc7 100644 --- a/tests/PSProxmoxVE.Tests/Integration/16_Cluster.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/Integration/16_Cluster.Tests.ps1 @@ -360,7 +360,7 @@ Describe 'Cluster Config & HA Lifecycle — Integration' -Tag 'Integration' { return } - { Set-PveHaRule -Rule 'pester-rule-1' ` + { Set-PveHaRule -Rule 'pester-rule-1' -Type 'node-affinity' ` -Comment 'Updated by Pester' ` -Confirm:$false ` -ErrorAction Stop } | Should -Not -Throw