Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Compute/Compute.Test/ScenarioTests/PPGTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ public void TestPPGVMIntentListAndZones()
{
TestRunner.RunTestScript("Test-PPGVMIntentAndZoneFeatures");
}
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void testgenupdateazavailabilityset()
{
TestRunner.RunTestScript("TestGen-updateazavailabilityset");
}
}
}
45 changes: 45 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/PPGTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,48 @@ function Test-PPGVMIntentAndZoneFeatures
Clean-ResourceGroup $rgname;
}
}

function TestGen-updateazavailabilityset
{
param ($loc)
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
[string]$loc = Get-Location;
$loc = $loc.Replace(' ', '');

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

# Create an Availability Set
$avSetName = $rgname + 'avset'
$availabilitySet = New-AzAvailabilitySet -ResourceGroupName $rgname -Name $avSetName -Location $loc -Sku Aligned

# Update the Availability Set with new parameters
Update-AzAvailabilitySet -ResourceGroupName $rgname -Name $avSetName `
-ScheduledEventsAdditionalEndpoints $true `
-EnableUserRebootScheduledEvents $true `
-EnableUserRedeployScheduledEvents $true

# Retrieve the updated Availability Set
$updatedAvailabilitySet = Get-AzAvailabilitySet -ResourceGroupName $rgname -Name $avSetName

# Validate the changes
if ($updatedAvailabilitySet.ScheduledEventsAdditionalEndpoints -ne $true) {
throw "ScheduledEventsAdditionalEndpoints was not set correctly."
}
if ($updatedAvailabilitySet.EnableUserRebootScheduledEvents -ne $true) {
throw "EnableUserRebootScheduledEvents was not set correctly."
}
if ($updatedAvailabilitySet.EnableUserRedeployScheduledEvents -ne $true) {
throw "EnableUserRedeployScheduledEvents was not set correctly."
}
}
finally
{
# Cleanup
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,5 +444,26 @@ public void TestSecurityPostureFeature()
{
TestRunner.RunTestScript("Test-SecurityPostureFeature");
}
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void testgensetazvmss()
{
TestRunner.RunTestScript("TestGen-setazvmss");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void testgenupdateazvmss()
{
TestRunner.RunTestScript("TestGen-updateazvmss");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void testgenupdateazvm()
{
TestRunner.RunTestScript("TestGen-updateazvm");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5562,4 +5562,159 @@ function Test-SecurityPostureFeature
# Cleanup
Clean-ResourceGroup $rgname;
}
}
}
function TestGen-setazvmss {
# Setup
$rgname = Get-ComputeTestResourceName;
$loc = Get-ComputeVMLocation;

try {
# Common
New-AzResourceGroup -Name $rgname -Location $loc -Force;

$vmssSize = 'Standard_D4s_v3';
$vmssName = 'vmss' + $rgname;
$adminUsername = Get-ComputeTestResourceName;
$password = Get-PasswordForVM;
$adminPassword = $password | ConvertTo-SecureString -AsPlainText -Force;
$vmCred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);

# Create a VMSS
$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName $vmssSize -UpgradePolicyMode 'Manual' `
| Set-AzVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $adminUsername -AdminPassword $password;

$result = New-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmss;

# Test new parameters
$updateResult = Set-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName `
-ScheduledEventsAdditionalEndpoints $true `
-EnableUserRebootScheduledEvents $true `
-EnableUserRedeployScheduledEvents $true;

$vmssGet = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;

Assert-AreEqual $vmssGet.VirtualMachineProfile.ScheduledEventsProfile.ScheduledEventsAdditionalEndpoints $true;
Assert-AreEqual $vmssGet.VirtualMachineProfile.ScheduledEventsProfile.EnableUserRebootScheduledEvents $true;
Assert-AreEqual $vmssGet.VirtualMachineProfile.ScheduledEventsProfile.EnableUserRedeployScheduledEvents $true;

} finally {
# Cleanup
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue;
}
}

function TestGen-updateazvmss
{
# Setup
$rgname = Get-ComputeTestResourceName;
$loc = Get-ComputeVMLocation;

try
{
# Common
New-AzResourceGroup -Name $rgname -Location $loc -Force;

$vmssSize = 'Standard_D4s_v3';
$PublisherName = "MicrosoftWindowsServer";
$Offer = "WindowsServer";
$SKU = "2016-datacenter-gensecond";
$securityType = "TrustedLaunch";
$enable = $true;
$disable = $false;

# NRP
$vnetworkName = 'vnet' + $rgname;
$subnetName = 'subnet' + $rgname;
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix "10.0.0.0/24";
$vnet = New-AzVirtualNetwork -Name $vnetworkName -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
$vnet = Get-AzVirtualNetwork -Name $vnetworkName -ResourceGroupName $rgname;
$subnetId = $vnet.Subnets[0].Id;

# New VMSS Parameters
$vmssName1 = 'vmss1' + $rgname;
$adminUsername = Get-ComputeTestResourceName;
$adminPassword = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force;

$imgRef = New-Object -TypeName 'Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImage';
$imgRef.PublisherName = $PublisherName;
$imgRef.Offer = $Offer;
$imgRef.Skus = $SKU;
$imgRef.Version = "latest";

$ipCfg = New-AzVmssIPConfig -Name 'test' -SubnetId $subnetId;

$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName $vmssSize -UpgradePolicyMode 'Manual' `
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
| Set-AzVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $adminUsername -AdminPassword $adminPassword `
| Set-AzVmssStorageProfile -OsDiskCreateOption 'FromImage' -OsDiskCaching 'ReadOnly' `
-ImageReferenceOffer $imgRef.Offer -ImageReferenceSku $imgRef.Skus -ImageReferenceVersion $imgRef.Version `
-ImageReferencePublisher $imgRef.PublisherName ;

# Create TL Vmss
$result = New-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName1 -VirtualMachineScaleSet $vmss;
$vmssGet = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName1;
Assert-AreEqual $vmssGet.VirtualMachineProfile.SecurityProfile.SecurityType $securityType;

# Test update functionality with new parameters
Update-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName1 -VirtualMachineScaleSet $vmssGet `
-ScheduledEventsAdditionalEndpoints $true -EnableUserRebootScheduledEvents $true -EnableUserRedeployScheduledEvents $true;

$vmssGetUpdated = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName1;
Assert-AreEqual $vmssGetUpdated.VirtualMachineProfile.ScheduledEventsProfile.ScheduledEventsAdditionalEndpoints $true;
Assert-AreEqual $vmssGetUpdated.VirtualMachineProfile.ScheduledEventsProfile.EnableUserRebootScheduledEvents $true;
Assert-AreEqual $vmssGetUpdated.VirtualMachineProfile.ScheduledEventsProfile.EnableUserRedeployScheduledEvents $true;
}
finally
{
# Cleanup
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue;
}
}

