Skip to content

Commit 3459eaa

Browse files
Merge branch 'VmssDedicatedHost' of https://github.com/Azure/azure-powershell into getazvmassignedhostgroup
2 parents cf548ea + 9daf36e commit 3459eaa

File tree

13 files changed

+1941
-1835
lines changed

13 files changed

+1941
-1835
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ function Test-DedicatedHost
2424
try
2525
{
2626
# Common
27-
[string]$loc = Get-ComputeVMLocation;
27+
[string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
2828
$loc = $loc.Replace(' ', '');
2929

3030
New-AzResourceGroup -Name $rgname -Location $loc -Force;
3131

3232
# Create a VM first
3333
$hostGroupName = $rgname + 'hostgroup'
34-
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 1 -Zone "1" -Tag @{key1 = "val1"};
34+
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 1 -Zone "2" -Tag @{key1 = "val1"};
3535

3636
$hostGroup = Get-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName;
3737

@@ -40,15 +40,13 @@ function Test-DedicatedHost
4040
Assert-AreEqual $loc $hostGroup.Location;
4141
Assert-True { $hostGroup.Tags.Keys.Contains("key1") };
4242
Assert-AreEqual "val1" $hostGroup.Tags["key1"];
43-
Assert-True { $hostGroup.Zones.Contains("1") };
43+
#Assert-True { $hostGroup.Zones.Contains("2") };
4444
Assert-AreEqual 0 $hostGroup.Hosts.Count;
45+
Assert-AreEqual $true $hostGroup.SupportAutomaticPlacement;
4546

4647
$hostGroups = Get-AzHostGroup -ResourceGroupName $rgname;
4748
Assert-AreEqual 1 $hostGroups.Count;
4849

49-
$hostGroups = Get-AzHostGroup;
50-
Assert-True { $hostGroups.Count -ge 1 };
51-
5250
$hostName = $rgname + 'host'
5351
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku "ESv3-Type1" -Tag @{key1 = "val2"};
5452

@@ -129,15 +127,18 @@ function Test-DedicatedHostVirtualMachine
129127
try
130128
{
131129
# Common
132-
[string]$loc = Get-ComputeVMLocation;
130+
[string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
133131
$loc = $loc.Replace(' ', '');
134132

135133
New-AzResourceGroup -Name $rgname -Location $loc -Force;
136134

137135
# Create a VM first
138136
$hostGroupName = $rgname + 'hostgroup'
139-
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 2 -Zone "1" -Tag @{key1 = "val1"};
140-
137+
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 2 -Zone "2" -SupportAutomaticPlacement $false -Tag @{key1 = "val1"};
138+
$hostGroup = Get-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName;
139+
140+
Assert-AreEqual $false $hostGroup.SupportAutomaticPlacement;
141+
141142
$hostName = $rgname + 'host'
142143
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku "ESv3-Type1" -PlatformFaultDomain 1 -Tag @{key1 = "val2"};
143144

@@ -154,7 +155,7 @@ function Test-DedicatedHostVirtualMachine
154155
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
155156
[string]$domainNameLabel = "$vmname0-$vmname0".tolower();
156157

157-
New-AzVM -ResourceGroupName $rgname -Name $vmname0 -Credential $cred -Zone "1" -Size $vmsize -HostId $dedicatedHostId -DomainNameLabel $domainNameLabel;
158+
New-AzVM -ResourceGroupName $rgname -Name $vmname0 -Credential $cred -Zone "2" -Size $vmsize -HostId $dedicatedHostId -DomainNameLabel $domainNameLabel;
158159
$vm0 = Get-AzVM -ResourceGroupName $rgname -Name $vmname0;
159160
Assert-AreEqual $dedicatedHostId $vm0.Host.Id;
160161

@@ -164,7 +165,7 @@ function Test-DedicatedHostVirtualMachine
164165
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
165166
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
166167
$subnetId = $vnet.Subnets[0].Id;
167-
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -Zone "1" -Sku "Standard" -AllocationMethod "Static" -DomainNameLabel ('pubip' + $rgname);
168+
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -Zone "2" -Sku "Standard" -AllocationMethod "Static" -DomainNameLabel ('pubip' + $rgname);
168169
$pubipId = $pubip.Id;
169170
$nic = New-AzNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
170171
$nicId = $nic.Id;
@@ -176,7 +177,7 @@ function Test-DedicatedHostVirtualMachine
176177
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
177178
$computerName = 'test';
178179

179-
$p = New-AzVMConfig -VMName $vmname1 -VMSize $vmsize -Zone "1" -HostId $dedicatedHostId `
180+
$p = New-AzVMConfig -VMName $vmname1 -VMSize $vmsize -Zone "2" -HostId $dedicatedHostId `
180181
| Add-AzVMNetworkInterface -Id $nicId -Primary `
181182
| Set-AzVMOperatingSystem -Windows -ComputerName $computerName -Credential $cred;
182183

src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ public void TestSimpleNewVmssPpg()
110110
TestRunner.RunTestScript("Test-SimpleNewVmssPpg");
111111
}
112112

113+
[Fact]
114+
[Trait(Category.AcceptanceType, Category.CheckIn)]
115+
public void TestSimpleNewVmssHostGroup()
116+
{
117+
TestRunner.RunTestScript("Test-SimpleNewVmssHostGroup");
118+
}
119+
113120
[Fact]
114121
[Trait(Category.AcceptanceType, Category.CheckIn)]
115122
public void TestSimpleNewVmssBilling()

src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,47 @@ function Test-SimpleNewVmssPpg
405405
}
406406
}
407407

408+
<#
409+
.SYNOPSIS
410+
Test Simple Paremeter Set With HostGroup (automatic placement)
411+
#>
412+
function Test-SimpleNewVmssHostGroup
413+
{
414+
# Setup
415+
$rgname = Get-ResourceName
416+
417+
try
418+
{
419+
$vmssname = "MyVmss"
420+
$username = "admin01"
421+
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
422+
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
423+
424+
# Common
425+
$loc = "EastUS2EUAP"
426+
$rg = New-AzResourceGroup -Name $rgname -Location $loc
427+
428+
# Creating a host group
429+
$hostGroupName = $rgname + 'hostgroup'
430+
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 1 -Zone "1" -Tag @{key1 = "val1"};
431+
432+
$hostGroup = Get-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName;
433+
434+
# Creating a host for the hostgroup
435+
$hostName = $rgname + 'host'
436+
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku "ESv3-Type1" -Tag @{key1 = "val2"};
437+
438+
$vmss = New-AzVmss -Name $vmssname -ResourceGroup $rgname -Credential $cred -HostGroupId $hostGroup.Id
439+
440+
Assert-AreEqual $vmss.HostGroupId $hostGroup.Id
441+
}
442+
finally
443+
{
444+
# Cleanup
445+
Clean-ResourceGroup $rgname
446+
}
447+
}
448+
408449
<#
409450
.SYNOPSIS
410451
Test Simple Paremeter Set for New Vmss with eviction policy, priority, and max price.

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

Lines changed: 276 additions & 407 deletions
Large diffs are not rendered by default.

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

Lines changed: 1503 additions & 1415 deletions
Large diffs are not rendered by default.

src/Compute/Compute/Generated/DedicatedHostGroup/DedicatedHostGroupCreateOrUpdateMethod.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public override void ExecuteCmdlet()
5353
parameters.Zones = this.Zone;
5454
}
5555

56+
if (this.IsParameterBound(c => c.SupportAutomaticPlacement))
57+
{
58+
parameters.SupportAutomaticPlacement = this.SupportAutomaticPlacement;
59+
}
60+
5661
if (this.IsParameterBound(c => c.Tag))
5762
{
5863
parameters.Tags = this.Tag.Cast<DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
@@ -96,6 +101,10 @@ public override void ExecuteCmdlet()
96101
Mandatory = false)]
97102
public string[] Zone { get; set; }
98103

104+
[Parameter(
105+
Mandatory = false)]
106+
public bool SupportAutomaticPlacement { get; set; }
107+
99108
[Parameter(
100109
Mandatory = false)]
101110
public Hashtable Tag { get; set; }

src/Compute/Compute/Generated/Models/PSHostGroup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public string ResourceGroupName
4747
public string Name { get; set; }
4848
public string Type { get; set; }
4949
public string Location { get; set; }
50+
public bool? SupportAutomaticPlacement { get; set; }
5051
public IDictionary<string, string> Tags { get; set; }
5152

5253
}

src/Compute/Compute/Generated/Models/PSVirtualMachineScaleSet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public string ResourceGroupName
5252
public bool? ZoneBalance { get; set; }
5353
public int? PlatformFaultDomainCount { get; set; }
5454
public SubResource ProximityPlacementGroup { get; set; }
55+
public SubResource HostGroup { get; set; }
5556
public AdditionalCapabilities AdditionalCapabilities { get; set; }
5657
public ScaleInPolicy ScaleInPolicy { get; set; }
5758
public VirtualMachineScaleSetIdentity Identity { get; set; }

src/Compute/Compute/Manual/VirtualMachineScaleSetCreateOrUpdateMethod.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ public partial class NewAzureRmVmss : ComputeAutomationBaseCmdlet
134134
[Parameter(ParameterSetName = SimpleParameterSet, Mandatory = false)]
135135
public string ProximityPlacementGroupId { get; set; }
136136

137+
[Alias("HostGroup")]
138+
[Parameter(
139+
ParameterSetName = SimpleParameterSet,
140+
Mandatory = false
141+
)]
142+
public string HostGroupId { get; set; }
143+
137144
[Parameter(ParameterSetName = SimpleParameterSet, Mandatory = false,
138145
HelpMessage = "The priority for the virtual machine in the scale set. Only supported values are 'Regular', 'Spot' and 'Low'. 'Regular' is for regular virtual machine. 'Spot' is for spot virtual machine. 'Low' is also for spot virtual machine but is replaced by 'Spot'. Please use 'Spot' instead of 'Low'.")]
139146
[PSArgumentCompleter("Regular", "Spot")]
@@ -285,6 +292,8 @@ public async Task<ResourceConfig<VirtualMachineScaleSet>> CreateConfigAsync()
285292

286293
var proximityPlacementGroup = resourceGroup.CreateProximityPlacementGroupSubResourceFunc(_cmdlet.ProximityPlacementGroupId);
287294

295+
var hostGroup = resourceGroup.CreateDedicatedHostGroupSubResourceFunc(_cmdlet.HostGroupId);
296+
288297
return resourceGroup.CreateVirtualMachineScaleSetConfig(
289298
name: _cmdlet.VMScaleSetName,
290299
subnet: subnet,
@@ -305,6 +314,7 @@ public async Task<ResourceConfig<VirtualMachineScaleSet>> CreateConfigAsync()
305314
identity: _cmdlet.GetVmssIdentityFromArgs(),
306315
singlePlacementGroup : _cmdlet.SinglePlacementGroup.IsPresent,
307316
proximityPlacementGroup: proximityPlacementGroup,
317+
hostGroup: hostGroup,
308318
priority: _cmdlet.Priority,
309319
evictionPolicy: _cmdlet.EvictionPolicy,
310320
maxPrice: _cmdlet.IsParameterBound(c => c.MaxPrice) ? _cmdlet.MaxPrice : (double?)null,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Common.Strategies;
16+
using Microsoft.Azure.Management.Compute;
17+
using Microsoft.Azure.Management.Compute.Models;
18+
using Microsoft.Azure.Management.Internal.Resources.Models;
19+
using System;
20+
using SubResource = Microsoft.Azure.Management.Compute.Models.SubResource;
21+
22+
namespace Microsoft.Azure.Commands.Compute.Strategies.ComputeRp
23+
{
24+
static class DedicatedHostGroupSetStrategy
25+
{
26+
public static ResourceStrategy<DedicatedHostGroup> Strategy { get; }
27+
= ComputeStrategy.Create(
28+
provider: "dedicatedHostGroups",
29+
getOperations: client => client.DedicatedHostGroups,
30+
getAsync: (o, p) => o.GetAsync(
31+
p.ResourceGroupName, p.Name, null, p.CancellationToken),
32+
createOrUpdateAsync: (o, p) => o.CreateOrUpdateAsync(
33+
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
34+
createTime: _ => 1);
35+
36+
public static ResourceConfig<DedicatedHostGroup> CreateDedicatedHostGroupConfig(
37+
this ResourceConfig<ResourceGroup> resourceGroup, string name)
38+
=> Strategy.CreateNoncreatableResourceConfig(resourceGroup: resourceGroup, name: name);
39+
40+
public static Func<IEngine, SubResource> CreateDedicatedHostGroupSubResourceFunc(
41+
this ResourceConfig<ResourceGroup> resourceGroup, string name)
42+
{
43+
if (name == null)
44+
{
45+
return _ => null;
46+
}
47+
var id = ResourceId.TryParse(name);
48+
if (id == null)
49+
{
50+
var ppConfig = resourceGroup.CreateDedicatedHostGroupConfig(name);
51+
return e => e.GetReference(ppConfig);
52+
}
53+
return _ => new SubResource(name);
54+
}
55+
}
56+
}

src/Compute/Compute/Strategies/ComputeRp/SubResourceStrategy.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public static SubResource GetReference(
3232
this IEngine engine, ResourceConfig<ProximityPlacementGroup> proximityPlacementGroup)
3333
=> engine.GetSubResourceReference(proximityPlacementGroup);
3434

35+
public static SubResource GetReference(
36+
this IEngine engine, ResourceConfig<DedicatedHostGroup> dedicatedHostGroup)
37+
=> engine.GetSubResourceReference(dedicatedHostGroup);
38+
3539
public static SubResource GetReference(
3640
this IEngine engine, ResourceConfig<N.NetworkSecurityGroup> networkSecurityGroup)
3741
=> engine.GetSubResourceReference(networkSecurityGroup);

src/Compute/Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ internal static ResourceConfig<VirtualMachineScaleSet> CreateVirtualMachineScale
5555
IList<string> zones,
5656
bool ultraSSDEnabled,
5757
Func<IEngine, SubResource> proximityPlacementGroup,
58+
Func<IEngine, SubResource> hostGroup,
5859
string priority,
5960
string evictionPolicy,
6061
double? maxPrice,
@@ -131,6 +132,7 @@ internal static ResourceConfig<VirtualMachineScaleSet> CreateVirtualMachineScale
131132
BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice)
132133
},
133134
ProximityPlacementGroup = proximityPlacementGroup(engine),
135+
HostGroup = hostGroup(engine),
134136
ScaleInPolicy = (scaleInPolicy == null) ? null : new ScaleInPolicy
135137
{
136138
Rules = scaleInPolicy

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Creates a host group.
1414

1515
```
1616
New-AzHostGroup [-ResourceGroupName] <String> [-Name] <String> [-Location] <String>
17-
-PlatformFaultDomain <Int32> [-Zone <String[]>] [-Tag <Hashtable>] [-AsJob]
17+
-PlatformFaultDomain <Int32> [-Zone <String[]>] [-SupportAutomaticPlacement <bool>] [-Tag <Hashtable>] [-AsJob]
1818
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
1919
```
2020

@@ -161,6 +161,23 @@ Accept pipeline input: False
161161
Accept wildcard characters: False
162162
```
163163
164+
### -SupportAutomaticPlacement
165+
If a dedicated host group has automatic placement enabled, VMs or VMScaleSets can be placed on the dedicated host group using automatic placement.
166+
Automatic placement means these VMs are placed on dedicated hosts, chosen by Azure, under the dedicated host group.
167+
168+
```yaml
169+
Type: bool
170+
Parameter Sets: (All)
171+
Aliases:
172+
173+
Required: False
174+
Position: Named
175+
Default value: None
176+
Accept pipeline input: False
177+
Accept wildcard characters: False
178+
```
179+
180+
164181
### -Confirm
165182
Prompts you for confirmation before running the cmdlet.
166183

0 commit comments

Comments
 (0)