Skip to content

Commit

Permalink
Update Get-AzHost cmdlet to return Host for -ResourceId parameterset (
Browse files Browse the repository at this point in the history
Azure#19770)

* Update `Get-AzHost` cmdlet to return Host for -ResourceId parameterset

* Added Test Case

* Added Example for `Get-AzHost` cmdlet
  • Loading branch information
pselugar authored Oct 17, 2022
1 parent f003a89 commit 95f926a
Show file tree
Hide file tree
Showing 6 changed files with 1,094 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,14 @@ public void VirtualMachineGetStatusWithHealhtExtension()
{
TestRunner.RunTestScript("Test-VirtualMachineGetStatusWithHealhtExtension");
}


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachineGetHost()
{
TestRunner.RunTestScript("Test-VirtualMachineGetHost");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachineGetStatusWithAssignedHost()
Expand Down
39 changes: 39 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3132,6 +3132,45 @@ function Test-VirtualMachineGetStatusWithHealhtExtension
}
}

<#
.SYNOPSIS
Test Virtual Machines
#>
function Test-VirtualMachineGetHost
{
param ($loc)
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
$loc = $loc.Replace(' ', '');

# Creating the resource group
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# Hostgroup and Hostgroupname
$hostGroupName = $rgname + "HostGroup";
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 1 -Zone "2" -Tag @{key1 = "val1"};

$Sku = "ESv3-Type1";
$hostGroup = Get-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName;
$hostName = $rgname + "Host";
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku $Sku -Tag @{key1 = "val2"};
$dedicatedHost = Get-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName;
$host2 = Get-AzHost -ResourceId $dedicatedHost.Id;

Assert-NotNull $host2.Id;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test Virtual Machines
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
-->
## Upcoming Release
* Updated `Get-AzHost` cmdlet logic to return Host for `-ResourceId` parameterset.
* For `New-AzGalleryImageVersion`, update property mapping for `Encryption`.

## Version 4.32.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public override void ExecuteCmdlet()
{
case "ResourceIdParameter":
resourceGroupName = GetResourceGroupName(this.ResourceId);
hostGroupName = GetResourceName(this.ResourceId, "Microsoft.Compute/hosts", "hosts");
hostName = GetResourceName(this.ResourceId, "Microsoft.Compute/hosts", "hosts");
hostGroupName = GetResourceName(this.ResourceId, "Microsoft.Compute/hostGroups", "hosts");
hostName = GetInstanceId(this.ResourceId, "Microsoft.Compute/hostGroups", "hosts");
break;
default:
resourceGroupName = this.ResourceGroupName;
Expand Down
32 changes: 32 additions & 0 deletions src/Compute/Compute/help/Get-AzHost.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,38 @@ myrg01 myhost02 eastus {[key1, val2]} ESv3-Type1 1

This command returns all hosts in the given host group.

### Example 4: This command retuns a Host for provided -ResourceId.
```powershell
$rgname = "rgname"
$loc = "eastus"
$hostGroupName = $rgname + "HostGroup"
$hostName = $rgname + "Host"
$Sku = "ESv3-Type1"
# Create Hostgroup and Hostgroupname
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 1 -Zone "2"
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku $Sku
# Fetch Host using -ResouceId
$dedicatedHost = Get-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName
$host = Get-AzHost -ResourceId $dedicatedHost.Id
```

```output
ResourceGroupName : rgname
PlatformFaultDomain : 0
AutoReplaceOnFailure : True
HostId : 0730655b-051d-4559-a83a-5d579d15fec2
ProvisioningTime : 10/14/2022 7:28:47 AM
ProvisioningState : Succeeded
Sku :
Name : ESv3-Type1
Id : /subscriptions/e37510d7-33b6-4676-886f-ee75bcc01871/resourceGroups/rgname/providers/Microsoft.Compute/hostGroups/rgnameHostGroup/hosts/rgnameHost
Name : rgnameHost
Type : Microsoft.Compute/hostGroups/hosts
Location : eastus
Tags : {}
```

## PARAMETERS

### -DefaultProfile
Expand Down

0 comments on commit 95f926a

Please sign in to comment.