/*******************************************************************************
* 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.ECS;
using Amazon.ECS.Model;
namespace Amazon.PowerShell.Cmdlets.ECS
{
///
/// Create a task set in the specified cluster and service. This is used when a service
/// uses the EXTERNAL
deployment controller type. For more information, see
/// Amazon
/// ECS deployment types in the Amazon Elastic Container Service Developer Guide.
///
[Cmdlet("New", "ECSTaskSet", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.ECS.Model.TaskSet")]
[AWSCmdlet("Calls the Amazon EC2 Container Service CreateTaskSet API operation.", Operation = new[] {"CreateTaskSet"}, SelectReturnType = typeof(Amazon.ECS.Model.CreateTaskSetResponse))]
[AWSCmdletOutput("Amazon.ECS.Model.TaskSet or Amazon.ECS.Model.CreateTaskSetResponse",
"This cmdlet returns an Amazon.ECS.Model.TaskSet object.",
"The service call response (type Amazon.ECS.Model.CreateTaskSetResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewECSTaskSetCmdlet : AmazonECSClientCmdlet, IExecutor
{
#region Parameter AwsvpcConfiguration_AssignPublicIp
///
///
/// Whether the task's elastic network interface receives a public IP address. The default
/// value is DISABLED
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("NetworkConfiguration_AwsvpcConfiguration_AssignPublicIp")]
[AWSConstantClassSource("Amazon.ECS.AssignPublicIp")]
public Amazon.ECS.AssignPublicIp AwsvpcConfiguration_AssignPublicIp { get; set; }
#endregion
#region Parameter CapacityProviderStrategy
///
///
/// The capacity provider strategy to use for the task set.A capacity provider strategy consists of one or more capacity providers along with
/// the base
and weight
to assign to them. A capacity provider
/// must be associated with the cluster to be used in a capacity provider strategy. The
/// PutClusterCapacityProviders API is used to associate a capacity provider with
/// a cluster. Only capacity providers with an ACTIVE
or UPDATING
/// status can be used.If a capacityProviderStrategy
is specified, the launchType
/// parameter must be omitted. If no capacityProviderStrategy
or launchType
/// is specified, the defaultCapacityProviderStrategy
for the cluster is
/// used.If specifying a capacity provider that uses an Auto Scaling group, the capacity provider
/// must already be created. New capacity providers can be created with the CreateCapacityProvider
/// API operation.To use a Fargate capacity provider, specify either the FARGATE
or FARGATE_SPOT
/// capacity providers. The Fargate capacity providers are available to all accounts and
/// only need to be associated with a cluster to be used.The PutClusterCapacityProviders API operation is used to update the list of
/// available capacity providers for a cluster after the cluster is created.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public Amazon.ECS.Model.CapacityProviderStrategyItem[] CapacityProviderStrategy { get; set; }
#endregion
#region Parameter Cluster
///
///
/// The short name or full Amazon Resource Name (ARN) of the cluster that hosts the service
/// to create the task set in.
///
///
#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 Cluster { get; set; }
#endregion
#region Parameter ExternalId
///
///
/// An optional non-unique tag that identifies this task set in external systems. If the
/// task set is associated with a service discovery registry, the tasks in this task set
/// will have the ECS_TASK_SET_EXTERNAL_ID
Cloud Map attribute set to the
/// provided value.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ExternalId { get; set; }
#endregion
#region Parameter LaunchType
///
///
/// The launch type that new tasks in the task set uses. For more information, see Amazon
/// ECS launch types in the Amazon Elastic Container Service Developer Guide.If a launchType
is specified, the capacityProviderStrategy
/// parameter must be omitted.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.ECS.LaunchType")]
public Amazon.ECS.LaunchType LaunchType { get; set; }
#endregion
#region Parameter LoadBalancer
///
///
/// A load balancer object representing the load balancer to use with the task set. The
/// supported load balancer types are either an Application Load Balancer or a Network
/// Load Balancer.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("LoadBalancers")]
public Amazon.ECS.Model.LoadBalancer[] LoadBalancer { get; set; }
#endregion
#region Parameter PlatformVersion
///
///
/// The platform version that the tasks in the task set uses. A platform version is specified
/// only for tasks using the Fargate launch type. If one isn't specified, the LATEST
/// platform version is used.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PlatformVersion { get; set; }
#endregion
#region Parameter AwsvpcConfiguration_SecurityGroup
///
///
/// The IDs of the security groups associated with the task or service. If you don't specify
/// a security group, the default security group for the VPC is used. There's a limit
/// of 5 security groups that can be specified per AwsVpcConfiguration
.All specified security groups must be from the same VPC.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("NetworkConfiguration_AwsvpcConfiguration_SecurityGroups")]
public System.String[] AwsvpcConfiguration_SecurityGroup { get; set; }
#endregion
#region Parameter Service
///
///
/// The short name or full Amazon Resource Name (ARN) of the service to create the task
/// set in.
///
///
#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 Service { get; set; }
#endregion
#region Parameter ServiceRegistry
///
///
/// The details of the service discovery registries to assign to this task set. For more
/// information, see Service
/// discovery.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("ServiceRegistries")]
public Amazon.ECS.Model.ServiceRegistry[] ServiceRegistry { get; set; }
#endregion
#region Parameter AwsvpcConfiguration_Subnet
///
///
/// The IDs of the subnets associated with the task or service. There's a limit of 16
/// subnets that can be specified per AwsVpcConfiguration
.All specified subnets must be from the same VPC.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("NetworkConfiguration_AwsvpcConfiguration_Subnets")]
public System.String[] AwsvpcConfiguration_Subnet { get; set; }
#endregion
#region Parameter Tag
///
///
/// The metadata that you apply to the task set to help you categorize and organize them.
/// Each tag consists of a key and an optional value. You define both. When a service
/// is deleted, the tags are deleted.The following basic restrictions apply to tags:- Maximum number of tags per resource - 50
- For each resource, each tag key must be unique, and each tag key can have only one
/// value.
- Maximum key length - 128 Unicode characters in UTF-8
- Maximum value length - 256 Unicode characters in UTF-8
- If your tagging schema is used across multiple services and resources, remember that
/// other services may have restrictions on allowed characters. Generally allowed characters
/// are: letters, numbers, and spaces representable in UTF-8, and the following characters:
/// + - = . _ : / @.
- Tag keys and values are case-sensitive.
- Do not use
aws:
, AWS:
, or any upper or lowercase combination
/// of such as a prefix for either keys or values as it is reserved for Amazon Web Services
/// use. You cannot edit or delete tag keys or values with this prefix. Tags with this
/// prefix do not count against your tags per resource limit.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.ECS.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter TaskDefinition
///
///
/// The task definition for the tasks in the task set to use.
///
///
#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 TaskDefinition { get; set; }
#endregion
#region Parameter Scale_Unit
///
///
/// The unit of measure for the scale value.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.ECS.ScaleUnit")]
public Amazon.ECS.ScaleUnit Scale_Unit { get; set; }
#endregion
#region Parameter Scale_Value
///
///
/// The value, specified as a percent total of a service's desiredCount
,
/// to scale the task set. Accepted values are numbers between 0 and 100.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Double? Scale_Value { get; set; }
#endregion
#region Parameter ClientToken
///
///
/// The identifier that you provide to ensure the idempotency of the request. It's case
/// sensitive and must be unique. It can be up to 32 ASCII characters are allowed.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ClientToken { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'TaskSet'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.ECS.Model.CreateTaskSetResponse).
/// Specifying the name of a property of type Amazon.ECS.Model.CreateTaskSetResponse will result in that property being returned.
/// 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; } = "TaskSet";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the Cluster parameter.
/// The -PassThru parameter is deprecated, use -Select '^Cluster' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Cluster' 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.Cluster), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-ECSTaskSet (CreateTaskSet)"))
{
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.Cluster;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (this.CapacityProviderStrategy != null)
{
context.CapacityProviderStrategy = new List(this.CapacityProviderStrategy);
}
context.ClientToken = this.ClientToken;
context.Cluster = this.Cluster;
#if MODULAR
if (this.Cluster == null && ParameterWasBound(nameof(this.Cluster)))
{
WriteWarning("You are passing $null as a value for parameter Cluster 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.ExternalId = this.ExternalId;
context.LaunchType = this.LaunchType;
if (this.LoadBalancer != null)
{
context.LoadBalancer = new List(this.LoadBalancer);
}
context.AwsvpcConfiguration_AssignPublicIp = this.AwsvpcConfiguration_AssignPublicIp;
if (this.AwsvpcConfiguration_SecurityGroup != null)
{
context.AwsvpcConfiguration_SecurityGroup = new List(this.AwsvpcConfiguration_SecurityGroup);
}
if (this.AwsvpcConfiguration_Subnet != null)
{
context.AwsvpcConfiguration_Subnet = new List(this.AwsvpcConfiguration_Subnet);
}
context.PlatformVersion = this.PlatformVersion;
context.Scale_Unit = this.Scale_Unit;
context.Scale_Value = this.Scale_Value;
context.Service = this.Service;
#if MODULAR
if (this.Service == null && ParameterWasBound(nameof(this.Service)))
{
WriteWarning("You are passing $null as a value for parameter Service 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
if (this.ServiceRegistry != null)
{
context.ServiceRegistry = new List(this.ServiceRegistry);
}
if (this.Tag != null)
{
context.Tag = new List(this.Tag);
}
context.TaskDefinition = this.TaskDefinition;
#if MODULAR
if (this.TaskDefinition == null && ParameterWasBound(nameof(this.TaskDefinition)))
{
WriteWarning("You are passing $null as a value for parameter TaskDefinition 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
// 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.ECS.Model.CreateTaskSetRequest();
if (cmdletContext.CapacityProviderStrategy != null)
{
request.CapacityProviderStrategy = cmdletContext.CapacityProviderStrategy;
}
if (cmdletContext.ClientToken != null)
{
request.ClientToken = cmdletContext.ClientToken;
}
if (cmdletContext.Cluster != null)
{
request.Cluster = cmdletContext.Cluster;
}
if (cmdletContext.ExternalId != null)
{
request.ExternalId = cmdletContext.ExternalId;
}
if (cmdletContext.LaunchType != null)
{
request.LaunchType = cmdletContext.LaunchType;
}
if (cmdletContext.LoadBalancer != null)
{
request.LoadBalancers = cmdletContext.LoadBalancer;
}
// populate NetworkConfiguration
var requestNetworkConfigurationIsNull = true;
request.NetworkConfiguration = new Amazon.ECS.Model.NetworkConfiguration();
Amazon.ECS.Model.AwsVpcConfiguration requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration = null;
// populate AwsvpcConfiguration
var requestNetworkConfiguration_networkConfiguration_AwsvpcConfigurationIsNull = true;
requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration = new Amazon.ECS.Model.AwsVpcConfiguration();
Amazon.ECS.AssignPublicIp requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_AssignPublicIp = null;
if (cmdletContext.AwsvpcConfiguration_AssignPublicIp != null)
{
requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_AssignPublicIp = cmdletContext.AwsvpcConfiguration_AssignPublicIp;
}
if (requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_AssignPublicIp != null)
{
requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration.AssignPublicIp = requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_AssignPublicIp;
requestNetworkConfiguration_networkConfiguration_AwsvpcConfigurationIsNull = false;
}
List requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_SecurityGroup = null;
if (cmdletContext.AwsvpcConfiguration_SecurityGroup != null)
{
requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_SecurityGroup = cmdletContext.AwsvpcConfiguration_SecurityGroup;
}
if (requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_SecurityGroup != null)
{
requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration.SecurityGroups = requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_SecurityGroup;
requestNetworkConfiguration_networkConfiguration_AwsvpcConfigurationIsNull = false;
}
List requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_Subnet = null;
if (cmdletContext.AwsvpcConfiguration_Subnet != null)
{
requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_Subnet = cmdletContext.AwsvpcConfiguration_Subnet;
}
if (requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_Subnet != null)
{
requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration.Subnets = requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration_awsvpcConfiguration_Subnet;
requestNetworkConfiguration_networkConfiguration_AwsvpcConfigurationIsNull = false;
}
// determine if requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration should be set to null
if (requestNetworkConfiguration_networkConfiguration_AwsvpcConfigurationIsNull)
{
requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration = null;
}
if (requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration != null)
{
request.NetworkConfiguration.AwsvpcConfiguration = requestNetworkConfiguration_networkConfiguration_AwsvpcConfiguration;
requestNetworkConfigurationIsNull = false;
}
// determine if request.NetworkConfiguration should be set to null
if (requestNetworkConfigurationIsNull)
{
request.NetworkConfiguration = null;
}
if (cmdletContext.PlatformVersion != null)
{
request.PlatformVersion = cmdletContext.PlatformVersion;
}
// populate Scale
var requestScaleIsNull = true;
request.Scale = new Amazon.ECS.Model.Scale();
Amazon.ECS.ScaleUnit requestScale_scale_Unit = null;
if (cmdletContext.Scale_Unit != null)
{
requestScale_scale_Unit = cmdletContext.Scale_Unit;
}
if (requestScale_scale_Unit != null)
{
request.Scale.Unit = requestScale_scale_Unit;
requestScaleIsNull = false;
}
System.Double? requestScale_scale_Value = null;
if (cmdletContext.Scale_Value != null)
{
requestScale_scale_Value = cmdletContext.Scale_Value.Value;
}
if (requestScale_scale_Value != null)
{
request.Scale.Value = requestScale_scale_Value.Value;
requestScaleIsNull = false;
}
// determine if request.Scale should be set to null
if (requestScaleIsNull)
{
request.Scale = null;
}
if (cmdletContext.Service != null)
{
request.Service = cmdletContext.Service;
}
if (cmdletContext.ServiceRegistry != null)
{
request.ServiceRegistries = cmdletContext.ServiceRegistry;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
if (cmdletContext.TaskDefinition != null)
{
request.TaskDefinition = cmdletContext.TaskDefinition;
}
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.ECS.Model.CreateTaskSetResponse CallAWSServiceOperation(IAmazonECS client, Amazon.ECS.Model.CreateTaskSetRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon EC2 Container Service", "CreateTaskSet");
try
{
#if DESKTOP
return client.CreateTaskSet(request);
#elif CORECLR
return client.CreateTaskSetAsync(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 List CapacityProviderStrategy { get; set; }
public System.String ClientToken { get; set; }
public System.String Cluster { get; set; }
public System.String ExternalId { get; set; }
public Amazon.ECS.LaunchType LaunchType { get; set; }
public List LoadBalancer { get; set; }
public Amazon.ECS.AssignPublicIp AwsvpcConfiguration_AssignPublicIp { get; set; }
public List AwsvpcConfiguration_SecurityGroup { get; set; }
public List AwsvpcConfiguration_Subnet { get; set; }
public System.String PlatformVersion { get; set; }
public Amazon.ECS.ScaleUnit Scale_Unit { get; set; }
public System.Double? Scale_Value { get; set; }
public System.String Service { get; set; }
public List ServiceRegistry { get; set; }
public List Tag { get; set; }
public System.String TaskDefinition { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.TaskSet;
}
}
}