Skip to content

Commit 95f926a

Browse files
authored
Update Get-AzHost cmdlet to return Host for -ResourceId parameterset (#19770)
* Update `Get-AzHost` cmdlet to return Host for -ResourceId parameterset * Added Test Case * Added Example for `Get-AzHost` cmdlet
1 parent f003a89 commit 95f926a

File tree

6 files changed

+1094
-3
lines changed

6 files changed

+1094
-3
lines changed

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,14 @@ public void VirtualMachineGetStatusWithHealhtExtension()
234234
{
235235
TestRunner.RunTestScript("Test-VirtualMachineGetStatusWithHealhtExtension");
236236
}
237-
237+
238+
[Fact]
239+
[Trait(Category.AcceptanceType, Category.CheckIn)]
240+
public void TestVirtualMachineGetHost()
241+
{
242+
TestRunner.RunTestScript("Test-VirtualMachineGetHost");
243+
}
244+
238245
[Fact]
239246
[Trait(Category.AcceptanceType, Category.CheckIn)]
240247
public void TestVirtualMachineGetStatusWithAssignedHost()

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,6 +3132,45 @@ function Test-VirtualMachineGetStatusWithHealhtExtension
31323132
}
31333133
}
31343134

3135+
<#
3136+
.SYNOPSIS
3137+
Test Virtual Machines
3138+
#>
3139+
function Test-VirtualMachineGetHost
3140+
{
3141+
param ($loc)
3142+
# Setup
3143+
$rgname = Get-ComputeTestResourceName
3144+
3145+
try
3146+
{
3147+
# Common
3148+
$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
3149+
$loc = $loc.Replace(' ', '');
3150+
3151+
# Creating the resource group
3152+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
3153+
3154+
# Hostgroup and Hostgroupname
3155+
$hostGroupName = $rgname + "HostGroup";
3156+
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 1 -Zone "2" -Tag @{key1 = "val1"};
3157+
3158+
$Sku = "ESv3-Type1";
3159+
$hostGroup = Get-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName;
3160+
$hostName = $rgname + "Host";
3161+
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku $Sku -Tag @{key1 = "val2"};
3162+
$dedicatedHost = Get-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName;
3163+
$host2 = Get-AzHost -ResourceId $dedicatedHost.Id;
3164+
3165+
Assert-NotNull $host2.Id;
3166+
}
3167+
finally
3168+
{
3169+
# Cleanup
3170+
Clean-ResourceGroup $rgname
3171+
}
3172+
}
3173+
31353174
<#
31363175
.SYNOPSIS
31373176
Test Virtual Machines

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests/TestVirtualMachineGetHost.json

Lines changed: 1012 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Updated `Get-AzHost` cmdlet logic to return Host for `-ResourceId` parameterset.
2324
* For `New-AzGalleryImageVersion`, update property mapping for `Encryption`.
2425

2526
## Version 4.32.0

src/Compute/Compute/Generated/DedicatedHost/DedicatedHostGetMethod.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public override void ExecuteCmdlet()
4848
{
4949
case "ResourceIdParameter":
5050
resourceGroupName = GetResourceGroupName(this.ResourceId);
51-
hostGroupName = GetResourceName(this.ResourceId, "Microsoft.Compute/hosts", "hosts");
52-
hostName = GetResourceName(this.ResourceId, "Microsoft.Compute/hosts", "hosts");
51+
hostGroupName = GetResourceName(this.ResourceId, "Microsoft.Compute/hostGroups", "hosts");
52+
hostName = GetInstanceId(this.ResourceId, "Microsoft.Compute/hostGroups", "hosts");
5353
break;
5454
default:
5555
resourceGroupName = this.ResourceGroupName;

src/Compute/Compute/help/Get-AzHost.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,38 @@ myrg01 myhost02 eastus {[key1, val2]} ESv3-Type1 1
113113

114114
This command returns all hosts in the given host group.
115115

116+
### Example 4: This command retuns a Host for provided -ResourceId.
117+
```powershell
118+
$rgname = "rgname"
119+
$loc = "eastus"
120+
$hostGroupName = $rgname + "HostGroup"
121+
$hostName = $rgname + "Host"
122+
$Sku = "ESv3-Type1"
123+
# Create Hostgroup and Hostgroupname
124+
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 1 -Zone "2"
125+
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku $Sku
126+
127+
# Fetch Host using -ResouceId
128+
$dedicatedHost = Get-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName
129+
$host = Get-AzHost -ResourceId $dedicatedHost.Id
130+
```
131+
132+
```output
133+
ResourceGroupName : rgname
134+
PlatformFaultDomain : 0
135+
AutoReplaceOnFailure : True
136+
HostId : 0730655b-051d-4559-a83a-5d579d15fec2
137+
ProvisioningTime : 10/14/2022 7:28:47 AM
138+
ProvisioningState : Succeeded
139+
Sku :
140+
Name : ESv3-Type1
141+
Id : /subscriptions/e37510d7-33b6-4676-886f-ee75bcc01871/resourceGroups/rgname/providers/Microsoft.Compute/hostGroups/rgnameHostGroup/hosts/rgnameHost
142+
Name : rgnameHost
143+
Type : Microsoft.Compute/hostGroups/hosts
144+
Location : eastus
145+
Tags : {}
146+
```
147+
116148
## PARAMETERS
117149

118150
### -DefaultProfile

0 commit comments

Comments
 (0)