/******************************************************************************* * 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.ApplicationAutoScaling; using Amazon.ApplicationAutoScaling.Model; namespace Amazon.PowerShell.Cmdlets.AAS { /// /// Creates or updates a scheduled action for an Application Auto Scaling scalable target. /// /// /// /// /// Each scalable target is identified by a service namespace, resource ID, and scalable /// dimension. A scheduled action applies to the scalable target identified by those three /// attributes. You cannot create a scheduled action until you have registered the resource /// as a scalable target. /// /// When you specify start and end times with a recurring schedule using a cron expression /// or rates, they form the boundaries for when the recurring action starts and stops. /// /// To update a scheduled action, specify the parameters that you want to change. If you /// don't specify start and end times, the old values are deleted. /// /// For more information, see Scheduled /// scaling in the Application Auto Scaling User Guide. /// /// If a scalable target is deregistered, the scalable target is no longer available to /// run scheduled actions. Any scheduled actions that were specified for the scalable /// target are deleted. /// /// [Cmdlet("Set", "AASScheduledAction", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("None")] [AWSCmdlet("Calls the Application Auto Scaling PutScheduledAction API operation.", Operation = new[] {"PutScheduledAction"}, SelectReturnType = typeof(Amazon.ApplicationAutoScaling.Model.PutScheduledActionResponse))] [AWSCmdletOutput("None or Amazon.ApplicationAutoScaling.Model.PutScheduledActionResponse", "This cmdlet does not generate any output." + "The service response (type Amazon.ApplicationAutoScaling.Model.PutScheduledActionResponse) can be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class SetAASScheduledActionCmdlet : AmazonApplicationAutoScalingClientCmdlet, IExecutor { #region Parameter EndTime /// /// /// The date and time for the recurring schedule to end, in UTC. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.DateTime? EndTime { get; set; } #endregion #region Parameter ScalableTargetAction_MaxCapacity /// /// /// The maximum capacity.Although you can specify a large maximum capacity, note that service quotas may impose /// lower limits. Each service has its own default quotas for the maximum capacity of /// the resource. If you want to specify a higher limit, you can request an increase. /// For more information, consult the documentation for that service. For information /// about the default quotas for each service, see Service /// endpoints and quotas in the Amazon Web Services General Reference. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? ScalableTargetAction_MaxCapacity { get; set; } #endregion #region Parameter ScalableTargetAction_MinCapacity /// /// /// The minimum capacity.When the scheduled action runs, the resource will have at least this much capacity, /// but it might have more depending on other settings, such as the target utilization /// level of a target tracking scaling policy. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? ScalableTargetAction_MinCapacity { get; set; } #endregion #region Parameter ResourceId /// /// /// The identifier of the resource associated with the scheduled action. This string consists /// of the resource type and unique identifier. /// /// #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 ResourceId { get; set; } #endregion #region Parameter ScalableDimension /// /// /// The scalable dimension. This string consists of the service namespace, resource type, /// and scaling property. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] [AWSConstantClassSource("Amazon.ApplicationAutoScaling.ScalableDimension")] public Amazon.ApplicationAutoScaling.ScalableDimension ScalableDimension { get; set; } #endregion #region Parameter Schedule /// /// /// The schedule for this action. The following formats are supported:At expressions are useful for one-time schedules. Cron expressions are useful for /// scheduled actions that run periodically at a specified date and time, and rate expressions /// are useful for scheduled actions that run at a regular interval.At and cron expressions use Universal Coordinated Time (UTC) by default.The cron format consists of six fields separated by white spaces: [Minutes] [Hours] /// [Day_of_Month] [Month] [Day_of_Week] [Year].For rate expressions, value is a positive integer and unit is minute /// | minutes | hour | hours | day /// | days.For more information and examples, see Example /// scheduled actions for Application Auto Scaling in the Application Auto Scaling /// User Guide. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Schedule { get; set; } #endregion #region Parameter ScheduledActionName /// /// /// The name of the scheduled action. This name must be unique among all other scheduled /// actions on the specified scalable target. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(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 ServiceNamespace /// /// /// The namespace of the Amazon Web Services service that provides the resource. For a /// resource provided by your own application or service, use custom-resource /// instead. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] [AWSConstantClassSource("Amazon.ApplicationAutoScaling.ServiceNamespace")] public Amazon.ApplicationAutoScaling.ServiceNamespace ServiceNamespace { get; set; } #endregion #region Parameter StartTime /// /// /// The date and time for this scheduled action to start, in UTC. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.DateTime? StartTime { get; set; } #endregion #region Parameter Timezone /// /// /// Specifies the time zone used when setting a scheduled action by using an at or 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 supported by Joda-Time /// (such as Etc/GMT+9 or Pacific/Tahiti). For more information, /// see https://www.joda.org/joda-time/timezones.html. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Timezone { 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.ApplicationAutoScaling.Model.PutScheduledActionResponse). /// 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 ResourceId parameter. /// The -PassThru parameter is deprecated, use -Select '^ResourceId' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ResourceId' 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.ResourceId), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Set-AASScheduledAction (PutScheduledAction)")) { 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.ResourceId; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.EndTime = this.EndTime; context.ResourceId = this.ResourceId; #if MODULAR if (this.ResourceId == null && ParameterWasBound(nameof(this.ResourceId))) { WriteWarning("You are passing $null as a value for parameter ResourceId 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.ScalableDimension = this.ScalableDimension; #if MODULAR if (this.ScalableDimension == null && ParameterWasBound(nameof(this.ScalableDimension))) { WriteWarning("You are passing $null as a value for parameter ScalableDimension 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.ScalableTargetAction_MaxCapacity = this.ScalableTargetAction_MaxCapacity; context.ScalableTargetAction_MinCapacity = this.ScalableTargetAction_MinCapacity; context.Schedule = this.Schedule; 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.ServiceNamespace = this.ServiceNamespace; #if MODULAR if (this.ServiceNamespace == null && ParameterWasBound(nameof(this.ServiceNamespace))) { WriteWarning("You are passing $null as a value for parameter ServiceNamespace 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.StartTime = this.StartTime; context.Timezone = this.Timezone; // 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.ApplicationAutoScaling.Model.PutScheduledActionRequest(); if (cmdletContext.EndTime != null) { request.EndTime = cmdletContext.EndTime.Value; } if (cmdletContext.ResourceId != null) { request.ResourceId = cmdletContext.ResourceId; } if (cmdletContext.ScalableDimension != null) { request.ScalableDimension = cmdletContext.ScalableDimension; } // populate ScalableTargetAction var requestScalableTargetActionIsNull = true; request.ScalableTargetAction = new Amazon.ApplicationAutoScaling.Model.ScalableTargetAction(); System.Int32? requestScalableTargetAction_scalableTargetAction_MaxCapacity = null; if (cmdletContext.ScalableTargetAction_MaxCapacity != null) { requestScalableTargetAction_scalableTargetAction_MaxCapacity = cmdletContext.ScalableTargetAction_MaxCapacity.Value; } if (requestScalableTargetAction_scalableTargetAction_MaxCapacity != null) { request.ScalableTargetAction.MaxCapacity = requestScalableTargetAction_scalableTargetAction_MaxCapacity.Value; requestScalableTargetActionIsNull = false; } System.Int32? requestScalableTargetAction_scalableTargetAction_MinCapacity = null; if (cmdletContext.ScalableTargetAction_MinCapacity != null) { requestScalableTargetAction_scalableTargetAction_MinCapacity = cmdletContext.ScalableTargetAction_MinCapacity.Value; } if (requestScalableTargetAction_scalableTargetAction_MinCapacity != null) { request.ScalableTargetAction.MinCapacity = requestScalableTargetAction_scalableTargetAction_MinCapacity.Value; requestScalableTargetActionIsNull = false; } // determine if request.ScalableTargetAction should be set to null if (requestScalableTargetActionIsNull) { request.ScalableTargetAction = null; } if (cmdletContext.Schedule != null) { request.Schedule = cmdletContext.Schedule; } if (cmdletContext.ScheduledActionName != null) { request.ScheduledActionName = cmdletContext.ScheduledActionName; } if (cmdletContext.ServiceNamespace != null) { request.ServiceNamespace = cmdletContext.ServiceNamespace; } if (cmdletContext.StartTime != null) { request.StartTime = cmdletContext.StartTime.Value; } if (cmdletContext.Timezone != null) { request.Timezone = cmdletContext.Timezone; } 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.ApplicationAutoScaling.Model.PutScheduledActionResponse CallAWSServiceOperation(IAmazonApplicationAutoScaling client, Amazon.ApplicationAutoScaling.Model.PutScheduledActionRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Application Auto Scaling", "PutScheduledAction"); try { #if DESKTOP return client.PutScheduledAction(request); #elif CORECLR return client.PutScheduledActionAsync(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.DateTime? EndTime { get; set; } public System.String ResourceId { get; set; } public Amazon.ApplicationAutoScaling.ScalableDimension ScalableDimension { get; set; } public System.Int32? ScalableTargetAction_MaxCapacity { get; set; } public System.Int32? ScalableTargetAction_MinCapacity { get; set; } public System.String Schedule { get; set; } public System.String ScheduledActionName { get; set; } public Amazon.ApplicationAutoScaling.ServiceNamespace ServiceNamespace { get; set; } public System.DateTime? StartTime { get; set; } public System.String Timezone { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => null; } } }