/******************************************************************************* * 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.Drs; using Amazon.Drs.Model; namespace Amazon.PowerShell.Cmdlets.EDRS { /// <summary> /// Creates a new ReplicationConfigurationTemplate. /// </summary> [Cmdlet("New", "EDRSReplicationConfigurationTemplate", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.Drs.Model.CreateReplicationConfigurationTemplateResponse")] [AWSCmdlet("Calls the Elastic Disaster Recovery Service CreateReplicationConfigurationTemplate API operation.", Operation = new[] {"CreateReplicationConfigurationTemplate"}, SelectReturnType = typeof(Amazon.Drs.Model.CreateReplicationConfigurationTemplateResponse))] [AWSCmdletOutput("Amazon.Drs.Model.CreateReplicationConfigurationTemplateResponse", "This cmdlet returns an Amazon.Drs.Model.CreateReplicationConfigurationTemplateResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewEDRSReplicationConfigurationTemplateCmdlet : AmazonDrsClientCmdlet, IExecutor { protected override bool IsSensitiveRequest { get; set; } = true; protected override bool IsSensitiveResponse { get; set; } = true; #region Parameter AssociateDefaultSecurityGroup /// <summary> /// <para> /// <para>Whether to associate the default Elastic Disaster Recovery Security group with the /// Replication Configuration Template.</para> /// </para> /// </summary> #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.Boolean? AssociateDefaultSecurityGroup { get; set; } #endregion #region Parameter AutoReplicateNewDisk /// <summary> /// <para> /// <para>Whether to allow the AWS replication agent to automatically replicate newly added /// disks.</para> /// </para> /// </summary> [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("AutoReplicateNewDisks")] public System.Boolean? AutoReplicateNewDisk { get; set; } #endregion #region Parameter BandwidthThrottling /// <summary> /// <para> /// <para>Configure bandwidth throttling for the outbound data transfer rate of the Source Server /// in Mbps.</para> /// </para> /// </summary> #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.Int64? BandwidthThrottling { get; set; } #endregion #region Parameter CreatePublicIP /// <summary> /// <para> /// <para>Whether to create a Public IP for the Recovery Instance by default.</para> /// </para> /// </summary> #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.Boolean? CreatePublicIP { get; set; } #endregion #region Parameter DataPlaneRouting /// <summary> /// <para> /// <para>The data plane routing mechanism that will be used for replication.</para> /// </para> /// </summary> #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.Drs.ReplicationConfigurationDataPlaneRouting")] public Amazon.Drs.ReplicationConfigurationDataPlaneRouting DataPlaneRouting { get; set; } #endregion #region Parameter DefaultLargeStagingDiskType /// <summary> /// <para> /// <para>The Staging Disk EBS volume type to be used during replication.</para> /// </para> /// </summary> #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.Drs.ReplicationConfigurationDefaultLargeStagingDiskType")] public Amazon.Drs.ReplicationConfigurationDefaultLargeStagingDiskType DefaultLargeStagingDiskType { get; set; } #endregion #region Parameter EbsEncryption /// <summary> /// <para> /// <para>The type of EBS encryption to be used during replication.</para> /// </para> /// </summary> #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.Drs.ReplicationConfigurationEbsEncryption")] public Amazon.Drs.ReplicationConfigurationEbsEncryption EbsEncryption { get; set; } #endregion #region Parameter EbsEncryptionKeyArn /// <summary> /// <para> /// <para>The ARN of the EBS encryption key to be used during replication.</para> /// </para> /// </summary> [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String EbsEncryptionKeyArn { get; set; } #endregion #region Parameter PitPolicy /// <summary> /// <para> /// <para>The Point in time (PIT) policy to manage snapshots taken during replication.</para> /// </para> /// </summary> #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowEmptyCollection] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public Amazon.Drs.Model.PITPolicyRule[] PitPolicy { get; set; } #endregion #region Parameter ReplicationServerInstanceType /// <summary> /// <para> /// <para>The instance type to be used for the replication server.</para> /// </para> /// </summary> #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 ReplicationServerInstanceType { get; set; } #endregion #region Parameter ReplicationServersSecurityGroupsIDs /// <summary> /// <para> /// <para>The security group IDs that will be used by the replication server.</para> /// </para> /// </summary> #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowEmptyCollection] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public System.String[] ReplicationServersSecurityGroupsIDs { get; set; } #endregion #region Parameter StagingAreaSubnetId /// <summary> /// <para> /// <para>The subnet to be used by the replication staging area.</para> /// </para> /// </summary> #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 StagingAreaSubnetId { get; set; } #endregion #region Parameter StagingAreaTag /// <summary> /// <para> /// <para>A set of tags to be associated with all resources created in the replication staging /// area: EC2 replication server, EBS volumes, EBS snapshots, etc.</para> /// </para> /// </summary> #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowEmptyCollection] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] [Alias("StagingAreaTags")] public System.Collections.Hashtable StagingAreaTag { get; set; } #endregion #region Parameter Tag /// <summary> /// <para> /// <para>A set of tags to be associated with the Replication Configuration Template resource.</para> /// </para> /// </summary> [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public System.Collections.Hashtable Tag { get; set; } #endregion #region Parameter UseDedicatedReplicationServer /// <summary> /// <para> /// <para>Whether to use a dedicated Replication Server in the replication staging area.</para> /// </para> /// </summary> #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.Boolean? UseDedicatedReplicationServer { get; set; } #endregion #region Parameter Select /// <summary> /// 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.Drs.Model.CreateReplicationConfigurationTemplateResponse). /// Specifying the name of a property of type Amazon.Drs.Model.CreateReplicationConfigurationTemplateResponse will result in that property being returned. /// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value. /// </summary> [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public string Select { get; set; } = "*"; #endregion #region Parameter Force /// <summary> /// This parameter overrides confirmation prompts to force /// the cmdlet to continue its operation. This parameter should always /// be used with caution. /// </summary> [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.StagingAreaSubnetId), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-EDRSReplicationConfigurationTemplate (CreateReplicationConfigurationTemplate)")) { return; } var context = new CmdletContext(); // allow for manipulation of parameters prior to loading into context PreExecutionContextLoad(context); if (ParameterWasBound(nameof(this.Select))) { context.Select = CreateSelectDelegate<Amazon.Drs.Model.CreateReplicationConfigurationTemplateResponse, NewEDRSReplicationConfigurationTemplateCmdlet>(Select) ?? throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select)); } context.AssociateDefaultSecurityGroup = this.AssociateDefaultSecurityGroup; #if MODULAR if (this.AssociateDefaultSecurityGroup == null && ParameterWasBound(nameof(this.AssociateDefaultSecurityGroup))) { WriteWarning("You are passing $null as a value for parameter AssociateDefaultSecurityGroup 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.AutoReplicateNewDisk = this.AutoReplicateNewDisk; context.BandwidthThrottling = this.BandwidthThrottling; #if MODULAR if (this.BandwidthThrottling == null && ParameterWasBound(nameof(this.BandwidthThrottling))) { WriteWarning("You are passing $null as a value for parameter BandwidthThrottling 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.CreatePublicIP = this.CreatePublicIP; #if MODULAR if (this.CreatePublicIP == null && ParameterWasBound(nameof(this.CreatePublicIP))) { WriteWarning("You are passing $null as a value for parameter CreatePublicIP 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.DataPlaneRouting = this.DataPlaneRouting; #if MODULAR if (this.DataPlaneRouting == null && ParameterWasBound(nameof(this.DataPlaneRouting))) { WriteWarning("You are passing $null as a value for parameter DataPlaneRouting 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.DefaultLargeStagingDiskType = this.DefaultLargeStagingDiskType; #if MODULAR if (this.DefaultLargeStagingDiskType == null && ParameterWasBound(nameof(this.DefaultLargeStagingDiskType))) { WriteWarning("You are passing $null as a value for parameter DefaultLargeStagingDiskType 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.EbsEncryption = this.EbsEncryption; #if MODULAR if (this.EbsEncryption == null && ParameterWasBound(nameof(this.EbsEncryption))) { WriteWarning("You are passing $null as a value for parameter EbsEncryption 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.EbsEncryptionKeyArn = this.EbsEncryptionKeyArn; if (this.PitPolicy != null) { context.PitPolicy = new List<Amazon.Drs.Model.PITPolicyRule>(this.PitPolicy); } #if MODULAR if (this.PitPolicy == null && ParameterWasBound(nameof(this.PitPolicy))) { WriteWarning("You are passing $null as a value for parameter PitPolicy 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.ReplicationServerInstanceType = this.ReplicationServerInstanceType; #if MODULAR if (this.ReplicationServerInstanceType == null && ParameterWasBound(nameof(this.ReplicationServerInstanceType))) { WriteWarning("You are passing $null as a value for parameter ReplicationServerInstanceType 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.ReplicationServersSecurityGroupsIDs != null) { context.ReplicationServersSecurityGroupsIDs = new List<System.String>(this.ReplicationServersSecurityGroupsIDs); } #if MODULAR if (this.ReplicationServersSecurityGroupsIDs == null && ParameterWasBound(nameof(this.ReplicationServersSecurityGroupsIDs))) { WriteWarning("You are passing $null as a value for parameter ReplicationServersSecurityGroupsIDs 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.StagingAreaSubnetId = this.StagingAreaSubnetId; #if MODULAR if (this.StagingAreaSubnetId == null && ParameterWasBound(nameof(this.StagingAreaSubnetId))) { WriteWarning("You are passing $null as a value for parameter StagingAreaSubnetId 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.StagingAreaTag != null) { context.StagingAreaTag = new Dictionary<System.String, System.String>(StringComparer.Ordinal); foreach (var hashKey in this.StagingAreaTag.Keys) { context.StagingAreaTag.Add((String)hashKey, (String)(this.StagingAreaTag[hashKey])); } } #if MODULAR if (this.StagingAreaTag == null && ParameterWasBound(nameof(this.StagingAreaTag))) { WriteWarning("You are passing $null as a value for parameter StagingAreaTag 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 Dictionary<System.String, System.String>(StringComparer.Ordinal); foreach (var hashKey in this.Tag.Keys) { context.Tag.Add((String)hashKey, (String)(this.Tag[hashKey])); } } context.UseDedicatedReplicationServer = this.UseDedicatedReplicationServer; #if MODULAR if (this.UseDedicatedReplicationServer == null && ParameterWasBound(nameof(this.UseDedicatedReplicationServer))) { WriteWarning("You are passing $null as a value for parameter UseDedicatedReplicationServer 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.Drs.Model.CreateReplicationConfigurationTemplateRequest(); if (cmdletContext.AssociateDefaultSecurityGroup != null) { request.AssociateDefaultSecurityGroup = cmdletContext.AssociateDefaultSecurityGroup.Value; } if (cmdletContext.AutoReplicateNewDisk != null) { request.AutoReplicateNewDisks = cmdletContext.AutoReplicateNewDisk.Value; } if (cmdletContext.BandwidthThrottling != null) { request.BandwidthThrottling = cmdletContext.BandwidthThrottling.Value; } if (cmdletContext.CreatePublicIP != null) { request.CreatePublicIP = cmdletContext.CreatePublicIP.Value; } if (cmdletContext.DataPlaneRouting != null) { request.DataPlaneRouting = cmdletContext.DataPlaneRouting; } if (cmdletContext.DefaultLargeStagingDiskType != null) { request.DefaultLargeStagingDiskType = cmdletContext.DefaultLargeStagingDiskType; } if (cmdletContext.EbsEncryption != null) { request.EbsEncryption = cmdletContext.EbsEncryption; } if (cmdletContext.EbsEncryptionKeyArn != null) { request.EbsEncryptionKeyArn = cmdletContext.EbsEncryptionKeyArn; } if (cmdletContext.PitPolicy != null) { request.PitPolicy = cmdletContext.PitPolicy; } if (cmdletContext.ReplicationServerInstanceType != null) { request.ReplicationServerInstanceType = cmdletContext.ReplicationServerInstanceType; } if (cmdletContext.ReplicationServersSecurityGroupsIDs != null) { request.ReplicationServersSecurityGroupsIDs = cmdletContext.ReplicationServersSecurityGroupsIDs; } if (cmdletContext.StagingAreaSubnetId != null) { request.StagingAreaSubnetId = cmdletContext.StagingAreaSubnetId; } if (cmdletContext.StagingAreaTag != null) { request.StagingAreaTags = cmdletContext.StagingAreaTag; } if (cmdletContext.Tag != null) { request.Tags = cmdletContext.Tag; } if (cmdletContext.UseDedicatedReplicationServer != null) { request.UseDedicatedReplicationServer = cmdletContext.UseDedicatedReplicationServer.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.Drs.Model.CreateReplicationConfigurationTemplateResponse CallAWSServiceOperation(IAmazonDrs client, Amazon.Drs.Model.CreateReplicationConfigurationTemplateRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Elastic Disaster Recovery Service", "CreateReplicationConfigurationTemplate"); try { #if DESKTOP return client.CreateReplicationConfigurationTemplate(request); #elif CORECLR return client.CreateReplicationConfigurationTemplateAsync(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.Boolean? AssociateDefaultSecurityGroup { get; set; } public System.Boolean? AutoReplicateNewDisk { get; set; } public System.Int64? BandwidthThrottling { get; set; } public System.Boolean? CreatePublicIP { get; set; } public Amazon.Drs.ReplicationConfigurationDataPlaneRouting DataPlaneRouting { get; set; } public Amazon.Drs.ReplicationConfigurationDefaultLargeStagingDiskType DefaultLargeStagingDiskType { get; set; } public Amazon.Drs.ReplicationConfigurationEbsEncryption EbsEncryption { get; set; } public System.String EbsEncryptionKeyArn { get; set; } public List<Amazon.Drs.Model.PITPolicyRule> PitPolicy { get; set; } public System.String ReplicationServerInstanceType { get; set; } public List<System.String> ReplicationServersSecurityGroupsIDs { get; set; } public System.String StagingAreaSubnetId { get; set; } public Dictionary<System.String, System.String> StagingAreaTag { get; set; } public Dictionary<System.String, System.String> Tag { get; set; } public System.Boolean? UseDedicatedReplicationServer { get; set; } public System.Func<Amazon.Drs.Model.CreateReplicationConfigurationTemplateResponse, NewEDRSReplicationConfigurationTemplateCmdlet, object> Select { get; set; } = (response, cmdlet) => response; } } }