Skip to content

Commit 91b7b61

Browse files
[Compute] HostGroup: add InstanceView parameter to Get-AzHostGroup (#12554)
* Added the InstanceView switch to the Get-AzHostGroup cmdlet * Added test for instanceview switch and re-recorded resources * Updated documentation
1 parent 0f4b318 commit 91b7b61

File tree

7 files changed

+1954
-2445
lines changed

7 files changed

+1954
-2445
lines changed

src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ function Test-DedicatedHost
7979
Assert-AreEqual 1 $hostGroup.Hosts.Count;
8080
Assert-AreEqual 1 $hostGroup.Count;
8181

82+
$hostGroupInstanceViewResult = Get-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -InstanceView;
83+
Assert-NotNull $hostGroupInstanceViewResult.Hosts;
84+
foreach ($hostInstanceViewWithName in $hostGroupInstanceViewResult.Hosts) {
85+
Assert-NotNull $hostInstanceViewWithName.Name;
86+
}
87+
8288
Remove-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName;
8389

8490
Assert-ThrowsContains {

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DedicatedHostTests/TestDedicatedHost.json

Lines changed: 406 additions & 399 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DedicatedHostTests/TestDedicatedHostVirtualMachine.json

Lines changed: 1475 additions & 2040 deletions
Large diffs are not rendered by default.

src/Compute/Compute/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
- Additional information about change #1
2020
-->
2121
## Upcoming Release
22+
* Added the '-InstanceView' switch as optional parameter to Get-AzHostGroup
23+
2224

2325
## Version 4.2.1
2426
* Added warning when using `New-AzVmss` without "latest" image version.

src/Compute/Compute/Generated/DedicatedHostGroup/DedicatedHostGroupGetMethod.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,21 @@ public override void ExecuteCmdlet()
5656

5757
if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(hostGroupName))
5858
{
59-
var result = DedicatedHostGroupsClient.Get(resourceGroupName, hostGroupName);
60-
var psObject = new PSHostGroup();
61-
ComputeAutomationAutoMapperProfile.Mapper.Map<DedicatedHostGroup, PSHostGroup>(result, psObject);
62-
WriteObject(psObject);
59+
if (this.InstanceView.IsPresent)
60+
{
61+
var result = DedicatedHostGroupsClient.Get(resourceGroupName, hostGroupName, InstanceViewTypes.InstanceView).InstanceView;
62+
var psObject = new PSHostGroupInstanceView();
63+
ComputeAutoMapperProfile.Mapper.Map<DedicatedHostGroupInstanceView, PSHostGroupInstanceView>(result, psObject);
64+
WriteObject(psObject);
65+
}
66+
else
67+
{
68+
var result = DedicatedHostGroupsClient.Get(resourceGroupName, hostGroupName);
69+
var psObject = new PSHostGroup();
70+
ComputeAutomationAutoMapperProfile.Mapper.Map<DedicatedHostGroup, PSHostGroup>(result, psObject);
71+
WriteObject(psObject);
72+
}
73+
6374
}
6475
else if (!string.IsNullOrEmpty(resourceGroupName))
6576
{
@@ -121,6 +132,12 @@ public override void ExecuteCmdlet()
121132
[ResourceNameCompleter("Microsoft.Compute/hostGroups", "ResourceGroupName")]
122133
public string Name { get; set; }
123134

135+
[Parameter(
136+
ParameterSetName = "DefaultParameter",
137+
Mandatory=false
138+
)]
139+
public SwitchParameter InstanceView { get; set; } = false;
140+
124141
[Parameter(
125142
ParameterSetName = "ResourceIdParameter",
126143
Position = 0,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Copyright (c) Microsoft and contributors. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
using System.Collections.Generic;
18+
using Microsoft.Azure.Management.Compute.Models;
19+
20+
21+
namespace Microsoft.Azure.Commands.Compute.Automation.Models
22+
{
23+
public partial class PSHostGroupInstanceView
24+
{
25+
public IList<DedicatedHostInstanceViewWithName> Hosts { get; set; }
26+
}
27+
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Get or list hosts.
1414

1515
### DefaultParameter (Default)
1616
```
17-
Get-AzHostGroup [[-ResourceGroupName] <String>] [[-Name] <String>] [-DefaultProfile <IAzureContextContainer>]
18-
[<CommonParameters>]
17+
Get-AzHostGroup [[-ResourceGroupName] <String>] [[-Name] <String>] [-InstanceView]
18+
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1919
```
2020

2121
### ResourceIdParameter
@@ -88,6 +88,21 @@ Accept pipeline input: False
8888
Accept wildcard characters: False
8989
```
9090
91+
### -InstanceView
92+
Expand the returned object to also list the host's instance views.
93+
94+
```yaml
95+
Type: System.Management.Automation.SwitchParameter
96+
Parameter Sets: DefaultParameter
97+
Aliases:
98+
99+
Required: False
100+
Position: Named
101+
Default value: None
102+
Accept pipeline input: False
103+
Accept wildcard characters: False
104+
```
105+
91106
### -Name
92107
The name of the host group.
93108

0 commit comments

Comments
 (0)