Skip to content

Commit c3b135a

Browse files
Sandidomadewithsmiles
authored andcommitted
New-AzVm cmdlet dev and test work (#12595)
* Update NewAzureVMCommand.cs * Update VirtualMachineStrategy.cs * Update PSVirtualMachine.cs * Update VirtualMachineTests.cs * Update VirtualMachineTests.ps1 * Update ChangeLog.md * Update VirtualMachineTests.ps1 * Update NewAzureVMCommand.cs * Update VirtualMachineTests.ps1
1 parent a6d6cfd commit c3b135a

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,5 +311,12 @@ public void TestSetAzVMOperatingSystemError()
311311
{
312312
TestRunner.RunTestScript("Test-SetAzVMOperatingSystemError");
313313
}
314+
315+
[Fact]
316+
[Trait(Category.AcceptanceType, Category.CheckIn)]
317+
public void TestHostGroupPropertySetOnVirtualMachine()
318+
{
319+
TestRunner.RunTestScript("Test-HostGroupPropertySetOnVirtualMachine");
320+
}
314321
}
315322
}

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,3 +4171,47 @@ function Test-SetAzVMOperatingSystemError
41714171
}
41724172
}
41734173

4174+
<#
4175+
.SYNOPSIS
4176+
Test HostGroup property is set on a VM correctly when HostGroup.Id is passed as a parameter.
4177+
#>
4178+
function Test-HostGroupPropertySetOnVirtualMachine
4179+
{
4180+
# Setup
4181+
$rgname = Get-ComputeTestResourceName
4182+
4183+
try
4184+
{
4185+
# Common
4186+
[string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
4187+
$loc = $loc.Replace(' ', '');
4188+
4189+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
4190+
4191+
# Create a VM first
4192+
$hostGroupName = $rgname + 'hostgroup'
4193+
$hostGroup = New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 2 -Zone "2";
4194+
4195+
$hostName = $rgname + 'host'
4196+
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku "ESv3-Type1" -PlatformFaultDomain 1;
4197+
4198+
# VM Profile & Hardware
4199+
$vmsize = 'Standard_E2s_v3';
4200+
$vmname0 = 'v' + $rgname;
4201+
4202+
# Creating a VM using simple parameter set
4203+
$username = "admin01"
4204+
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
4205+
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
4206+
4207+
$vm0 = New-AzVM -ResourceGroupName $rgname -Location $loc -Name $vmname0 -Credential $cred -Zone "2" -Size $vmsize -HostGroupId $hostGroup.Id;
4208+
4209+
Assert-AreEqual $hostGroup.Id $vm0.HostGroup.Id;
4210+
}
4211+
finally
4212+
{
4213+
# Cleanup
4214+
Clean-ResourceGroup $rgname
4215+
}
4216+
}
4217+

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* Added '-EncryptionAtHost' parameter to New-AzVm, New-AzVmss, New-AzVMConfig, New-AzVmssConfig, Update-AzVM, and Update-AzVmss
2424
* Added 'SecurityProfile' to Get-AzVM and Get-AzVmss return object
2525
* Added the '-InstanceView' switch as optional parameter to Get-AzHostGroup
26+
* Added the '-HostGroupId' parameter to New-AzVm.
2627

2728
## Version 4.2.1
2829
* Added warning when using `New-AzVmss` without "latest" image version

src/Compute/Compute/Models/PSVirtualMachine.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,8 @@ public string ResourceGroupName
124124

125125
// Gets or sets the Priority
126126
public string Priority { get; set; }
127+
128+
// Gets or sets the HostGroup
129+
public SubResource HostGroup { get; set; }
127130
}
128131
}

src/Compute/Compute/Strategies/ComputeRp/VirtualMachineStrategy.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
5353
bool ultraSSDEnabled,
5454
Func<IEngine, SubResource> proximityPlacementGroup,
5555
string hostId,
56+
string hostGroupId,
5657
string priority,
5758
string evictionPolicy,
5859
double? maxPrice,
@@ -94,6 +95,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
9495
AdditionalCapabilities = ultraSSDEnabled ? new AdditionalCapabilities(true) : null,
9596
ProximityPlacementGroup = proximityPlacementGroup(engine),
9697
Host = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostId),
98+
HostGroup = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostGroupId),
9799
Priority = priority,
98100
EvictionPolicy = evictionPolicy,
99101
BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice),
@@ -114,6 +116,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
114116
bool ultraSSDEnabled,
115117
Func<IEngine, SubResource> proximityPlacementGroup,
116118
string hostId,
119+
string hostGroupId,
117120
string priority,
118121
string evictionPolicy,
119122
double? maxPrice,
@@ -152,6 +155,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
152155
AdditionalCapabilities = ultraSSDEnabled ? new AdditionalCapabilities(true) : null,
153156
ProximityPlacementGroup = proximityPlacementGroup(engine),
154157
Host = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostId),
158+
HostGroup = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostGroupId),
155159
Priority = priority,
156160
EvictionPolicy = evictionPolicy,
157161
BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice),

src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ public class NewAzureVMCommand : VirtualMachineBaseCmdlet
259259
[Parameter(ParameterSetName = DiskFileParameterSet, Mandatory = false,
260260
HelpMessage = "EncryptionAtHost property can be used by user in the request to enable or disable the Host Encryption for the virtual machine. This will enable the encryption for all the disks including Resource/Temp disk at host itself.")]
261261
public SwitchParameter EncryptionAtHost { get; set; } = false;
262+
263+
[Parameter(ParameterSetName = SimpleParameterSet, Mandatory = false,
264+
HelpMessage = "The resource id of the dedicated host group, on which the customer wants their VM placed using automatic placement.",
265+
ValueFromPipelineByPropertyName = true)]
266+
[Parameter(ParameterSetName = DiskFileParameterSet, Mandatory = false,
267+
HelpMessage = "The resource id of the dedicated host group, on which the customer wants their VM placed using automatic placement.",
268+
ValueFromPipelineByPropertyName = true)]
269+
public string HostGroupId { get; set; }
262270

263271
public override void ExecuteCmdlet()
264272
{
@@ -392,6 +400,7 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
392400
identity: _cmdlet.GetVMIdentityFromArgs(),
393401
proximityPlacementGroup: ppgSubResourceFunc,
394402
hostId: _cmdlet.HostId,
403+
hostGroupId: _cmdlet.HostGroupId,
395404
priority: _cmdlet.Priority,
396405
evictionPolicy: _cmdlet.EvictionPolicy,
397406
maxPrice: _cmdlet.IsParameterBound(c => c.MaxPrice) ? _cmdlet.MaxPrice : (double?)null,
@@ -417,6 +426,7 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
417426
identity: _cmdlet.GetVMIdentityFromArgs(),
418427
proximityPlacementGroup: ppgSubResourceFunc,
419428
hostId: _cmdlet.HostId,
429+
hostGroupId: _cmdlet.HostGroupId,
420430
priority: _cmdlet.Priority,
421431
evictionPolicy: _cmdlet.EvictionPolicy,
422432
maxPrice: _cmdlet.IsParameterBound(c => c.MaxPrice) ? _cmdlet.MaxPrice : (double?)null,

0 commit comments

Comments
 (0)