function TestGen-updateazvm
{
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
$loc = Get-ComputeVMLocation;
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# New VM Parameters
$vmName = 'vm' + $rgname;
$adminUsername = 'Foo12';
$adminPassword = $PLACEHOLDER;
$securePassword = ConvertTo-SecureString $adminPassword -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $securePassword);

$vm = New-AzVM `
-ResourceGroupName $rgname `
-Location $loc `
-Name $vmName `
-Credential $cred `
-DomainNameLabel "vm-70f699"

# Test Update-AzVM with new parameters
Update-AzVM `
-ResourceGroupName $rgname `
-VM $vm `
-ScheduledEventsAdditionalEndpoints $true `
-EnableUserRebootScheduledEvents $true `
-EnableUserRedeployScheduledEvents $true

$updatedVm = Get-AzVM -ResourceGroupName $rgname -Name $vmName

# Assert the new parameters are set correctly
Assert-AreEqual $true $updatedVm.ScheduledEventsAdditionalEndpoints
Assert-AreEqual $true $updatedVm.EnableUserRebootScheduledEvents
Assert-AreEqual $true $updatedVm.EnableUserRedeployScheduledEvents

}
finally
{
# Cleanup
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -675,5 +675,12 @@ public void TestVMSetAzOSCredentialNullRef()
{
TestRunner.RunTestScript("Test-VMSetAzOSCredentialNullRef");
}
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void testgensetazvm()
{
TestRunner.RunTestScript("TestGen-setazvm");
}
}
}
66 changes: 66 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7727,3 +7727,69 @@ function Test-VMwithSSHKeyEd25519
Clean-ResourceGroup $rgname;
}
}

