-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[Compute] Add VMSS Lifecycle Hooks cmdlets (Az.Compute preview) #29574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
3
commits into
main
Choose a base branch
from
copilot/design-review-az-compute-vmss-lifecycle-hooks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...mpute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssLifecycleHookConfigCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
57 changes: 57 additions & 0 deletions
57
...ute/Generated/VirtualMachineScaleSet/Config/SetAzureRmVmssLifecycleHooksProfileCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } | ||
| } | ||
| } |
107 changes: 107 additions & 0 deletions
107
...mpute/Compute/Generated/VirtualMachineScaleSet/GetAzureRmVmssLifecycleHookEventCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot add a comment that "Since currently in production, if the customer does no pass defaultAction, we use "Approve" for these types, this works. In the future if we change the default defaultAction in production for any existing / future types, this needs to change"