/******************************************************************************* * 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.DirectConnect; using Amazon.DirectConnect.Model; namespace Amazon.PowerShell.Cmdlets.DC { /// /// Creates a hosted connection on the specified interconnect or a link aggregation group /// (LAG) of interconnects. /// /// /// /// Allocates a VLAN number and a specified amount of capacity (bandwidth) for use by /// a hosted connection on the specified interconnect or LAG of interconnects. Amazon /// Web Services polices the hosted connection for the specified capacity and the Direct /// Connect Partner must also police the hosted connection for the specified capacity. /// /// Intended for use by Direct Connect Partners only. /// /// [Cmdlet("New", "DCHostedConnection", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.DirectConnect.Model.AllocateHostedConnectionResponse")] [AWSCmdlet("Calls the AWS Direct Connect AllocateHostedConnection API operation.", Operation = new[] {"AllocateHostedConnection"}, SelectReturnType = typeof(Amazon.DirectConnect.Model.AllocateHostedConnectionResponse))] [AWSCmdletOutput("Amazon.DirectConnect.Model.AllocateHostedConnectionResponse", "This cmdlet returns an Amazon.DirectConnect.Model.AllocateHostedConnectionResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewDCHostedConnectionCmdlet : AmazonDirectConnectClientCmdlet, IExecutor { #region Parameter Bandwidth /// /// /// The bandwidth of the connection. The possible values are 50Mbps, 100Mbps, 200Mbps, /// 300Mbps, 400Mbps, 500Mbps, 1Gbps, 2Gbps, 5Gbps, and 10Gbps. Note that only those Direct /// Connect Partners who have met specific requirements are allowed to create a 1Gbps, /// 2Gbps, 5Gbps or 10Gbps hosted connection. /// /// #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 Bandwidth { get; set; } #endregion #region Parameter ConnectionId /// /// /// The ID of the interconnect or LAG. /// /// #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 ConnectionId { get; set; } #endregion #region Parameter ConnectionName /// /// /// The name of the hosted connection. /// /// #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 ConnectionName { get; set; } #endregion #region Parameter OwnerAccount /// /// /// The ID of the Amazon Web Services account ID of the customer for the connection. /// /// #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 OwnerAccount { get; set; } #endregion #region Parameter Tag /// /// /// The tags associated with the connection. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.DirectConnect.Model.Tag[] Tag { get; set; } #endregion #region Parameter Vlan /// /// /// The dedicated VLAN provisioned to the hosted connection. /// /// #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] public System.Int32? Vlan { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is '*'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.DirectConnect.Model.AllocateHostedConnectionResponse). /// Specifying the name of a property of type Amazon.DirectConnect.Model.AllocateHostedConnectionResponse 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; } = "*"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the ConnectionId parameter. /// The -PassThru parameter is deprecated, use -Select '^ConnectionId' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ConnectionId' 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.ConnectionId), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-DCHostedConnection (AllocateHostedConnection)")) { 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.ConnectionId; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.Bandwidth = this.Bandwidth; #if MODULAR if (this.Bandwidth == null && ParameterWasBound(nameof(this.Bandwidth))) { WriteWarning("You are passing $null as a value for parameter Bandwidth 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.ConnectionId = this.ConnectionId; #if MODULAR if (this.ConnectionId == null && ParameterWasBound(nameof(this.ConnectionId))) { WriteWarning("You are passing $null as a value for parameter ConnectionId 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.ConnectionName = this.ConnectionName; #if MODULAR if (this.ConnectionName == null && ParameterWasBound(nameof(this.ConnectionName))) { WriteWarning("You are passing $null as a value for parameter ConnectionName 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.OwnerAccount = this.OwnerAccount; #if MODULAR if (this.OwnerAccount == null && ParameterWasBound(nameof(this.OwnerAccount))) { WriteWarning("You are passing $null as a value for parameter OwnerAccount 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.Tag != null) { context.Tag = new List(this.Tag); } context.Vlan = this.Vlan; #if MODULAR if (this.Vlan == null && ParameterWasBound(nameof(this.Vlan))) { WriteWarning("You are passing $null as a value for parameter Vlan 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.DirectConnect.Model.AllocateHostedConnectionRequest(); if (cmdletContext.Bandwidth != null) { request.Bandwidth = cmdletContext.Bandwidth; } if (cmdletContext.ConnectionId != null) { request.ConnectionId = cmdletContext.ConnectionId; } if (cmdletContext.ConnectionName != null) { request.ConnectionName = cmdletContext.ConnectionName; } if (cmdletContext.OwnerAccount != null) { request.OwnerAccount = cmdletContext.OwnerAccount; } if (cmdletContext.Tag != null) { request.Tags = cmdletContext.Tag; } if (cmdletContext.Vlan != null) { request.Vlan = cmdletContext.Vlan.Value; } 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.DirectConnect.Model.AllocateHostedConnectionResponse CallAWSServiceOperation(IAmazonDirectConnect client, Amazon.DirectConnect.Model.AllocateHostedConnectionRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Direct Connect", "AllocateHostedConnection"); try { #if DESKTOP return client.AllocateHostedConnection(request); #elif CORECLR return client.AllocateHostedConnectionAsync(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 Bandwidth { get; set; } public System.String ConnectionId { get; set; } public System.String ConnectionName { get; set; } public System.String OwnerAccount { get; set; } public List Tag { get; set; } public System.Int32? Vlan { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response; } } }