[Compute] Adding Scheduledevents to VM and VMSS#29123
Conversation
…zVM, and Update-AzVmss cmdlets - Introduced `-ScheduledEventsApiVersion` to specify the API version for Scheduled Events configuration. - Added `-EnableAllInstancesDown` to auto-approve Scheduled Events when all instances are down. - Updated related help documentation for cmdlets to reflect new parameters. - Enhanced handling of Scheduled Events policy in the cmdlet implementations.
… scheduledevents
| Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status. |
There was a problem hiding this comment.
Pull request overview
Adds Scheduled Events configuration support to Az.Compute VM/VMSS (and Availability Set) cmdlets by introducing two new parameters that populate ScheduledEventsPolicy in the corresponding ARM payloads.
Changes:
- Added
-ScheduledEventsApiVersionand-EnableAllInstancesDownparameters to VM/VMSS/Availability Set create/update cmdlets and wired them into request models. - Updated generated/help markdown to document the new parameters.
- Added new scenario tests (and one new recording) intended to validate the behavior.
Reviewed changes
Copilot reviewed 23 out of 25 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Compute/Compute/help/Update-AzVmss.md | Documents new Scheduled Events parameters for Update-AzVmss (and adds -ProgressAction entry). |
| src/Compute/Compute/help/Update-AzVM.md | Documents new Scheduled Events parameters for Update-AzVM (and adds -ProgressAction entry). |
| src/Compute/Compute/help/Update-AzAvailabilitySet.md | Documents new Scheduled Events parameters for Update-AzAvailabilitySet (and adds -ProgressAction entry). |
| src/Compute/Compute/help/New-AzVmss.md | Documents new Scheduled Events parameters for New-AzVmss and updates syntax block. |
| src/Compute/Compute/help/New-AzVM.md | Documents new Scheduled Events parameters for New-AzVM and updates syntax block. |
| src/Compute/Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs | Adds parameters and populates ScheduledEventsPolicy for VM update calls. |
| src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs | Adds parameters and passes Scheduled Events inputs through strategy-based VM creation; also forwards ScheduledEventsPolicy from PSVirtualMachine to the SDK model. |
| src/Compute/Compute/Strategies/ComputeRp/VirtualMachineStrategy.cs | Extends strategy VM config builder to construct ScheduledEventsPolicy during VM creation. |
| src/Compute/Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs | Extends strategy VMSS config builder to construct ScheduledEventsPolicy during VMSS creation. |
| src/Compute/Compute/Models/PSVirtualMachine.cs | Adds ScheduledEventsPolicy property to the PowerShell VM model. |
| src/Compute/Compute/Manual/VirtualMachineScaleSetCreateOrUpdateMethod.cs | Adds Scheduled Events parameters to VMSS create cmdlet path and passes them into strategy config. |
| src/Compute/Compute/Manual/PSVirtualMachineScaleSet.cs | Adds ScheduledEventsPolicy property to the PowerShell VMSS model. |
| src/Compute/Compute/Generated/VirtualMachineScaleSet/VirtualMachineScaleSetUpdateMethod.cs | Adds Scheduled Events parameters to Update-AzVmss and applies them only in PUT path (not PATCH). |
| src/Compute/Compute/ChangeLog.md | Adds an Upcoming Release note about the new parameters. |
| src/Compute/Compute/AvailabilitySets/UpdateAzureAvailabilitySetCommand.cs | Adds parameters and populates ScheduledEventsPolicy for availability set updates. |
| src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.AvailabilitySetTests/TestAvailabilitySetScheduledEventsPolicy.json | Adds a recording for the new availability set Scheduled Events scenario. |
| src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1 | Adds a VM Scheduled Events scenario test script. |
| src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs | Registers the new VM Scheduled Events scenario test for check-in runs. |
| src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1 | Adds a VMSS Scheduled Events scenario test script. |
| src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.cs | Registers the new VMSS Scheduled Events scenario test for check-in runs. |
| src/Compute/Compute.Test/ScenarioTests/StrategiesVirtualMachineTests.ps1 | Adds a strategy-based New-AzVM SimpleParameterSet Scheduled Events scenario test script. |
| src/Compute/Compute.Test/ScenarioTests/StrategiesVirtualMachineTests.cs | Registers the new strategy-based Scheduled Events scenario test for check-in runs. |
| src/Compute/Compute.Test/ScenarioTests/AvailabilitySetTests.ps1 | Adds an availability set Scheduled Events scenario test script. |
| src/Compute/Compute.Test/ScenarioTests/AvailabilitySetTests.cs | Registers the new availability set Scheduled Events scenario test for check-in runs. |
Comments suppressed due to low confidence (1)
src/Compute/Compute/help/New-AzVmss.md:651
- The -HighSpeedInterconnectPlacement parameter help no longer lists its accepted values (e.g., None/Trunk). Other cmdlets in this module include an "Accepted values:" line for constrained strings; please restore that here to avoid losing important guidance.
### -HighSpeedInterconnectPlacement
Specifies the high speed interconnect placement for the virtual machine scale set.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
</details>
| if (avSetParams.ScheduledEventsPolicy == null) | ||
| { | ||
| avSetParams.ScheduledEventsPolicy = new ScheduledEventsPolicy(); | ||
| } | ||
|
|
||
| if (this.IsParameterBound(c => c.ScheduledEventsApiVersion)) | ||
| { | ||
| if (avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets == null) | ||
| { | ||
| avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets = new ScheduledEventsAdditionalPublishingTargets(); | ||
| } | ||
| if (avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph == null) | ||
| { | ||
| avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph = new EventGridAndResourceGraph(); | ||
| } | ||
| avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion = this.ScheduledEventsApiVersion; | ||
| } | ||
|
|
||
| if (this.IsParameterBound(c => c.EnableAllInstancesDown)) | ||
| { | ||
| if (avSetParams.ScheduledEventsPolicy.AllInstancesDown == null) | ||
| { | ||
| avSetParams.ScheduledEventsPolicy.AllInstancesDown = new AllInstancesDown(); | ||
| } | ||
| avSetParams.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove = this.EnableAllInstancesDown; | ||
| } |
There was a problem hiding this comment.
This cmdlet now sends ScheduledEventsPolicy on Availability Set create/update, but the recorded service response shows ARM returning 400 InvalidParameter "Scheduled Event Policy is not supported". Exposing these parameters will cause user-facing failures and will also break the new scenario test. Please gate this feature to supported API/regions, or remove these parameters until Availability Sets support ScheduledEventsPolicy, and consider surfacing a clearer error message if unsupported.
| if (avSetParams.ScheduledEventsPolicy == null) | |
| { | |
| avSetParams.ScheduledEventsPolicy = new ScheduledEventsPolicy(); | |
| } | |
| if (this.IsParameterBound(c => c.ScheduledEventsApiVersion)) | |
| { | |
| if (avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets == null) | |
| { | |
| avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets = new ScheduledEventsAdditionalPublishingTargets(); | |
| } | |
| if (avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph == null) | |
| { | |
| avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph = new EventGridAndResourceGraph(); | |
| } | |
| avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion = this.ScheduledEventsApiVersion; | |
| } | |
| if (this.IsParameterBound(c => c.EnableAllInstancesDown)) | |
| { | |
| if (avSetParams.ScheduledEventsPolicy.AllInstancesDown == null) | |
| { | |
| avSetParams.ScheduledEventsPolicy.AllInstancesDown = new AllInstancesDown(); | |
| } | |
| avSetParams.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove = this.EnableAllInstancesDown; | |
| } | |
| throw new PSInvalidOperationException( | |
| "Scheduled Event Policy is not supported for Availability Sets in the current API or region. " + | |
| "Remove 'ScheduledEventsApiVersion' and 'EnableAllInstancesDown' parameters and try again."); |
| // To use ScheduledEventsApiVersion or EnableAllInstancesDown parameters, | ||
| // you must provide a VirtualMachineScaleSet object which will use the CreateOrUpdate path. |
There was a problem hiding this comment.
Update-AzVmss accepts -ScheduledEventsApiVersion/-EnableAllInstancesDown, but in the PATCH path (when -VirtualMachineScaleSet is not provided) these parameters are silently ignored because VirtualMachineScaleSetUpdate doesn’t support ScheduledEventsPolicy. Please enforce this at runtime (e.g., throw a terminating error if either parameter is bound while VirtualMachineScaleSet is null) or otherwise ensure the parameters have effect.
| // To use ScheduledEventsApiVersion or EnableAllInstancesDown parameters, | |
| // you must provide a VirtualMachineScaleSet object which will use the CreateOrUpdate path. | |
| // When using the PATCH path (VirtualMachineScaleSet is null), ScheduledEventsApiVersion and | |
| // EnableAllInstancesDown parameters are not applied and are therefore rejected at runtime. | |
| if (this.VirtualMachineScaleSet == null && | |
| (this.IsParameterBound(c => c.ScheduledEventsApiVersion) || | |
| this.IsParameterBound(c => c.EnableAllInstancesDown))) | |
| { | |
| throw new PSArgumentException("ScheduledEventsApiVersion and EnableAllInstancesDown parameters are only supported when updating a Virtual Machine Scale Set using the CreateOrUpdate path. Provide a VirtualMachineScaleSet object or remove these parameters."); | |
| } |
| $asetUpdated = $aset | Update-AzAvailabilitySet ` | ||
| -ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true; | ||
|
|
||
| # Verify the properties are set | ||
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy; | ||
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets; | ||
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph; | ||
| Assert-AreEqual $apiVersion $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion; | ||
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy.AllInstancesDown; | ||
| Assert-AreEqual $true $asetUpdated.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove; |
There was a problem hiding this comment.
This scenario test asserts ScheduledEventsPolicy is set on the updated availability set, but the added session recording shows the update request fails with 400 "Scheduled Event Policy is not supported". Either the cmdlet behavior/feature gating needs to change, or this test should be updated to validate the expected failure instead of asserting success.
| $asetUpdated = $aset | Update-AzAvailabilitySet ` | |
| -ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true; | |
| # Verify the properties are set | |
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy; | |
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets; | |
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph; | |
| Assert-AreEqual $apiVersion $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion; | |
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy.AllInstancesDown; | |
| Assert-AreEqual $true $asetUpdated.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove; | |
| # The service currently does not support Scheduled Event Policy on availability sets | |
| # and returns HTTP 400 "Scheduled Event Policy is not supported". | |
| # Validate that the cmdlet surfaces this failure instead of assuming success. | |
| Assert-ThrowsContains { | |
| $null = $aset | Update-AzAvailabilitySet ` | |
| -ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true; | |
| } "Scheduled Event Policy is not supported"; |
| [Fact] | ||
| [Trait(Category.AcceptanceType, Category.CheckIn)] | ||
| public void TestVirtualMachineScheduledEventsPolicy() | ||
| { | ||
| TestRunner.RunTestScript("Test-VirtualMachineScheduledEventsPolicy 'eastus2euap'"); | ||
| } |
There was a problem hiding this comment.
This new [CheckIn] scenario test will require a corresponding session record under Compute.Test/SessionRecords for playback runs. Please add the recorded HTTP session (or mark the test LiveOnly if it cannot be reliably recorded).
| ``` | ||
|
|
||
| ### -ProgressAction | ||
| {{ Fill ProgressAction Description }} |
There was a problem hiding this comment.
The generated help still contains the placeholder text "{{ Fill ProgressAction Description }}" for -ProgressAction. Please replace it with a real description (or regenerate help so it’s populated) before merging, since this renders the published reference help incomplete.
| {{ Fill ProgressAction Description }} | |
| Specifies how this cmdlet reports progress updates. Use `SilentlyContinue` to suppress progress output. |
| [Fact] | ||
| [Trait(Category.AcceptanceType, Category.CheckIn)] | ||
| public void TestVirtualMachineScaleSetScheduledEventsPolicy() | ||
| { | ||
| TestRunner.RunTestScript("Test-VirtualMachineScaleSetScheduledEventsPolicy 'eastus2euap'"); | ||
| } |
There was a problem hiding this comment.
This new [CheckIn] scenario test will require a corresponding session record under Compute.Test/SessionRecords for playback runs. Please add the recorded HTTP session (or mark the test LiveOnly if it cannot be reliably recorded).
| [Fact] | ||
| [Trait(Category.AcceptanceType, Category.CheckIn)] | ||
| public void TestSimpleNewVmScheduledEventsPolicy() | ||
| { | ||
| TestRunner.RunTestScript("Test-SimpleNewVmScheduledEventsPolicy"); | ||
| } |
There was a problem hiding this comment.
This new [CheckIn] scenario test will require a corresponding session record under Compute.Test/SessionRecords for playback runs. Please add the recorded HTTP session (or mark the test LiveOnly if it cannot be reliably recorded).
| ``` | ||
|
|
||
| ### -ProgressAction | ||
| {{ Fill ProgressAction Description }} |
There was a problem hiding this comment.
The generated help still contains the placeholder text "{{ Fill ProgressAction Description }}" for -ProgressAction. Please replace it with a real description (or regenerate help so it’s populated) before merging, since this renders the published reference help incomplete.
| {{ Fill ProgressAction Description }} | |
| Specifies how the cmdlet responds to progress updates, such as whether to display or silently ignore progress information. |
| ``` | ||
|
|
||
| ### -ProgressAction | ||
| {{ Fill ProgressAction Description }} |
There was a problem hiding this comment.
The generated help still contains the placeholder text "{{ Fill ProgressAction Description }}" for -ProgressAction. Please replace it with a real description (or regenerate help so it’s populated) before merging, since this renders the published reference help incomplete.
| {{ Fill ProgressAction Description }} | |
| Specifies how PowerShell responds to progress updates for this cmdlet, such as displaying or silently ignoring progress. |
| ``` | ||
|
|
||
| ### -ProgressAction | ||
| {{ Fill ProgressAction Description }} |
There was a problem hiding this comment.
The generated help still contains the placeholder text "{{ Fill ProgressAction Description }}" for -ProgressAction. Please replace it with a real description (or regenerate help so it’s populated) before merging, since this renders the published reference help incomplete.
| {{ Fill ProgressAction Description }} | |
| Specifies how PowerShell displays and handles progress updates for the operation, such as Continue, SilentlyContinue, or Stop. |
| ``` | ||
|
|
||
| ### -ProgressAction | ||
| {{ Fill ProgressAction Description }} |
There was a problem hiding this comment.
-ProgressAction has placeholder help text ({{ Fill ProgressAction Description }}) in the generated help. Please replace with standard common-parameter wording (or regenerate help to populate it).
| {{ Fill ProgressAction Description }} | |
| Specifies how PowerShell responds to progress updates for the cmdlet. |
| public bool? EnableAllInstancesDown { get; set; } | ||
|
|
||
| private void BuildPatchObject() | ||
| { |
There was a problem hiding this comment.
Update-AzVmss exposes -ScheduledEventsApiVersion / -EnableAllInstancesDown, but in the default (patch) path (VirtualMachineScaleSet == null) BuildPatchObject() does not apply them and may leave VirtualMachineScaleSetUpdate null. If a user specifies only these new parameters, the cmdlet can fall through to CreateOrUpdate(...) with an empty VirtualMachineScaleSet payload (AutoMapper maps from null), which risks overwriting the VMSS configuration. Add explicit handling: either (1) force the PUT path by loading the current VMSS and applying ScheduledEventsPolicy, (2) restrict these parameters to the PUT parameter set (require -VirtualMachineScaleSet input), or (3) throw a terminating error when these parameters are used without a VMSS object.
| { | |
| { | |
| // The ScheduledEvents parameters are only safely supported when a full | |
| // VirtualMachineScaleSet object is provided (PUT path). When the cmdlet is | |
| // invoked on the default (patch) path with these parameters and without a | |
| // VirtualMachineScaleSet object, there is a risk of sending an unintended | |
| // empty VMSS payload. To prevent this, we explicitly disallow that | |
| // combination of inputs. | |
| if (this.VirtualMachineScaleSet == null && | |
| (this.IsParameterBound(c => c.ScheduledEventsApiVersion) || | |
| this.IsParameterBound(c => c.EnableAllInstancesDown))) | |
| { | |
| throw new PSInvalidOperationException( | |
| "The ScheduledEventsApiVersion and EnableAllInstancesDown parameters can only be used when a VirtualMachineScaleSet object is supplied. Use 'Get-AzVmss' to retrieve the scale set and pipe it to 'Update-AzVmss' when configuring Scheduled Events."); | |
| } |
| # Update with ScheduledEventsPolicy | ||
| $apiVersion = "2020-07-01"; | ||
| $asetUpdated = $aset | Update-AzAvailabilitySet ` | ||
| -ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true; | ||
|
|
||
| # Verify the properties are set | ||
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy; | ||
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets; | ||
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph; | ||
| Assert-AreEqual $apiVersion $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion; | ||
| Assert-NotNull $asetUpdated.ScheduledEventsPolicy.AllInstancesDown; | ||
| Assert-AreEqual $true $asetUpdated.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove; | ||
| } |
There was a problem hiding this comment.
This new test asserts that updating an availability set with ScheduledEventsPolicy succeeds, but the committed session record for this test includes a 400 response ("Scheduled Event Policy is not supported"). In playback, the cmdlet will throw and these assertions will fail. Update the recording to a region/API where the feature is supported, or change the test to expect/handle the unsupported response (and align the session record accordingly).
Description
https://github.com/Azure/azure-powershell-cmdlet-review-pr/issues/1511
Mandatory Checklist
Please choose the target release of Azure PowerShell. (⚠️ Target release is a different concept from API readiness. Please click below links for details.)
Check this box to confirm: I have read the Submitting Changes section of
CONTRIBUTING.mdand reviewed the following information:ChangeLog.mdfile(s) appropriatelysrc/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.## Upcoming Releaseheader in the past tense.ChangeLog.mdif no new release is required, such as fixing test case only.