From a592991bfe323a7dae7f0c72569d122336af1046 Mon Sep 17 00:00:00 2001 From: Jacob Coats Date: Wed, 14 May 2025 12:00:51 -0700 Subject: [PATCH 1/4] Remake changes --- .../ScenarioTests/DedicatedHostTests.cs | 7 +++ .../ScenarioTests/DedicatedHostTests.ps1 | 43 +++++++++++++++++++ src/Compute/Compute/ChangeLog.md | 1 + .../DedicatedHostUpdateMethod.cs | 23 +++++++--- .../Compute/Generated/Models/PSHost.cs | 3 +- 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.cs b/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.cs index a3345e489d66..5292fd04e0b8 100644 --- a/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.cs +++ b/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.cs @@ -51,5 +51,12 @@ public void TestDedicatedHostUpdateAndSize() { TestRunner.RunTestScript("Test-DedicatedHostUpdateAndSize"); } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void testgenupdateazhost() + { + TestRunner.RunTestScript("TestGen-updateazhost"); + } } } diff --git a/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 b/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 index 56b2057f8a2a..4d0c0997dc0c 100644 --- a/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 +++ b/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 @@ -327,6 +327,49 @@ function Test-DedicatedHostUpdateAndSize $dHUpdate = Update-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -AutoReplaceOnFailure $false; Assert-AreEqual $dHUpdate.AutoReplaceOnFailure $False ; + } + finally + { + # Cleanup + Clean-ResourceGroup $rgname + } +} + +} + +<# +.SYNOPSIS +Test Update-AzHost with Redeploy parameter. +#> +function TestGen-updateazhost +{ + # Setup + $rgname = Get-ComputeTestResourceName + + try + { + # Common + [string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP"; + $loc = $loc.Replace(' ', ''); + + New-AzResourceGroup -Name $rgname -Location $loc -Force; + + $hostGroupName = $rgname + 'hostgroup'; + New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 1 -Zone "2" -Tag @{key1 = "val1"}; + + $hostName = $rgname + 'host'; + New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku "Dadsv5-Type1" -Tag @{key1 = "val2"}; + + # Test Update-AzHost with Redeploy parameter + $updateHost = Update-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Redeploy $true; + Assert-AreEqual $true $updateHost.Redeploy; + + # Verify the host is updated + $dedicatedHost = Get-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName; + Assert-AreEqual $hostName $dedicatedHost.Name; + Assert-AreEqual $rgname $dedicatedHost.ResourceGroupName; + Assert-AreEqual $loc $dedicatedHost.Location; + } finally { diff --git a/src/Compute/Compute/ChangeLog.md b/src/Compute/Compute/ChangeLog.md index dd327ab98cbb..3aa7fa46d12f 100644 --- a/src/Compute/Compute/ChangeLog.md +++ b/src/Compute/Compute/ChangeLog.md @@ -23,6 +23,7 @@ * Added new properties `Architecture`, `HyperVGeneration`, and `ImageDeprecationStatus` to be returned in `Get-AzVMImage` ListVMImage parameter set. * Deprecated `Get-AzVMSize` 'List Virtual Machine Size' parameter set. * Added new parameters `EnableAutomaticZoneRebalance`, `AutomaticZoneRebalanceStrategy` and `AutomaticZoneRebalanceBehavior` to `New-AzVmssConfig` and `Update-AzVmss` cmdlets for VMSS Automatic Zone Rebalancing. +* Added `-Redeploy` parameter as an optional boolean for `Update-AzHost` cmdlet to enhance host management capabilities. ## Version 9.3.0 * Added new cmdlets `Add-AzVmssSkuProfileVMSize` and `Remove-AzVmssSkuProfileVMSize` to add and remove VM sizes to and from the VMSS SkuProfile. diff --git a/src/Compute/Compute/Generated/DedicatedHost/DedicatedHostUpdateMethod.cs b/src/Compute/Compute/Generated/DedicatedHost/DedicatedHostUpdateMethod.cs index b11cce725ad6..fea27e35d45b 100644 --- a/src/Compute/Compute/Generated/DedicatedHost/DedicatedHostUpdateMethod.cs +++ b/src/Compute/Compute/Generated/DedicatedHost/DedicatedHostUpdateMethod.cs @@ -78,11 +78,19 @@ public override void ExecuteCmdlet() parameters.Sku = new Sku(this.Sku, null, null); } + if (this.IsParameterBound(c => c.Redeploy)) + { + var redeployResult = DedicatedHostsClient.Redeploy(resourceGroupName, hostGroupName, Name); + WriteObject(redeployResult); + } + else + { + var result = DedicatedHostsClient.Update(resourceGroupName, hostGroupName, Name, parameters); - var result = DedicatedHostsClient.Update(resourceGroupName, hostGroupName, Name, parameters); - var psObject = new PSHost(); - ComputeAutomationAutoMapperProfile.Mapper.Map(result, psObject); - WriteObject(psObject); + var psObject = new PSHost(); + ComputeAutomationAutoMapperProfile.Mapper.Map(result, psObject); + WriteObject(psObject); + } } }); } @@ -123,6 +131,11 @@ public override void ExecuteCmdlet() Mandatory = false)] public DedicatedHostLicenseTypes LicenseType { get; set; } + [Parameter( + Mandatory = false, + HelpMessage = "Redeploy the dedicated host. The operation will complete successfully once the dedicated host has migrated to a new node and is running. To determine the health of VMs deployed on the dedicated host after the redeploy check the Resource Health Center in the Azure Portal. Please refer to https://docs.microsoft.com/azure/service-health/resource-health-overview for more details.")] + public bool Redeploy { get; set; } + [Parameter( ParameterSetName = "ResourceIdParameter", Position = 0, @@ -131,4 +144,4 @@ public override void ExecuteCmdlet() public string ResourceId { get; set; } } -} +} \ No newline at end of file diff --git a/src/Compute/Compute/Generated/Models/PSHost.cs b/src/Compute/Compute/Generated/Models/PSHost.cs index 0b132b34833d..ce897d1aa8f9 100644 --- a/src/Compute/Compute/Generated/Models/PSHost.cs +++ b/src/Compute/Compute/Generated/Models/PSHost.cs @@ -54,6 +54,5 @@ public string ResourceGroupName public string Type { get; set; } public string Location { get; set; } public IDictionary Tags { get; set; } - } -} +} \ No newline at end of file From ac0499737173e58caff90833b3914cd9ca4b45ef Mon Sep 17 00:00:00 2001 From: Jacob Coats Date: Tue, 20 May 2025 14:00:11 -0700 Subject: [PATCH 2/4] Update markdown --- src/Compute/Compute/help/Update-AzHost.md | 72 ++++++++++++++--------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/src/Compute/Compute/help/Update-AzHost.md b/src/Compute/Compute/help/Update-AzHost.md index 9ea3b45c5314..8416af254df1 100644 --- a/src/Compute/Compute/help/Update-AzHost.md +++ b/src/Compute/Compute/help/Update-AzHost.md @@ -15,16 +15,15 @@ Updates the Dedicated Host. ### DefaultParameter (Default) ``` Update-AzHost [-ResourceGroupName] [-HostGroupName] [-Name] [-Sku ] - [-AutoReplaceOnFailure ] [-LicenseType ] - [-DefaultProfile ] [-WhatIf] [-Confirm] - [] + [-AutoReplaceOnFailure ] [-LicenseType ] [-Redeploy ] + [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` ### ResourceIdParameter ``` Update-AzHost [-Sku ] [-AutoReplaceOnFailure ] [-LicenseType ] - [-ResourceId] [-DefaultProfile ] - [-WhatIf] [-Confirm] [] + [-Redeploy ] [-ResourceId] [-DefaultProfile ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -60,7 +59,7 @@ This command updates the given Sku of a host. Specifies whether the host should be replaced automatically in case of a failure. ```yaml -Type: System.Boolean +Type: Boolean Parameter Sets: (All) Aliases: @@ -71,11 +70,26 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -DefaultProfile The credentials, account, tenant, and subscription used for communication with Azure. ```yaml -Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer +Type: IAzureContextContainer Parameter Sets: (All) Aliases: AzContext, AzureRmContext, AzureCredential @@ -90,7 +104,7 @@ Accept wildcard characters: False Name of the Host Group. ```yaml -Type: System.String +Type: String Parameter Sets: DefaultParameter Aliases: @@ -105,7 +119,7 @@ Accept wildcard characters: False Specifies the software license type that will be applied to the VMs deployed on the host. Possible values are: None, Windows_Server_Hybrid, and Windows_Server_Perpetual. Default value is None. ```yaml -Type: Microsoft.Azure.Management.Compute.Models.DedicatedHostLicenseTypes +Type: DedicatedHostLicenseTypes Parameter Sets: (All) Aliases: Accepted values: None, WindowsServerHybrid, WindowsServerPerpetual @@ -121,7 +135,7 @@ Accept wildcard characters: False Specifies the name of the Host to be updated. ```yaml -Type: System.String +Type: String Parameter Sets: DefaultParameter Aliases: HostName @@ -132,11 +146,26 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -Redeploy +Redeploy the dedicated host. The operation will complete successfully once the dedicated host has migrated to a new node and is running. To determine the health of VMs deployed on the dedicated host after the redeploy check the Resource Health Center in the Azure Portal. Please refer to https://docs.microsoft.com/azure/service-health/resource-health-overview for more details. + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -ResourceGroupName The name of the resource group. ```yaml -Type: System.String +Type: String Parameter Sets: DefaultParameter Aliases: @@ -151,7 +180,7 @@ Accept wildcard characters: False Resource Id of the Host to be updated. ```yaml -Type: System.String +Type: String Parameter Sets: ResourceIdParameter Aliases: @@ -166,7 +195,7 @@ Accept wildcard characters: False The Sku Name that needs to be updated. ```yaml -Type: System.String +Type: String Parameter Sets: (All) Aliases: @@ -177,27 +206,12 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Confirm -Prompts you for confirmation before running the cmdlet. - -```yaml -Type: System.Management.Automation.SwitchParameter -Parameter Sets: (All) -Aliases: cf - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -WhatIf Shows what would happen if the cmdlet runs. The cmdlet is not run. ```yaml -Type: System.Management.Automation.SwitchParameter +Type: SwitchParameter Parameter Sets: (All) Aliases: wi From 06d78306763a4f56df5fe123898eb37d5da38e96 Mon Sep 17 00:00:00 2001 From: Jacob Coats Date: Wed, 21 May 2025 14:22:15 -0700 Subject: [PATCH 3/4] Remove extraneous curly brace --- src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 b/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 index 4d0c0997dc0c..22a6be0f9ae5 100644 --- a/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 +++ b/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 @@ -335,8 +335,6 @@ function Test-DedicatedHostUpdateAndSize } } -} - <# .SYNOPSIS Test Update-AzHost with Redeploy parameter. From f376046066472739d69925afb6d4477f6381ad7f Mon Sep 17 00:00:00 2001 From: Jacob Coats Date: Mon, 26 May 2025 17:49:10 -0700 Subject: [PATCH 4/4] Change to switch parameter --- src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 | 4 ++-- .../Generated/DedicatedHost/DedicatedHostUpdateMethod.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 b/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 index 22a6be0f9ae5..199fbbf5bfe2 100644 --- a/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 +++ b/src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1 @@ -359,8 +359,8 @@ function TestGen-updateazhost New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku "Dadsv5-Type1" -Tag @{key1 = "val2"}; # Test Update-AzHost with Redeploy parameter - $updateHost = Update-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Redeploy $true; - Assert-AreEqual $true $updateHost.Redeploy; + $updateHost = Update-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Redeploy; + Assert-IsNotNull $updateHost.Redeploy; # Verify the host is updated $dedicatedHost = Get-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName; diff --git a/src/Compute/Compute/Generated/DedicatedHost/DedicatedHostUpdateMethod.cs b/src/Compute/Compute/Generated/DedicatedHost/DedicatedHostUpdateMethod.cs index fea27e35d45b..f3645b9080f5 100644 --- a/src/Compute/Compute/Generated/DedicatedHost/DedicatedHostUpdateMethod.cs +++ b/src/Compute/Compute/Generated/DedicatedHost/DedicatedHostUpdateMethod.cs @@ -78,7 +78,7 @@ public override void ExecuteCmdlet() parameters.Sku = new Sku(this.Sku, null, null); } - if (this.IsParameterBound(c => c.Redeploy)) + if (this.Redeploy.IsPresent) { var redeployResult = DedicatedHostsClient.Redeploy(resourceGroupName, hostGroupName, Name); WriteObject(redeployResult); @@ -134,7 +134,7 @@ public override void ExecuteCmdlet() [Parameter( Mandatory = false, HelpMessage = "Redeploy the dedicated host. The operation will complete successfully once the dedicated host has migrated to a new node and is running. To determine the health of VMs deployed on the dedicated host after the redeploy check the Resource Health Center in the Azure Portal. Please refer to https://docs.microsoft.com/azure/service-health/resource-health-overview for more details.")] - public bool Redeploy { get; set; } + public SwitchParameter Redeploy { get; set; } [Parameter( ParameterSetName = "ResourceIdParameter",