/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file 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.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.AutoScaling;
using Amazon.AutoScaling.Model;
namespace Amazon.PowerShell.Cmdlets.AS
{
///
/// Creates or updates a scheduled scaling action for an Auto Scaling group.
///
///
///
/// For more information, see Scheduled
/// scaling in the Amazon EC2 Auto Scaling User Guide.
///
/// You can view the scheduled actions for an Auto Scaling group using the DescribeScheduledActions
/// API call. If you are no longer using a scheduled action, you can delete it by calling
/// the DeleteScheduledAction API.
///
/// If you try to schedule your action in the past, Amazon EC2 Auto Scaling returns an
/// error message.
///
///
[Cmdlet("Write", "ASScheduledUpdateGroupAction", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("None")]
[AWSCmdlet("Calls the AWS Auto Scaling PutScheduledUpdateGroupAction API operation.", Operation = new[] {"PutScheduledUpdateGroupAction"}, SelectReturnType = typeof(Amazon.AutoScaling.Model.PutScheduledUpdateGroupActionResponse))]
[AWSCmdletOutput("None or Amazon.AutoScaling.Model.PutScheduledUpdateGroupActionResponse",
"This cmdlet does not generate any output." +
"The service response (type Amazon.AutoScaling.Model.PutScheduledUpdateGroupActionResponse) can be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class WriteASScheduledUpdateGroupActionCmdlet : AmazonAutoScalingClientCmdlet, IExecutor
{
#region Parameter AutoScalingGroupName
///
///
/// The name of the Auto Scaling group.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
#else
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String AutoScalingGroupName { get; set; }
#endregion
#region Parameter DesiredCapacity
///
///
/// The desired capacity is the initial capacity of the Auto Scaling group after the scheduled
/// action runs and the capacity it attempts to maintain. It can scale beyond this capacity
/// if you add more scaling conditions. You must specify at least one of the following properties: MaxSize
, MinSize
,
/// or DesiredCapacity
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? DesiredCapacity { get; set; }
#endregion
#region Parameter UtcEndTime
///
///
/// The date and time for the recurring schedule to end, in UTC. For example, "2021-06-01T00:00:00Z"
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.DateTime? UtcEndTime { get; set; }
#endregion
#region Parameter MaxSize
///
///
/// The maximum size of the Auto Scaling group.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? MaxSize { get; set; }
#endregion
#region Parameter MinSize
///
///
/// The minimum size of the Auto Scaling group.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? MinSize { get; set; }
#endregion
#region Parameter Recurrence
///
///
/// The recurring schedule for this action. This format consists of five fields separated
/// by white spaces: [Minute] [Hour] [Day_of_Month] [Month_of_Year] [Day_of_Week]. The
/// value must be in quotes (for example, "30 0 1 1,6,12 *"
). For more information
/// about this format, see Crontab.When StartTime
and EndTime
are specified with Recurrence
,
/// they form the boundaries of when the recurring action starts and stops.Cron expressions use Universal Coordinated Time (UTC) by default.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Recurrence { get; set; }
#endregion
#region Parameter ScheduledActionName
///
///
/// The name of this scaling action.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String ScheduledActionName { get; set; }
#endregion
#region Parameter UtcStartTime
///
///
/// The date and time for this action to start, in YYYY-MM-DDThh:mm:ssZ format in UTC/GMT
/// only and in quotes (for example, "2021-06-01T00:00:00Z"
).If you specify Recurrence
and StartTime
, Amazon EC2 Auto
/// Scaling performs the action at this time, and then performs the action based on the
/// specified recurrence.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.DateTime? UtcStartTime { get; set; }
#endregion
#region Parameter UtcTime
///
///
/// This property is no longer used.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.DateTime? UtcTime { get; set; }
#endregion
#region Parameter TimeZone
///
///
/// Specifies the time zone for a cron expression. If a time zone is not provided, UTC
/// is used by default. Valid values are the canonical names of the IANA time zones, derived from the IANA
/// Time Zone Database (such as Etc/GMT+9
or Pacific/Tahiti
).
/// For more information, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String TimeZone { get; set; }
#endregion
#region Parameter EndTime
///
///
/// This property is deprecated. Setting this property results in non-UTC DateTimes not
/// being marshalled correctly. Use EndTimeUtc instead. Setting either EndTime or EndTimeUtc
/// results in both EndTime and EndTimeUtc being assigned, the latest assignment to either
/// one of the two property is reflected in the value of both. EndTime is provided for
/// backwards compatibility only and assigning a non-Utc DateTime to it results in the
/// wrong timestamp being passed to the service.The date and time for the recurring schedule to end, in UTC. For example, "2021-06-01T00:00:00Z"
.
///
/// This parameter is deprecated.
///
[System.Management.Automation.Parameter(Position = 3, ValueFromPipelineByPropertyName = true)]
[System.ObsoleteAttribute("This parameter is deprecated and may result in the wrong timestamp being passed to the service, use UtcEndTime instead.")]
public System.DateTime? EndTime { get; set; }
#endregion
#region Parameter StartTime
///
///
/// This property is deprecated. Setting this property results in non-UTC DateTimes not
/// being marshalled correctly. Use StartTimeUtc instead. Setting either StartTime or
/// StartTimeUtc results in both StartTime and StartTimeUtc being assigned, the latest
/// assignment to either one of the two property is reflected in the value of both. StartTime
/// is provided for backwards compatibility only and assigning a non-Utc DateTime to it
/// results in the wrong timestamp being passed to the service.The date and time for this action to start, in YYYY-MM-DDThh:mm:ssZ format in UTC/GMT
/// only and in quotes (for example, "2021-06-01T00:00:00Z"
).If you specify Recurrence
and StartTime
, Amazon EC2 Auto
/// Scaling performs the action at this time, and then performs the action based on the
/// specified recurrence.
///
/// This parameter is deprecated.
///
[System.Management.Automation.Parameter(Position = 2, ValueFromPipelineByPropertyName = true)]
[System.ObsoleteAttribute("This parameter is deprecated and may result in the wrong timestamp being passed to the service, use UtcStartTime instead.")]
public System.DateTime? StartTime { get; set; }
#endregion
#region Parameter Time
///
///
/// This property is deprecated. Setting this property results in non-UTC DateTimes not
/// being marshalled correctly. Use TimeUtc instead. Setting either Time or TimeUtc results
/// in both Time and TimeUtc being assigned, the latest assignment to either one of the
/// two property is reflected in the value of both. Time is provided for backwards compatibility
/// only and assigning a non-Utc DateTime to it results in the wrong timestamp being passed
/// to the service.This property is no longer used.
///
/// This parameter is deprecated.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[System.ObsoleteAttribute("This parameter is deprecated and may result in the wrong timestamp being passed to the service, use UtcTime instead.")]
public System.DateTime? Time { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The cmdlet doesn't have a return value by default.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.AutoScaling.Model.PutScheduledUpdateGroupActionResponse).
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "*";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the AutoScalingGroupName parameter.
/// The -PassThru parameter is deprecated, use -Select '^AutoScalingGroupName' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^AutoScalingGroupName' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { get; set; }
#endregion
#region Parameter Force
///
/// This parameter overrides confirmation prompts to force
/// the cmdlet to continue its operation. This parameter should always
/// be used with caution.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter Force { get; set; }
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var resourceIdentifiersText = FormatParameterValuesForConfirmationMsg(nameof(this.AutoScalingGroupName), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Write-ASScheduledUpdateGroupAction (PutScheduledUpdateGroupAction)"))
{
return;
}
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
if (this.PassThru.IsPresent)
{
throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select));
}
}
else if (this.PassThru.IsPresent)
{
context.Select = (response, cmdlet) => this.AutoScalingGroupName;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AutoScalingGroupName = this.AutoScalingGroupName;
#if MODULAR
if (this.AutoScalingGroupName == null && ParameterWasBound(nameof(this.AutoScalingGroupName)))
{
WriteWarning("You are passing $null as a value for parameter AutoScalingGroupName which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.DesiredCapacity = this.DesiredCapacity;
context.UtcEndTime = this.UtcEndTime;
context.MaxSize = this.MaxSize;
context.MinSize = this.MinSize;
context.Recurrence = this.Recurrence;
context.ScheduledActionName = this.ScheduledActionName;
#if MODULAR
if (this.ScheduledActionName == null && ParameterWasBound(nameof(this.ScheduledActionName)))
{
WriteWarning("You are passing $null as a value for parameter ScheduledActionName which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.UtcStartTime = this.UtcStartTime;
context.UtcTime = this.UtcTime;
context.TimeZone = this.TimeZone;
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.EndTime = this.EndTime;
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.StartTime = this.StartTime;
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.Time = this.Time;
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.AutoScaling.Model.PutScheduledUpdateGroupActionRequest();
if (cmdletContext.AutoScalingGroupName != null)
{
request.AutoScalingGroupName = cmdletContext.AutoScalingGroupName;
}
if (cmdletContext.DesiredCapacity != null)
{
request.DesiredCapacity = cmdletContext.DesiredCapacity.Value;
}
if (cmdletContext.UtcEndTime != null)
{
request.EndTimeUtc = cmdletContext.UtcEndTime.Value;
}
if (cmdletContext.MaxSize != null)
{
request.MaxSize = cmdletContext.MaxSize.Value;
}
if (cmdletContext.MinSize != null)
{
request.MinSize = cmdletContext.MinSize.Value;
}
if (cmdletContext.Recurrence != null)
{
request.Recurrence = cmdletContext.Recurrence;
}
if (cmdletContext.ScheduledActionName != null)
{
request.ScheduledActionName = cmdletContext.ScheduledActionName;
}
if (cmdletContext.UtcStartTime != null)
{
request.StartTimeUtc = cmdletContext.UtcStartTime.Value;
}
if (cmdletContext.UtcTime != null)
{
request.TimeUtc = cmdletContext.UtcTime.Value;
}
if (cmdletContext.TimeZone != null)
{
request.TimeZone = cmdletContext.TimeZone;
}
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (cmdletContext.EndTime != null)
{
if (cmdletContext.UtcEndTime != null)
{
throw new System.ArgumentException("Parameters EndTime and UtcEndTime are mutually exclusive.", nameof(this.EndTime));
}
request.EndTime = cmdletContext.EndTime.Value;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (cmdletContext.StartTime != null)
{
if (cmdletContext.UtcStartTime != null)
{
throw new System.ArgumentException("Parameters StartTime and UtcStartTime are mutually exclusive.", nameof(this.StartTime));
}
request.StartTime = cmdletContext.StartTime.Value;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (cmdletContext.Time != null)
{
if (cmdletContext.UtcTime != null)
{
throw new System.ArgumentException("Parameters Time and UtcTime are mutually exclusive.", nameof(this.Time));
}
request.Time = cmdletContext.Time.Value;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
CmdletOutput output;
// issue call
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
pipelineOutput = cmdletContext.Select(response, this);
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
return output;
}
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.AutoScaling.Model.PutScheduledUpdateGroupActionResponse CallAWSServiceOperation(IAmazonAutoScaling client, Amazon.AutoScaling.Model.PutScheduledUpdateGroupActionRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Auto Scaling", "PutScheduledUpdateGroupAction");
try
{
#if DESKTOP
return client.PutScheduledUpdateGroupAction(request);
#elif CORECLR
return client.PutScheduledUpdateGroupActionAsync(request).GetAwaiter().GetResult();
#else
#error "Unknown build edition"
#endif
}
catch (AmazonServiceException exc)
{
var webException = exc.InnerException as System.Net.WebException;
if (webException != null)
{
throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
}
throw;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public System.String AutoScalingGroupName { get; set; }
public System.Int32? DesiredCapacity { get; set; }
public System.DateTime? UtcEndTime { get; set; }
public System.Int32? MaxSize { get; set; }
public System.Int32? MinSize { get; set; }
public System.String Recurrence { get; set; }
public System.String ScheduledActionName { get; set; }
public System.DateTime? UtcStartTime { get; set; }
public System.DateTime? UtcTime { get; set; }
public System.String TimeZone { get; set; }
[System.ObsoleteAttribute]
public System.DateTime? EndTime { get; set; }
[System.ObsoleteAttribute]
public System.DateTime? StartTime { get; set; }
[System.ObsoleteAttribute]
public System.DateTime? Time { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => null;
}
}
}