Skip to content

Commit a238f79

Browse files
Sandidoisra-felwyunchi-ms
authored
Edited New-AzVm to ensure the PlatformFaultDomain parameter in the VmConfig object is used (#17859)
* dev and test * changelog * example * Update ChangeLog.md to avoid bad merge * Update New-AzVM.md format example Co-authored-by: Yeming Liu <11371776+isra-fel@users.noreply.github.com> Co-authored-by: Yunchi Wang <54880216+wyunchi-ms@users.noreply.github.com>
1 parent d9ba744 commit a238f79

File tree

6 files changed

+3636
-1
lines changed

6 files changed

+3636
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,5 +493,12 @@ public void TestGetVirtualMachineById()
493493
{
494494
TestRunner.RunTestScript("Test-GetVirtualMachineById");
495495
}
496+
497+
[Fact]
498+
[Trait(Category.AcceptanceType, Category.CheckIn)]
499+
public void TestVirtualMachinePlatformFaultDomain()
500+
{
501+
TestRunner.RunTestScript("Test-VirtualMachinePlatformFaultDomain");
502+
}
496503
}
497504
}

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5714,3 +5714,84 @@ function Test-GetVirtualMachineById
57145714
Clean-ResourceGroup $rgname;
57155715
}
57165716
}
5717+
5718+
<#
5719+
.SYNOPSIS
5720+
Test Test GetVirtualMachineById Parameter Set
5721+
#>
5722+
function Test-VirtualMachinePlatformFaultDomain
5723+
{
5724+
# Setup
5725+
$rgname = Get-ComputeTestResourceName;
5726+
$loc = Get-ComputeVMLocation;
5727+
5728+
try
5729+
{
5730+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
5731+
5732+
# VM Profile & Hardware
5733+
$vmname = 'vm' + $rgname;
5734+
$domainNameLabel = "d1" + $rgname;
5735+
5736+
$vnetname = "myVnet";
5737+
$vnetAddress = "10.0.0.0/16";
5738+
$subnetname = "slb" + $rgname;
5739+
$subnetAddress = "10.0.2.0/24";
5740+
$vmssName = "vmss" + $rgname;
5741+
$FaultDomainNumber = 2;
5742+
$vmssFaultDomain = 3;
5743+
5744+
$OSDiskName = $vmname + "-osdisk";
5745+
$NICName = $vmname+ "-nic";
5746+
$NSGName = $vmname + "-NSG";
5747+
$OSDiskSizeinGB = 128;
5748+
$VMSize = "Standard_DS2_v2";
5749+
$PublisherName = "MicrosoftWindowsServer";
5750+
$Offer = "WindowsServer";
5751+
$SKU = "2019-Datacenter";
5752+
5753+
5754+
5755+
# Creating a VM using Simple parameterset
5756+
$securePassword = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force;
5757+
$user = "admin01";
5758+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
5759+
5760+
$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name $subnetname -AddressPrefix $subnetAddress;
5761+
5762+
$vnet = New-AzVirtualNetwork -Name $vnetname -ResourceGroupName $rgname -Location $loc -AddressPrefix $vnetAddress -Subnet $frontendSubnet;
5763+
5764+
$vmssConfig = New-AzVmssConfig -Location $loc -PlatformFaultDomainCount $vmssFaultDomain;
5765+
$VMSS = New-AzVmss -ResourceGroupName $RGName -Name $VMSSName -VirtualMachineScaleSet $vmssConfig -Verbose;
5766+
5767+
$nsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name RDP -Protocol Tcp -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow;
5768+
$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $RGName -Location $loc -Name $NSGName -SecurityRules $nsgRuleRDP;
5769+
$nic = New-AzNetworkInterface -Name $NICName -ResourceGroupName $RGName -Location $loc -SubnetId $vnet.Subnets[0].Id -NetworkSecurityGroupId $nsg.Id -EnableAcceleratedNetworking;
5770+
5771+
# VM
5772+
$vmConfig = New-AzVMConfig -VMName $vmName -VMSize $VMSize -VmssId $VMSS.Id -PlatformFaultDomain $FaultDomainNumber ;
5773+
Set-AzVMOperatingSystem -VM $vmConfig -Windows -ComputerName $vmName -Credential $cred ;
5774+
Set-AzVMOSDisk -VM $vmConfig -StorageAccountType "Premium_LRS" -Caching ReadWrite -Name $OSDiskName -DiskSizeInGB $OSDiskSizeinGB -CreateOption FromImage ;
5775+
Set-AzVMSourceImage -VM $vmConfig -PublisherName $PublisherName -Offer $Offer -Skus $SKU -Version latest ;
5776+
Add-AzVMNetworkInterface -VM $vmConfig -Id $nic.Id;
5777+
5778+
New-AzVM -ResourceGroupName $RGName -Location $loc -VM $vmConfig ;
5779+
$vm = Get-AzVm -ResourceGroupName $rgname -Name $vmName;
5780+
5781+
Assert-AreEqual $vm.PlatformFaultDomain $FaultDomainNumber;
5782+
5783+
# Create VM using Default Parameter set
5784+
$domainNameLabel = "d1" + $rgname;
5785+
$vmnameDef = "defvm" + $rgname;
5786+
$platformFaultDomainVMDefaultSet = 2;
5787+
$vmDef = New-AzVM -ResourceGroupName $rgname -Name $vmname -Credential $cred -DomainNameLabel $domainNameLabel -PlatformFaultDomain $platformFaultDomainVMDefaultSet -VmssId $VMSS.Id;
5788+
5789+
Assert-AreEqual $vmDef.PlatformFaultDomain $platformFaultDomainVMDefaultSet;
5790+
5791+
}
5792+
finally
5793+
{
5794+
# Cleanup
5795+
Clean-ResourceGroup $rgname;
5796+
}
5797+
}

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