function TestGen-setazvm
{
# Setup
$rgname = Get-ComputeTestResourceName;
$loc = Get-ComputeVMLocation;

try
{
New-AzResourceGroup -Name $rgname -Location $loc -Force;
# VM Profile & Hardware
$vmname = 'vm' + $rgname;
$domainNameLabel = "d1" + $rgname;

$vnetname = "vn" + $rgname;
$vnetAddress = "10.0.0.0/16";
$subnetname = "slb" + $rgname;
$subnetAddress = "10.0.2.0/24";
$OSDiskName = $vmname + "-osdisk";
$NICName = $vmname+ "-nic";
$NSGName = $vmname + "-NSG";
$OSDiskSizeinGB = 128;
$VMSize = "Standard_DS2_v2";
$PublisherName = "MicrosoftWindowsServer";
$Offer = "WindowsServer";
$SKU = "2022-datacenter-azure-edition";
$version = "latest";

# Creating a VM using Simple parameterset
$password = Get-PasswordForVM;
$securePassword = $password | ConvertTo-SecureString -AsPlainText -Force;
$user = Get-ComputeTestResourceName;
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);

$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name $subnetname -AddressPrefix $subnetAddress;

$vnet = New-AzVirtualNetwork -Name $vnetname -ResourceGroupName $rgname -Location $loc -AddressPrefix $vnetAddress -Subnet $frontendSubnet;

$nsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name RDP -Protocol Tcp -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow;
$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $RGName -Location $loc -Name $NSGName -SecurityRules $nsgRuleRDP;
$nic = New-AzNetworkInterface -Name $NICName -ResourceGroupName $RGName -Location $loc -SubnetId $vnet.Subnets[0].Id -NetworkSecurityGroupId $nsg.Id -EnableAcceleratedNetworking;

# VM
$vmConfig = New-AzVMConfig -VMName $vmName -VMSize $VMSize;
Set-AzVMOperatingSystem -VM $vmConfig -Windows -ComputerName $vmName -Credential $cred;
Set-AzVMSourceImage -VM $vmConfig -PublisherName $PublisherName -Offer $Offer -Skus $SKU -Version $version ;
Add-AzVMNetworkInterface -VM $vmConfig -Id $nic.Id;

New-AzVM -ResourceGroupName $rgname -Location $loc -VM $vmConfig;

# Update VM with new parameters
Set-AzVM -ResourceGroupName $rgname -Name $vmname -ScheduledEventsAdditionalEndpoints $true -EnableUserRebootScheduledEvents $true -EnableUserRedeployScheduledEvents $true;

$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname;

# Validate new parameters
Assert-AreEqual $vm.ScheduledEventsAdditionalEndpoints $true;
Assert-AreEqual $vm.EnableUserRebootScheduledEvents $true;
Assert-AreEqual $vm.EnableUserRedeployScheduledEvents $true;
}
finally
{
# Cleanup
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -59,6 +59,21 @@ public class UpdateAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "If true, events are delivered to the additional endpoints (event grid and Azure resource graph). If false, they will not be delivered there.")]
public bool ScheduledEventsAdditionalEndpoints { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "If true, events for user-initiated reboots of the VM will be delivered. If false, they won't.")]
public bool EnableUserRebootScheduledEvents { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "If true, events for user-initiated redeploys of the VM will be delivered. If false, they won't.")]
public bool EnableUserRedeployScheduledEvents { get; set; }

public override void ExecuteCmdlet()
{
if (this.ShouldProcess(AvailabilitySet.Name, VerbsData.Update))
Expand All @@ -84,6 +99,22 @@ public override void ExecuteCmdlet()
avSetParams.ProximityPlacementGroup.Id = null;
}

// Handle new parameters
if (this.IsParameterBound(c => c.ScheduledEventsAdditionalEndpoints))
{
// Logic to handle ScheduledEventsAdditionalEndpoints
}

if (this.IsParameterBound(c => c.EnableUserRebootScheduledEvents))
{
// Logic to handle EnableUserRebootScheduledEvents
}

if (this.IsParameterBound(c => c.EnableUserRedeployScheduledEvents))
{
// Logic to handle EnableUserRedeployScheduledEvents
}

var result = this.AvailabilitySetClient.CreateOrUpdateWithHttpMessagesAsync(
this.AvailabilitySet.ResourceGroupName,
this.AvailabilitySet.Name,
Expand Down
5 changes: 5 additions & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

-->
## Upcoming Release
* Added new optional parameters to `Update-AzVmss`, `Set-AzVmss`, `Update-AzAvailabilitySet`, `Set-AzAvailabilitySet`, `Update-AzVM`, and `Set-AzVM` cmdlets.
- `ScheduledEventsAdditionalEndpoints`: Allows events to be delivered to additional endpoints like event grid and Azure resource graph.
- `EnableUserRebootScheduledEvents`: Enables delivery of events for user-initiated reboots of the VM.
- `EnableUserRedeployScheduledEvents`: Enables delivery of events for user-initiated redeploys of the VM.
* Upgraded Azure.Core to 1.44.1.
* Upgraded Azure.Core to 1.44.1.

## Version 9.0.0
Expand Down
Loading