diff --git a/src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.cs b/src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.cs index dcda2e463a44..e2aafd60716e 100644 --- a/src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.cs +++ b/src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.cs @@ -137,5 +137,26 @@ public void SimpleNewVmssSkipExtOverprovision() { TestRunner.RunTestScript("Test-SimpleNewVmssSkipExtOverprovision"); } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void TestVmssLifecycleHookConfig() + { + TestRunner.RunTestScript("Test-VmssLifecycleHookConfig"); + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void TestSetVmssLifecycleHooksProfile() + { + TestRunner.RunTestScript("Test-SetVmssLifecycleHooksProfile"); + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void TestNewVmssConfigWithLifecycleHooksProfile() + { + TestRunner.RunTestScript("Test-NewVmssConfigWithLifecycleHooksProfile"); + } } } diff --git a/src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.ps1 b/src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.ps1 index 459adf55c85a..0c1a12c28ab6 100644 --- a/src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.ps1 +++ b/src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.ps1 @@ -551,3 +551,74 @@ function Test-SimpleNewVmssSkipExtOverprovision Clean-ResourceGroup $vmssname } } + +<# +.SYNOPSIS +Test New-AzVmssLifecycleHookConfig creates an in-memory lifecycle hook config object. +#> +function Test-VmssLifecycleHookConfig +{ + # Test creating a lifecycle hook config object in memory (no Azure calls needed) + $hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' -WaitDuration 'PT8H' + Assert-NotNull $hook + Assert-AreEqual 'UpgradeAutoOSScheduling' $hook.Type + Assert-AreEqual ([System.TimeSpan]::FromHours(8)) $hook.WaitDuration + Assert-AreEqual 'Approve' $hook.DefaultAction + + # With explicit default action + $hook2 = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSRollingBatchStarting' -WaitDuration 'PT30M' -DefaultAction 'Approve' + Assert-NotNull $hook2 + Assert-AreEqual 'UpgradeAutoOSRollingBatchStarting' $hook2.Type + Assert-AreEqual ([System.TimeSpan]::FromMinutes(30)) $hook2.WaitDuration + Assert-AreEqual 'Approve' $hook2.DefaultAction + + # Without wait duration + $hook3 = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' + Assert-NotNull $hook3 + Assert-Null $hook3.WaitDuration + Assert-AreEqual 'Approve' $hook3.DefaultAction +} + +<# +.SYNOPSIS +Test Set-AzVmssLifecycleHooksProfile attaches hooks to a VMSS config object. +#> +function Test-SetVmssLifecycleHooksProfile +{ + # Test attaching lifecycle hooks to an in-memory VMSS config (no Azure calls) + $hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' -WaitDuration 'PT8H' + $config = New-AzVmssConfig -Location 'eastus' -SkuCapacity 2 + + $config = Set-AzVmssLifecycleHooksProfile -VirtualMachineScaleSet $config -LifecycleHook $hook + + Assert-NotNull $config + Assert-NotNull $config.LifecycleHooksProfile + Assert-AreEqual 1 $config.LifecycleHooksProfile.LifecycleHooks.Count + Assert-AreEqual 'UpgradeAutoOSScheduling' $config.LifecycleHooksProfile.LifecycleHooks[0].Type + + # Test with multiple hooks + $hook2 = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSRollingBatchStarting' -WaitDuration 'PT30M' + $config = Set-AzVmssLifecycleHooksProfile -VirtualMachineScaleSet $config -LifecycleHook @($hook, $hook2) + + Assert-AreEqual 2 $config.LifecycleHooksProfile.LifecycleHooks.Count +} + +<# +.SYNOPSIS +Test New-AzVmssConfig with -LifecycleHooksProfile parameter. +#> +function Test-NewVmssConfigWithLifecycleHooksProfile +{ + # Test creating VMSS config with inline LifecycleHooksProfile + $hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' -WaitDuration 'PT8H' + $profile = [Microsoft.Azure.Management.Compute.Models.LifecycleHooksProfile]::new() + $profile.LifecycleHooks = [System.Collections.Generic.List[Microsoft.Azure.Management.Compute.Models.LifecycleHook]]::new() + $profile.LifecycleHooks.Add($hook) + + $config = New-AzVmssConfig -Location 'eastus' -SkuCapacity 2 -LifecycleHooksProfile $profile + + Assert-NotNull $config + Assert-NotNull $config.LifecycleHooksProfile + Assert-AreEqual 1 $config.LifecycleHooksProfile.LifecycleHooks.Count + Assert-AreEqual 'UpgradeAutoOSScheduling' $config.LifecycleHooksProfile.LifecycleHooks[0].Type +} diff --git a/src/Compute/Compute/ChangeLog.md b/src/Compute/Compute/ChangeLog.md index 3bb508e2d344..448ee537c027 100644 --- a/src/Compute/Compute/ChangeLog.md +++ b/src/Compute/Compute/ChangeLog.md @@ -20,6 +20,14 @@ --> ## Upcoming Release +* Added VMSS (Virtual Machine Scale Set) Lifecycle Hooks support (public preview) + - Added `New-AzVmssLifecycleHookConfig` cmdlet to create an in-memory lifecycle hook configuration object + - Added `Set-AzVmssLifecycleHooksProfile` cmdlet to attach lifecycle hooks to a VMSS configuration or live VMSS object + - Added `Remove-AzVmssLifecycleHook` cmdlet to remove one hook by `-Type` or all hooks with `-All` from a live VMSS + - Added `Get-AzVmssLifecycleHookEvent` cmdlet to list or retrieve lifecycle hook events for a VMSS + - Added `Update-AzVmssLifecycleHookEvent` cmdlet to respond to a lifecycle hook event (approve, reject, or delay) with optional per-VM instance filtering via `-InstanceId` + - Added `-LifecycleHooksProfile` parameter to `New-AzVmssConfig` to support inline lifecycle hooks profile construction + - Note: `-DefaultAction Reject` and `-ActionState Rejected` return a server error during preview; no client change is needed at GA * Added `-InstantAccess` parameter to `New-AzRestorePointCollection` cmdlet to enable instant access snapshots for restore points on Premium SSD v2 and Ultra disks * Added `-InstantAccess` parameter to `Update-AzRestorePointCollection` cmdlet to enable or disable instant access on an existing restore point collection * Added `-InstantAccessDurationInMinutes` parameter to `New-AzRestorePoint` cmdlet to specify the duration (1-300 minutes) for which the instant access snapshot is retained diff --git a/src/Compute/Compute/Generated/ComputeAutomationBaseCmdlet.cs b/src/Compute/Compute/Generated/ComputeAutomationBaseCmdlet.cs index b2c754538dac..e63124375cb0 100644 --- a/src/Compute/Compute/Generated/ComputeAutomationBaseCmdlet.cs +++ b/src/Compute/Compute/Generated/ComputeAutomationBaseCmdlet.cs @@ -295,6 +295,14 @@ public IVirtualMachineScaleSetVMRunCommandsOperations VirtualMachineScaleSetVMRu } } + public IVirtualMachineScaleSetLifeCycleHookEventsOperations VirtualMachineScaleSetLifeCycleHookEventsClient + { + get + { + return ComputeClient.ComputeManagementClient.VirtualMachineScaleSetLifeCycleHookEvents; + } + } + public IVirtualMachinesOperations VirtualMachinesClient { get diff --git a/src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssConfigCommand.cs b/src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssConfigCommand.cs index 276b3987ed5b..5608daec6efa 100644 --- a/src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssConfigCommand.cs +++ b/src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssConfigCommand.cs @@ -450,6 +450,12 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso [PSArgumentCompleter("None", "Trunk")] public string HighSpeedInterconnectPlacement { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Specifies the lifecycle hooks profile for the virtual machine scale set. Use Set-AzVmssLifecycleHooksProfile or create a LifecycleHooksProfile object directly.")] + public LifecycleHooksProfile LifecycleHooksProfile { get; set; } + protected override void ProcessRecord() { if (ShouldProcess("VirtualMachineScaleSet", "New")) @@ -1256,7 +1262,8 @@ private void Run() SkuProfile = vSkuProfile, ResiliencyPolicy = vResiliencyPolicy, Placement = vPlacement, - HighSpeedInterconnectPlacement = this.IsParameterBound(c => c.HighSpeedInterconnectPlacement) ? this.HighSpeedInterconnectPlacement : null + HighSpeedInterconnectPlacement = this.IsParameterBound(c => c.HighSpeedInterconnectPlacement) ? this.HighSpeedInterconnectPlacement : null, + LifecycleHooksProfile = this.IsParameterBound(c => c.LifecycleHooksProfile) ? this.LifecycleHooksProfile : null }; WriteObject(vVirtualMachineScaleSet); diff --git a/src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssLifecycleHookConfigCommand.cs b/src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssLifecycleHookConfigCommand.cs new file mode 100644 index 000000000000..abcda43a61dd --- /dev/null +++ b/src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssLifecycleHookConfigCommand.cs @@ -0,0 +1,75 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Management.Automation; +using System.Xml; +using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; +using Microsoft.Azure.Management.Compute.Models; + +namespace Microsoft.Azure.Commands.Compute.Automation +{ + [Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssLifecycleHookConfig", SupportsShouldProcess = true)] + [OutputType(typeof(LifecycleHook))] + public class NewAzureRmVmssLifecycleHookConfigCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + private const string DefaultDefaultAction = "Approve"; + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Specifies the type of the lifecycle hook. Possible values: 'UpgradeAutoOSScheduling', 'UpgradeAutoOSRollingBatchStarting'.")] + [PSArgumentCompleter("UpgradeAutoOSScheduling", "UpgradeAutoOSRollingBatchStarting")] + [ValidateNotNullOrEmpty] + public string Type { get; set; } + + [Parameter( + Mandatory = false, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Specifies the time duration the lifecycle hook event waits for a customer response before applying the default action. Must be in ISO 8601 duration format, for example 'PT8H' (8 hours) or 'PT30M' (30 minutes).")] + public string WaitDuration { get; set; } + + [Parameter( + Mandatory = false, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Specifies the default action applied when the wait duration expires with no customer response. Accepted values: 'Approve' (default), 'Reject'. Note: 'Reject' returns a server error during preview.")] + [PSArgumentCompleter("Approve", "Reject")] + [ValidateSet("Approve", "Reject")] + public string DefaultAction { get; set; } + + protected override void ProcessRecord() + { + if (ShouldProcess("VmssLifecycleHookConfig", "New")) + { + TimeSpan? waitDuration = null; + if (!string.IsNullOrEmpty(this.WaitDuration)) + { + waitDuration = XmlConvert.ToTimeSpan(this.WaitDuration); + } + + var hook = new LifecycleHook + { + Type = this.Type, + WaitDuration = waitDuration, + DefaultAction = string.IsNullOrEmpty(this.DefaultAction) ? DefaultDefaultAction : this.DefaultAction + }; + + WriteObject(hook); + } + } + } +} diff --git a/src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/SetAzureRmVmssLifecycleHooksProfileCommand.cs b/src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/SetAzureRmVmssLifecycleHooksProfileCommand.cs new file mode 100644 index 000000000000..34ba11a53964 --- /dev/null +++ b/src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/SetAzureRmVmssLifecycleHooksProfileCommand.cs @@ -0,0 +1,57 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using Microsoft.Azure.Commands.Compute.Automation.Models; +using Microsoft.Azure.Management.Compute.Models; + +namespace Microsoft.Azure.Commands.Compute.Automation +{ + [Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssLifecycleHooksProfile", SupportsShouldProcess = true)] + [OutputType(typeof(PSVirtualMachineScaleSet))] + public class SetAzureRmVmssLifecycleHooksProfileCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet + { + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The VMSS configuration object (PSVirtualMachineScaleSet) to update. Can be an in-memory config or a live VMSS object retrieved with Get-AzVmss.")] + [ValidateNotNull] + public PSVirtualMachineScaleSet VirtualMachineScaleSet { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + HelpMessage = "One or more lifecycle hook objects to attach to the VMSS. Use New-AzVmssLifecycleHookConfig to create hook objects.")] + [ValidateNotNull] + public LifecycleHook[] LifecycleHook { get; set; } + + protected override void ProcessRecord() + { + if (ShouldProcess(this.VirtualMachineScaleSet?.Name ?? "VirtualMachineScaleSet", "Set-AzVmssLifecycleHooksProfile")) + { + this.VirtualMachineScaleSet.LifecycleHooksProfile = new LifecycleHooksProfile + { + LifecycleHooks = this.LifecycleHook.ToList() + }; + + WriteObject(this.VirtualMachineScaleSet); + } + } + } +} diff --git a/src/Compute/Compute/Generated/VirtualMachineScaleSet/GetAzureRmVmssLifecycleHookEventCommand.cs b/src/Compute/Compute/Generated/VirtualMachineScaleSet/GetAzureRmVmssLifecycleHookEventCommand.cs new file mode 100644 index 000000000000..98ccb30ece61 --- /dev/null +++ b/src/Compute/Compute/Generated/VirtualMachineScaleSet/GetAzureRmVmssLifecycleHookEventCommand.cs @@ -0,0 +1,107 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; + +namespace Microsoft.Azure.Commands.Compute.Automation +{ + [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssLifecycleHookEvent", DefaultParameterSetName = ListParameterSet)] + [OutputType(typeof(VMScaleSetLifecycleHookEvent))] + public class GetAzureRmVmssLifecycleHookEventCommand : ComputeAutomationBaseCmdlet + { + private const string ListParameterSet = "ListParameterSet"; + private const string GetParameterSet = "GetParameterSet"; + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + ParameterSetName = ListParameterSet, + HelpMessage = "The name of the resource group.")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + ParameterSetName = GetParameterSet, + HelpMessage = "The name of the resource group.")] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + ParameterSetName = ListParameterSet, + HelpMessage = "The name of the VM scale set.")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + ParameterSetName = GetParameterSet, + HelpMessage = "The name of the VM scale set.")] + [ResourceNameCompleter("Microsoft.Compute/virtualMachineScaleSets", "ResourceGroupName")] + [ValidateNotNullOrEmpty] + [Alias("VMScaleSetName")] + public string VMScaleSetName { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + ParameterSetName = GetParameterSet, + HelpMessage = "The name (GUID) of the lifecycle hook event to retrieve.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + public override void ExecuteCmdlet() + { + base.ExecuteCmdlet(); + ExecuteClientAction(() => + { + if (this.ParameterSetName.Equals(GetParameterSet)) + { + var result = VirtualMachineScaleSetLifeCycleHookEventsClient.Get( + this.ResourceGroupName, + this.VMScaleSetName, + this.Name); + WriteObject(result); + } + else + { + var result = VirtualMachineScaleSetLifeCycleHookEventsClient.List( + this.ResourceGroupName, + this.VMScaleSetName); + var resultList = result.ToList(); + var nextPageLink = result.NextPageLink; + while (!string.IsNullOrEmpty(nextPageLink)) + { + var pageResult = VirtualMachineScaleSetLifeCycleHookEventsClient.ListNext(nextPageLink); + foreach (var pageItem in pageResult) + { + resultList.Add(pageItem); + } + nextPageLink = pageResult.NextPageLink; + } + WriteObject(resultList, true); + } + }); + } + } +} diff --git a/src/Compute/Compute/Generated/VirtualMachineScaleSet/RemoveAzureRmVmssLifecycleHookCommand.cs b/src/Compute/Compute/Generated/VirtualMachineScaleSet/RemoveAzureRmVmssLifecycleHookCommand.cs new file mode 100644 index 000000000000..3eb2d44353be --- /dev/null +++ b/src/Compute/Compute/Generated/VirtualMachineScaleSet/RemoveAzureRmVmssLifecycleHookCommand.cs @@ -0,0 +1,132 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using Microsoft.Azure.Commands.Compute.Automation.Models; +using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; + +namespace Microsoft.Azure.Commands.Compute.Automation +{ + [Cmdlet(VerbsCommon.Remove, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssLifecycleHook", SupportsShouldProcess = true, DefaultParameterSetName = ByTypeParameterSet)] + [OutputType(typeof(PSVirtualMachineScaleSet))] + public class RemoveAzureRmVmssLifecycleHookCommand : ComputeAutomationBaseCmdlet + { + private const string ByTypeParameterSet = "ByTypeParameterSet"; + private const string AllParameterSet = "AllParameterSet"; + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + ParameterSetName = ByTypeParameterSet, + HelpMessage = "The name of the resource group.")] + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + ParameterSetName = AllParameterSet, + HelpMessage = "The name of the resource group.")] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + ParameterSetName = ByTypeParameterSet, + HelpMessage = "The name of the VM scale set.")] + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + ParameterSetName = AllParameterSet, + HelpMessage = "The name of the VM scale set.")] + [ResourceNameCompleter("Microsoft.Compute/virtualMachineScaleSets", "ResourceGroupName")] + [ValidateNotNullOrEmpty] + [Alias("Name")] + public string VMScaleSetName { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + ParameterSetName = ByTypeParameterSet, + HelpMessage = "The lifecycle hook type to remove. Possible values: 'UpgradeAutoOSScheduling', 'UpgradeAutoOSRollingBatchStarting'.")] + [PSArgumentCompleter("UpgradeAutoOSScheduling", "UpgradeAutoOSRollingBatchStarting")] + [ValidateNotNullOrEmpty] + public string Type { get; set; } + + [Parameter( + Mandatory = true, + ParameterSetName = AllParameterSet, + HelpMessage = "When specified, removes all lifecycle hooks from the virtual machine scale set.")] + public SwitchParameter All { get; set; } + + [Parameter( + Mandatory = false, + HelpMessage = "Run cmdlet in the background.")] + public SwitchParameter AsJob { get; set; } + + public override void ExecuteCmdlet() + { + base.ExecuteCmdlet(); + ExecuteClientAction(() => + { + if (ShouldProcess(this.VMScaleSetName, "Remove-AzVmssLifecycleHook")) + { + var vmss = VirtualMachineScaleSetsClient.Get(this.ResourceGroupName, this.VMScaleSetName); + var psObject = new PSVirtualMachineScaleSet(); + ComputeAutomationAutoMapperProfile.Mapper.Map(vmss, psObject); + + if (this.ParameterSetName.Equals(AllParameterSet)) + { + psObject.LifecycleHooksProfile = null; + } + else + { + // Remove by type + if (psObject.LifecycleHooksProfile?.LifecycleHooks != null) + { + var remaining = psObject.LifecycleHooksProfile.LifecycleHooks + .Where(h => !string.Equals(h.Type, this.Type, System.StringComparison.OrdinalIgnoreCase)) + .ToList(); + + if (remaining.Count == 0) + { + psObject.LifecycleHooksProfile = null; + } + else + { + psObject.LifecycleHooksProfile = new LifecycleHooksProfile { LifecycleHooks = remaining }; + } + } + } + + var parameters = new VirtualMachineScaleSet(); + ComputeAutomationAutoMapperProfile.Mapper.Map(psObject, parameters); + + var result = VirtualMachineScaleSetsClient.CreateOrUpdate(this.ResourceGroupName, this.VMScaleSetName, parameters); + var resultPsObject = new PSVirtualMachineScaleSet(); + ComputeAutomationAutoMapperProfile.Mapper.Map(result, resultPsObject); + WriteObject(resultPsObject); + } + }); + } + } +} diff --git a/src/Compute/Compute/Generated/VirtualMachineScaleSet/UpdateAzureRmVmssLifecycleHookEventCommand.cs b/src/Compute/Compute/Generated/VirtualMachineScaleSet/UpdateAzureRmVmssLifecycleHookEventCommand.cs new file mode 100644 index 000000000000..8b7ace614756 --- /dev/null +++ b/src/Compute/Compute/Generated/VirtualMachineScaleSet/UpdateAzureRmVmssLifecycleHookEventCommand.cs @@ -0,0 +1,212 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; +using Microsoft.Azure.Management.Compute; +using Microsoft.Azure.Management.Compute.Models; + +namespace Microsoft.Azure.Commands.Compute.Automation +{ + [Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssLifecycleHookEvent", + SupportsShouldProcess = true, DefaultParameterSetName = ByNameParameterSet)] + [OutputType(typeof(VMScaleSetLifecycleHookEvent))] + public class UpdateAzureRmVmssLifecycleHookEventCommand : ComputeAutomationBaseCmdlet + { + private const string ByNameParameterSet = "ByNameParameterSet"; + private const string ByObjectParameterSet = "ByObjectParameterSet"; + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipelineByPropertyName = true, + ParameterSetName = ByNameParameterSet, + HelpMessage = "The name of the resource group.")] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + Position = 1, + ValueFromPipelineByPropertyName = true, + ParameterSetName = ByNameParameterSet, + HelpMessage = "The name of the VM scale set.")] + [ResourceNameCompleter("Microsoft.Compute/virtualMachineScaleSets", "ResourceGroupName")] + [ValidateNotNullOrEmpty] + [Alias("VMScaleSetName")] + public string VMScaleSetName { get; set; } + + [Parameter( + Mandatory = true, + Position = 2, + ValueFromPipelineByPropertyName = true, + ParameterSetName = ByNameParameterSet, + HelpMessage = "The name (GUID) of the lifecycle hook event to update.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ParameterSetName = ByObjectParameterSet, + HelpMessage = "The lifecycle hook event object from Get-AzVmssLifecycleHookEvent.")] + [ValidateNotNull] + public VMScaleSetLifecycleHookEvent InputObject { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The action state to apply to the lifecycle hook event targets. Accepted values: 'Approved', 'Rejected'. Note: 'Rejected' returns a server error during preview.")] + [PSArgumentCompleter("Approved", "Rejected")] + [ValidateSet("Approved", "Rejected")] + public string ActionState { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Filters the update to a subset of target VM instance IDs (decimal IDs for Uniform VMSS) or VM names (for Flex VMSS). When omitted, the action state is applied to all target resources in the event.")] + public string[] InstanceId { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Delays the event deadline to the specified UTC timestamp (ISO 8601 format, e.g. '2026-05-08T11:00:00Z'). The timestamp must not be beyond MaxWaitUntil.")] + public string WaitUntil { get; set; } + + public override void ExecuteCmdlet() + { + base.ExecuteCmdlet(); + ExecuteClientAction(() => + { + string resourceGroupName; + string vmScaleSetName; + string eventName; + VMScaleSetLifecycleHookEvent existingEvent; + + if (this.ParameterSetName.Equals(ByObjectParameterSet)) + { + // Extract resource group, VMSS name, and event name from the object's ID + // ID format: /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss}/lifecycleHookEvents/{name} + var id = this.InputObject?.Id; + if (string.IsNullOrEmpty(id)) + { + ThrowTerminatingError(new ErrorRecord( + new ArgumentException("The InputObject does not have a valid Id."), + "InvalidInputObject", + ErrorCategory.InvalidArgument, + this.InputObject)); + return; + } + + var parts = id.Split('/'); + // Find resourceGroups index + int rgIndex = Array.FindIndex(parts, p => string.Equals(p, "resourceGroups", StringComparison.OrdinalIgnoreCase)); + int vmssIndex = Array.FindIndex(parts, p => string.Equals(p, "virtualMachineScaleSets", StringComparison.OrdinalIgnoreCase)); + int eventIndex = Array.FindIndex(parts, p => string.Equals(p, "lifecycleHookEvents", StringComparison.OrdinalIgnoreCase)); + + if (rgIndex < 0 || vmssIndex < 0 || eventIndex < 0) + { + ThrowTerminatingError(new ErrorRecord( + new ArgumentException($"Could not parse resource group, VMSS name, or event name from Id: {id}"), + "InvalidResourceId", + ErrorCategory.InvalidArgument, + id)); + return; + } + + resourceGroupName = parts[rgIndex + 1]; + vmScaleSetName = parts[vmssIndex + 1]; + eventName = parts[eventIndex + 1]; + existingEvent = this.InputObject; + } + else + { + resourceGroupName = this.ResourceGroupName; + vmScaleSetName = this.VMScaleSetName; + eventName = this.Name; + existingEvent = null; + } + + if (ShouldProcess(eventName, "Update-AzVmssLifecycleHookEvent")) + { + // If we need to filter by InstanceId or apply ActionState, get current target resources + List targetResources = null; + + if (this.IsParameterBound(c => c.ActionState)) + { + // Get target resources from existing event (either piped object or fetched) + IList currentTargets; + if (existingEvent?.Properties?.TargetResources != null) + { + currentTargets = existingEvent.Properties.TargetResources; + } + else + { + var fetchedEvent = VirtualMachineScaleSetLifeCycleHookEventsClient.Get( + resourceGroupName, vmScaleSetName, eventName); + currentTargets = fetchedEvent?.Properties?.TargetResources ?? new List(); + } + + if (this.IsParameterBound(c => c.InstanceId) && this.InstanceId != null && this.InstanceId.Length > 0) + { + // Filter to only the specified instance IDs + var instanceIdSet = new HashSet(this.InstanceId, StringComparer.OrdinalIgnoreCase); + targetResources = currentTargets + .Where(t => t.Resource?.Id != null && instanceIdSet.Any(id => + t.Resource.Id.EndsWith("/" + id, StringComparison.OrdinalIgnoreCase) || + t.Resource.Id.EndsWith("_" + id, StringComparison.OrdinalIgnoreCase) || + string.Equals(t.Resource.Id, id, StringComparison.OrdinalIgnoreCase))) + .Select(t => new VMScaleSetLifecycleHookEventTargetResource + { + Resource = t.Resource, + ActionState = this.ActionState + }) + .ToList(); + } + else + { + // Apply to all targets + targetResources = currentTargets + .Select(t => new VMScaleSetLifecycleHookEventTargetResource + { + Resource = t.Resource, + ActionState = this.ActionState + }) + .ToList(); + } + } + + var updateParams = new VMScaleSetLifecycleHookEventUpdate + { + TargetResources = targetResources, + WaitUntil = this.IsParameterBound(c => c.WaitUntil) ? this.WaitUntil : null + }; + + var result = VirtualMachineScaleSetLifeCycleHookEventsClient.Update( + resourceGroupName, + vmScaleSetName, + eventName, + updateParams); + + WriteObject(result); + } + }); + } + } +} diff --git a/src/Compute/Compute/Manual/PSVirtualMachineScaleSet.cs b/src/Compute/Compute/Manual/PSVirtualMachineScaleSet.cs index a069d65f0a75..3a8270e03d63 100644 --- a/src/Compute/Compute/Manual/PSVirtualMachineScaleSet.cs +++ b/src/Compute/Compute/Manual/PSVirtualMachineScaleSet.cs @@ -27,5 +27,8 @@ public partial class PSVirtualMachineScaleSet // Gets or sets the ZonePlacementPolicy. public string ZonePlacementPolicy { get; set; } + // Gets or sets the lifecycle hooks profile. + public Microsoft.Azure.Management.Compute.Models.LifecycleHooksProfile LifecycleHooksProfile { get; set; } + } } \ No newline at end of file diff --git a/src/Compute/Compute/help/Get-AzVmssLifecycleHookEvent.md b/src/Compute/Compute/help/Get-AzVmssLifecycleHookEvent.md new file mode 100644 index 000000000000..262cb1a5ac28 --- /dev/null +++ b/src/Compute/Compute/help/Get-AzVmssLifecycleHookEvent.md @@ -0,0 +1,148 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Compute.dll-Help.xml +Module Name: Az.Compute +online version: https://learn.microsoft.com/powershell/module/az.compute/get-azvmsslifecyclehookevent +schema: 2.0.0 +--- + +# Get-AzVmssLifecycleHookEvent + +## SYNOPSIS +Lists or retrieves lifecycle hook events for a Virtual Machine Scale Set (VMSS). + +## SYNTAX + +### ListParameterSet (Default) +``` +Get-AzVmssLifecycleHookEvent -ResourceGroupName -VMScaleSetName + [-DefaultProfile ] [] +``` + +### GetParameterSet +``` +Get-AzVmssLifecycleHookEvent -ResourceGroupName -VMScaleSetName -Name + [-DefaultProfile ] [] +``` + +## DESCRIPTION +The **Get-AzVmssLifecycleHookEvent** cmdlet lists all lifecycle hook events for a virtual machine scale set (VMSS) or retrieves a specific event by name (GUID). Lifecycle hook events are created by the platform when configured hooks fire during Auto OS Upgrade phases. + +Events have a `Properties.State` of either 'Active' (waiting for a customer response) or 'Completed'. + +## EXAMPLES + +### Example 1: List all lifecycle hook events for a VMSS +```powershell +Get-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' +``` + +This example lists all lifecycle hook events for the specified VMSS. + +### Example 2: Get a specific event by name +```powershell +Get-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -Name 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' +``` + +This example retrieves a specific lifecycle hook event by its GUID name. + +### Example 3: Filter to active events only +```powershell +Get-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' | + Where-Object { $_.Properties.State -eq 'Active' } +``` + +This example lists only the active lifecycle hook events. + +### Example 4: Approve all active events via pipeline +```powershell +Get-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' | + Where-Object { $_.Properties.State -eq 'Active' } | + Update-AzVmssLifecycleHookEvent -ActionState Approved +``` + +This example retrieves all active events and approves each one through the pipeline. + +## PARAMETERS + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +The name (GUID) of the lifecycle hook event to retrieve. When omitted, all events for the VMSS are listed. + +```yaml +Type: System.String +Parameter Sets: GetParameterSet +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ResourceGroupName +The name of the resource group. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -VMScaleSetName +The name of the VM scale set. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +## OUTPUTS + +### Microsoft.Azure.Management.Compute.Models.VMScaleSetLifecycleHookEvent + +## NOTES + +## RELATED LINKS + +[Update-AzVmssLifecycleHookEvent](./Update-AzVmssLifecycleHookEvent.md) + +[New-AzVmssLifecycleHookConfig](./New-AzVmssLifecycleHookConfig.md) + +[Set-AzVmssLifecycleHooksProfile](./Set-AzVmssLifecycleHooksProfile.md) + +[Remove-AzVmssLifecycleHook](./Remove-AzVmssLifecycleHook.md) diff --git a/src/Compute/Compute/help/New-AzVmssConfig.md b/src/Compute/Compute/help/New-AzVmssConfig.md index 3fa33b567ee3..70fe2e0e1719 100644 --- a/src/Compute/Compute/help/New-AzVmssConfig.md +++ b/src/Compute/Compute/help/New-AzVmssConfig.md @@ -37,7 +37,7 @@ New-AzVmssConfig [[-Overprovision] ] [[-Location] ] [-EdgeZone [-EnableResilientVMDelete] [-EnableAutomaticZoneRebalance] [-AutomaticZoneRebalanceStrategy ] [-AutomaticZoneRebalanceBehavior ] [-ZonePlacementPolicy ] [-MaxZoneCount ] [-EnableMaxInstancePercentPerZone] [-MaxInstancePercentPerZoneValue ] [-IncludeZone ] - [-ExcludeZone ] [-HighSpeedInterconnectPlacement ] [-DefaultProfile ] + [-ExcludeZone ] [-HighSpeedInterconnectPlacement ] [-LifecycleHooksProfile ] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -66,7 +66,7 @@ New-AzVmssConfig [[-Overprovision] ] [[-Location] ] [-EdgeZone [-EnableResilientVMDelete] [-EnableAutomaticZoneRebalance] [-AutomaticZoneRebalanceStrategy ] [-AutomaticZoneRebalanceBehavior ] [-ZonePlacementPolicy ] [-MaxZoneCount ] [-EnableMaxInstancePercentPerZone] [-MaxInstancePercentPerZoneValue ] [-IncludeZone ] - [-ExcludeZone ] [-HighSpeedInterconnectPlacement ] [-DefaultProfile ] + [-ExcludeZone ] [-HighSpeedInterconnectPlacement ] [-LifecycleHooksProfile ] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -1350,6 +1350,29 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -LifecycleHooksProfile +Specifies the lifecycle hooks profile for the virtual machine scale set. + +Use 'New-AzVmssLifecycleHookConfig' to create hook objects, then build the profile with 'Set-AzVmssLifecycleHooksProfile', or create a LifecycleHooksProfile object directly as shown: + +```powershell +$hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' -WaitDuration 'PT8H' +$profile = [Microsoft.Azure.Management.Compute.Models.LifecycleHooksProfile]@{ LifecycleHooks = @($hook) } +New-AzVmssConfig -Location eastus -SkuCapacity 2 -LifecycleHooksProfile $profile +``` + +```yaml +Type: Microsoft.Azure.Management.Compute.Models.LifecycleHooksProfile +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -Confirm Prompts you for confirmation before running the cmdlet. diff --git a/src/Compute/Compute/help/New-AzVmssLifecycleHookConfig.md b/src/Compute/Compute/help/New-AzVmssLifecycleHookConfig.md new file mode 100644 index 000000000000..16df9d9f5ea4 --- /dev/null +++ b/src/Compute/Compute/help/New-AzVmssLifecycleHookConfig.md @@ -0,0 +1,172 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Compute.dll-Help.xml +Module Name: Az.Compute +online version: https://learn.microsoft.com/powershell/module/az.compute/new-azvmsslifecyclehookconfig +schema: 2.0.0 +--- + +# New-AzVmssLifecycleHookConfig + +## SYNOPSIS +Creates an in-memory lifecycle hook configuration object for use with a Virtual Machine Scale Set (VMSS). + +## SYNTAX + +``` +New-AzVmssLifecycleHookConfig -Type [-WaitDuration ] [-DefaultAction ] + [-DefaultProfile ] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +The **New-AzVmssLifecycleHookConfig** cmdlet creates a lifecycle hook configuration object that can be passed to **Set-AzVmssLifecycleHooksProfile** or **New-AzVmssConfig**. + +Lifecycle hooks let customers register hooks that fire before VMSS Auto OS Upgrade phases, then respond to events on a per-VM basis (approve, reject, or delay) before the platform proceeds. + +> **Preview note:** During preview, the `-DefaultAction` value `Reject` returns a server-side validation error. No client change is required at GA. + +## EXAMPLES + +### Example 1: Create a lifecycle hook for Auto OS upgrade scheduling +```powershell +$hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' -WaitDuration 'PT8H' +``` + +This example creates a lifecycle hook that fires before Auto OS Upgrade scheduling, with an 8-hour wait duration before the default action (Approve) is applied. + +### Example 2: Create a lifecycle hook with explicit default action +```powershell +$hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSRollingBatchStarting' -WaitDuration 'PT30M' -DefaultAction 'Approve' +``` + +This example creates a lifecycle hook that fires before each rolling batch starts, with a 30-minute wait duration and an explicit default action of Approve. + +### Example 3: Use the hook in a new VMSS +```powershell +$hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' -WaitDuration 'PT8H' +$config = New-AzVmssConfig -Location 'eastus' -SkuCapacity 2 +$config = Set-AzVmssLifecycleHooksProfile -VirtualMachineScaleSet $config -LifecycleHook $hook +New-AzVmss -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -VirtualMachineScaleSet $config +``` + +This example creates a VMSS with a lifecycle hook attached. + +## PARAMETERS + +### -DefaultAction +Specifies the action applied to a target resource in the lifecycle hook event if the platform does not receive a response from the customer before the wait duration expires. Accepted values: 'Approve' (default), 'Reject'. + +> **Preview note:** 'Reject' returns a server error during preview. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: +Accepted values: Approve, Reject + +Required: False +Position: 2 +Default value: Approve +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Type +Specifies the type of the lifecycle hook. Possible values: 'UpgradeAutoOSScheduling', 'UpgradeAutoOSRollingBatchStarting'. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: +Accepted values: UpgradeAutoOSScheduling, UpgradeAutoOSRollingBatchStarting + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -WaitDuration +Specifies the time duration the lifecycle hook event waits for a customer response before applying the default action. Must be in ISO 8601 duration format, for example 'PT8H' (8 hours) or 'PT30M' (30 minutes). + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +## OUTPUTS + +### Microsoft.Azure.Management.Compute.Models.LifecycleHook + +## NOTES + +## RELATED LINKS + +[Set-AzVmssLifecycleHooksProfile](./Set-AzVmssLifecycleHooksProfile.md) + +[New-AzVmssConfig](./New-AzVmssConfig.md) + +[Get-AzVmssLifecycleHookEvent](./Get-AzVmssLifecycleHookEvent.md) + +[Update-AzVmssLifecycleHookEvent](./Update-AzVmssLifecycleHookEvent.md) + +[Remove-AzVmssLifecycleHook](./Remove-AzVmssLifecycleHook.md) diff --git a/src/Compute/Compute/help/Remove-AzVmssLifecycleHook.md b/src/Compute/Compute/help/Remove-AzVmssLifecycleHook.md new file mode 100644 index 000000000000..c85dc89354c8 --- /dev/null +++ b/src/Compute/Compute/help/Remove-AzVmssLifecycleHook.md @@ -0,0 +1,182 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Compute.dll-Help.xml +Module Name: Az.Compute +online version: https://learn.microsoft.com/powershell/module/az.compute/remove-azvmsslifecyclehook +schema: 2.0.0 +--- + +# Remove-AzVmssLifecycleHook + +## SYNOPSIS +Removes one or all lifecycle hooks from a Virtual Machine Scale Set (VMSS). + +## SYNTAX + +### ByTypeParameterSet (Default) +``` +Remove-AzVmssLifecycleHook -ResourceGroupName -VMScaleSetName -Type + [-DefaultProfile ] [-WhatIf] [-Confirm] [] +``` + +### AllParameterSet +``` +Remove-AzVmssLifecycleHook -ResourceGroupName -VMScaleSetName [-All] + [-DefaultProfile ] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +The **Remove-AzVmssLifecycleHook** cmdlet removes one lifecycle hook (by `-Type`) or all lifecycle hooks (`-All`) from an existing virtual machine scale set (VMSS) by fetching the current VMSS, removing the specified hook(s), and updating the VMSS. + +## EXAMPLES + +### Example 1: Remove a lifecycle hook by type +```powershell +Remove-AzVmssLifecycleHook -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -Type 'UpgradeAutoOSScheduling' +``` + +This example removes the 'UpgradeAutoOSScheduling' lifecycle hook from the specified VMSS. + +### Example 2: Remove all lifecycle hooks +```powershell +Remove-AzVmssLifecycleHook -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -All +``` + +This example removes all lifecycle hooks from the specified VMSS. + +### Example 3: Preview removal with WhatIf +```powershell +Remove-AzVmssLifecycleHook -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -Type 'UpgradeAutoOSScheduling' -WhatIf +``` + +This example previews what would happen when removing the hook, without making any changes. + +## PARAMETERS + +### -All +When specified, removes all lifecycle hooks from the virtual machine scale set. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: AllParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ResourceGroupName +The name of the resource group. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Type +The lifecycle hook type to remove. Possible values: 'UpgradeAutoOSScheduling', 'UpgradeAutoOSRollingBatchStarting'. + +```yaml +Type: System.String +Parameter Sets: ByTypeParameterSet +Aliases: +Accepted values: UpgradeAutoOSScheduling, UpgradeAutoOSRollingBatchStarting + +Required: True +Position: 2 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -VMScaleSetName +The name of the VM scale set. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: Name + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +## OUTPUTS + +### Microsoft.Azure.Commands.Compute.Automation.Models.PSVirtualMachineScaleSet + +## NOTES + +## RELATED LINKS + +[New-AzVmssLifecycleHookConfig](./New-AzVmssLifecycleHookConfig.md) + +[Set-AzVmssLifecycleHooksProfile](./Set-AzVmssLifecycleHooksProfile.md) + +[Get-AzVmssLifecycleHookEvent](./Get-AzVmssLifecycleHookEvent.md) + +[Update-AzVmssLifecycleHookEvent](./Update-AzVmssLifecycleHookEvent.md) diff --git a/src/Compute/Compute/help/Set-AzVmssLifecycleHooksProfile.md b/src/Compute/Compute/help/Set-AzVmssLifecycleHooksProfile.md new file mode 100644 index 000000000000..b60ff9bead41 --- /dev/null +++ b/src/Compute/Compute/help/Set-AzVmssLifecycleHooksProfile.md @@ -0,0 +1,159 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Compute.dll-Help.xml +Module Name: Az.Compute +online version: https://learn.microsoft.com/powershell/module/az.compute/set-azvmsslifecyclehooksprofile +schema: 2.0.0 +--- + +# Set-AzVmssLifecycleHooksProfile + +## SYNOPSIS +Attaches lifecycle hooks to a Virtual Machine Scale Set (VMSS) configuration or live VMSS object. + +## SYNTAX + +``` +Set-AzVmssLifecycleHooksProfile -VirtualMachineScaleSet + -LifecycleHook [-DefaultProfile ] [-WhatIf] [-Confirm] + [] +``` + +## DESCRIPTION +The **Set-AzVmssLifecycleHooksProfile** cmdlet attaches lifecycle hooks to a VMSS configuration object (PSVirtualMachineScaleSet) and returns the updated object. This follows the standard Az.Compute builder convention (same as Set-AzVmssOsProfile, Set-AzVmssStorageProfile): it mutates the VMSS config object AND returns it. + +The updated object must be passed to **New-AzVmss** (for new scale sets) or **Update-AzVmss** (for existing scale sets) to persist the changes to Azure. + +## EXAMPLES + +### Example 1: Attach a lifecycle hook to a new VMSS configuration +```powershell +$hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' -WaitDuration 'PT8H' +$config = New-AzVmssConfig -Location 'eastus' -SkuCapacity 2 +$config = Set-AzVmssLifecycleHooksProfile -VirtualMachineScaleSet $config -LifecycleHook $hook +New-AzVmss -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -VirtualMachineScaleSet $config +``` + +This example creates a new VMSS with a lifecycle hook attached. + +### Example 2: Add a lifecycle hook to an existing VMSS +```powershell +$vmss = Get-AzVmss -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' +$existing = if ($vmss.LifecycleHooksProfile) { $vmss.LifecycleHooksProfile.LifecycleHooks } else { @() } +$batch = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSRollingBatchStarting' -WaitDuration 'PT30M' +$vmss = Set-AzVmssLifecycleHooksProfile -VirtualMachineScaleSet $vmss -LifecycleHook ($existing + $batch) +Update-AzVmss -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -VirtualMachineScaleSet $vmss +``` + +This example adds a second lifecycle hook to an existing VMSS, preserving the existing hooks. + +### Example 3: Use pipeline to attach hooks +```powershell +$hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' -WaitDuration 'PT8H' +New-AzVmssConfig -Location 'eastus' -SkuCapacity 2 | Set-AzVmssLifecycleHooksProfile -LifecycleHook $hook +``` + +This example uses the pipeline to attach a lifecycle hook to a VMSS configuration. + +## PARAMETERS + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LifecycleHook +One or more lifecycle hook objects to attach to the VMSS. Use 'New-AzVmssLifecycleHookConfig' to create hook objects. Replaces any existing lifecycle hooks on the VMSS config object. + +```yaml +Type: Microsoft.Azure.Management.Compute.Models.LifecycleHook[] +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -VirtualMachineScaleSet +The VMSS configuration object (PSVirtualMachineScaleSet) to update. Can be an in-memory config from 'New-AzVmssConfig' or a live VMSS object from 'Get-AzVmss'. + +```yaml +Type: Microsoft.Azure.Commands.Compute.Automation.Models.PSVirtualMachineScaleSet +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue, ByPropertyName) +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### Microsoft.Azure.Commands.Compute.Automation.Models.PSVirtualMachineScaleSet + +### Microsoft.Azure.Management.Compute.Models.LifecycleHook[] + +## OUTPUTS + +### Microsoft.Azure.Commands.Compute.Automation.Models.PSVirtualMachineScaleSet + +## NOTES + +## RELATED LINKS + +[New-AzVmssLifecycleHookConfig](./New-AzVmssLifecycleHookConfig.md) + +[New-AzVmssConfig](./New-AzVmssConfig.md) + +[Remove-AzVmssLifecycleHook](./Remove-AzVmssLifecycleHook.md) + +[Get-AzVmssLifecycleHookEvent](./Get-AzVmssLifecycleHookEvent.md) + +[Update-AzVmssLifecycleHookEvent](./Update-AzVmssLifecycleHookEvent.md) diff --git a/src/Compute/Compute/help/Update-AzVmssLifecycleHookEvent.md b/src/Compute/Compute/help/Update-AzVmssLifecycleHookEvent.md new file mode 100644 index 000000000000..34a15a6eb78e --- /dev/null +++ b/src/Compute/Compute/help/Update-AzVmssLifecycleHookEvent.md @@ -0,0 +1,274 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Compute.dll-Help.xml +Module Name: Az.Compute +online version: https://learn.microsoft.com/powershell/module/az.compute/update-azvmsslifecyclehookevent +schema: 2.0.0 +--- + +# Update-AzVmssLifecycleHookEvent + +## SYNOPSIS +Responds to a Virtual Machine Scale Set (VMSS) lifecycle hook event by approving, rejecting, or delaying it. + +## SYNTAX + +### ByNameParameterSet (Default) +``` +Update-AzVmssLifecycleHookEvent -ResourceGroupName -VMScaleSetName -Name + [-ActionState ] [-InstanceId ] [-WaitUntil ] + [-DefaultProfile ] [-WhatIf] [-Confirm] [] +``` + +### ByObjectParameterSet +``` +Update-AzVmssLifecycleHookEvent -InputObject [-ActionState ] + [-InstanceId ] [-WaitUntil ] [-DefaultProfile ] [-WhatIf] + [-Confirm] [] +``` + +## DESCRIPTION +The **Update-AzVmssLifecycleHookEvent** cmdlet responds to a VMSS lifecycle hook event. You can: +- Approve or reject the event (`-ActionState`) +- Approve or reject a subset of VM instances (`-InstanceId` with `-ActionState`) +- Delay the event deadline (`-WaitUntil`) + +The cmdlet accepts pipeline input from **Get-AzVmssLifecycleHookEvent**. + +> **Preview note:** `-ActionState Rejected` returns a server-side validation error during preview. No client change is required at GA. + +## EXAMPLES + +### Example 1: Approve all targets in an event +```powershell +Update-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -Name $eventGuid -ActionState Approved +``` + +This example approves all target resources in the lifecycle hook event. + +### Example 2: Reject all targets (returns server error during preview) +```powershell +Update-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -Name $eventGuid -ActionState Rejected +``` + +This example rejects all target resources. Note: this returns a server error during preview. + +### Example 3: Approve a subset of VMs in a Uniform VMSS +```powershell +Update-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -Name $eventGuid -InstanceId '0','1','2' -ActionState Approved +``` + +This example approves VMs with instance IDs 0, 1, and 2 in a Uniform VMSS. + +### Example 4: Approve a subset of VMs in a Flex VMSS +```powershell +Update-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -Name $eventGuid -InstanceId 'myvmss_3ec87a','myvmss_a1b2c3' -ActionState Approved +``` + +This example approves specific VM names in a Flex VMSS. + +### Example 5: Delay the event deadline +```powershell +Update-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -Name $eventGuid -WaitUntil '2026-05-08T11:00:00Z' +``` + +This example delays the event deadline to the specified UTC timestamp. + +### Example 6: Preview what would be approved +```powershell +Update-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -Name $eventGuid -ActionState Approved -WhatIf +``` + +This example shows what the cmdlet would do without making any changes. + +### Example 7: Approve all active events via pipeline +```powershell +Get-AzVmssLifecycleHookEvent -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' | + Where-Object { $_.Properties.State -eq 'Active' } | + Update-AzVmssLifecycleHookEvent -ActionState Approved +``` + +This example retrieves all active lifecycle hook events and approves each one through the pipeline. + +## PARAMETERS + +### -ActionState +The action state to apply to the lifecycle hook event targets. Accepted values: 'Approved', 'Rejected'. + +When `-InstanceId` is not specified, the action is applied to all target resources in the event. When `-InstanceId` is specified, only the matching targets are updated. + +> **Preview note:** 'Rejected' returns a server error during preview. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: +Accepted values: Approved, Rejected + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -InputObject +The lifecycle hook event object from 'Get-AzVmssLifecycleHookEvent'. When using this parameter set, the resource group name, VMSS name, and event name are extracted from the object. + +```yaml +Type: Microsoft.Azure.Management.Compute.Models.VMScaleSetLifecycleHookEvent +Parameter Sets: ByObjectParameterSet +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -InstanceId +Filters the update to a subset of target VM instance IDs (decimal IDs for Uniform VMSS) or VM names (for Flex VMSS). When omitted, the action state is applied to all target resources in the event. + +```yaml +Type: System.String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Name +The name (GUID) of the lifecycle hook event to update. + +```yaml +Type: System.String +Parameter Sets: ByNameParameterSet +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ResourceGroupName +The name of the resource group. + +```yaml +Type: System.String +Parameter Sets: ByNameParameterSet +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -VMScaleSetName +The name of the VM scale set. + +```yaml +Type: System.String +Parameter Sets: ByNameParameterSet +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -WaitUntil +Delays the event deadline to the specified UTC timestamp in ISO 8601 format (for example, '2026-05-08T11:00:00Z'). The timestamp must not exceed the event's MaxWaitUntil value. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### Microsoft.Azure.Management.Compute.Models.VMScaleSetLifecycleHookEvent + +### System.String + +### System.String[] + +## OUTPUTS + +### Microsoft.Azure.Management.Compute.Models.VMScaleSetLifecycleHookEvent + +## NOTES + +## RELATED LINKS + +[Get-AzVmssLifecycleHookEvent](./Get-AzVmssLifecycleHookEvent.md) + +[New-AzVmssLifecycleHookConfig](./New-AzVmssLifecycleHookConfig.md) + +[Set-AzVmssLifecycleHooksProfile](./Set-AzVmssLifecycleHooksProfile.md) + +[Remove-AzVmssLifecycleHook](./Remove-AzVmssLifecycleHook.md)