Lines changed: 3528 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+
* Edited `New-AzVm` cmdlet internal logic to use the `PlatformFaultDomain` value in the `PSVirtualMachine` object passed to it in the new virtual machine.
2324

2425
## Version 4.26.0
2526
* Added `-ImageReferenceId` parameter to following cmdlets: `New-AzVm`, `New-AzVmConfig`, `New-AzVmss`, `Set-AzVmssStorageProfile`

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,8 @@ public void DefaultExecuteCmdlet()
821821
BillingProfile = this.VM.BillingProfile,
822822
SecurityProfile = this.VM.SecurityProfile,
823823
CapacityReservation = this.VM.CapacityReservation,
824-
UserData = this.VM.UserData
824+
UserData = this.VM.UserData,
825+
PlatformFaultDomain = this.VM.PlatformFaultDomain
825826
};
826827

827828
Dictionary<string, List<string>> auxAuthHeader = null;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,23 @@ New-AzVm -ResourceGroupName ResourceGroup1 -Location SouthCentralUS -VM $Virtual
224224

225225
This example deploys a Windows VM from the marketplace in one resource group with an existing subnet in another resource group.
226226

227+
### Example 6: Creating a new VM as part of a VMSS with a PlatformFaultDomain value.
228+
```
229+
$resourceGroupName= <Resource Group Name>
230+
$domainNameLabel = <Domain Name Label Name>
231+
$vmname = "<Virtual Machine Name>
232+
$platformFaultDomainVMDefaultSet = 2
233+
$securePassword = <Password> | ConvertTo-SecureString -AsPlainText -Force
234+
$user = <Username>
235+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword)
236+
$vmssName = <Vmss Name>;
237+
238+
$vmssConfig = New-AzVmssConfig -Location $loc -PlatformFaultDomainCount $vmssFaultDomain;
239+
$vmss = New-AzVmss -ResourceGroupName $resourceGroupName -Name $vmssName -VirtualMachineScaleSet $vmssConfig;
240+
241+
$vm = New-AzVM -ResourceGroupName $resourceGroupName -Name $vmname -Credential $cred -DomainNameLabel $domainNameLabel -PlatformFaultDomain $platformFaultDomainVMDefaultSet -VmssId $vmss.Id
242+
```
243+
227244
## PARAMETERS
228245

229246
### -AddressPrefix

0 commit comments

Comments
 (0)