/*******************************************************************************
* 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.Neptune;
using Amazon.Neptune.Model;
namespace Amazon.PowerShell.Cmdlets.NPT
{
///
/// Creates a new DB cluster from a DB snapshot or DB cluster snapshot.
///
///
///
/// If a DB snapshot is specified, the target DB cluster is created from the source DB
/// snapshot with a default configuration and default security group.
///
/// If a DB cluster snapshot is specified, the target DB cluster is created from the source
/// DB cluster restore point with the same configuration as the original source DB cluster,
/// except that the new DB cluster is created with the default security group.
///
///
[Cmdlet("Restore", "NPTDBClusterFromSnapshot", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.Neptune.Model.DBCluster")]
[AWSCmdlet("Calls the Amazon Neptune RestoreDBClusterFromSnapshot API operation.", Operation = new[] {"RestoreDBClusterFromSnapshot"}, SelectReturnType = typeof(Amazon.Neptune.Model.RestoreDBClusterFromSnapshotResponse))]
[AWSCmdletOutput("Amazon.Neptune.Model.DBCluster or Amazon.Neptune.Model.RestoreDBClusterFromSnapshotResponse",
"This cmdlet returns an Amazon.Neptune.Model.DBCluster object.",
"The service call response (type Amazon.Neptune.Model.RestoreDBClusterFromSnapshotResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class RestoreNPTDBClusterFromSnapshotCmdlet : AmazonNeptuneClientCmdlet, IExecutor
{
#region Parameter AvailabilityZone
///
///
/// Provides the list of EC2 Availability Zones that instances in the restored DB cluster
/// can be created in.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("AvailabilityZones")]
public System.String[] AvailabilityZone { get; set; }
#endregion
#region Parameter CopyTagsToSnapshot
///
///
/// If set to true
, tags are copied to any snapshot of the restored DB
/// cluster that is created.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? CopyTagsToSnapshot { get; set; }
#endregion
#region Parameter DatabaseName
///
///
/// Not supported.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String DatabaseName { get; set; }
#endregion
#region Parameter DBClusterIdentifier
///
///
/// The name of the DB cluster to create from the DB snapshot or DB cluster snapshot.
/// This parameter isn't case-sensitive.Constraints:- Must contain from 1 to 63 letters, numbers, or hyphens
- First character must be a letter
- Cannot end with a hyphen or contain two consecutive hyphens
Example: my-snapshot-id
///
///
#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 DBClusterIdentifier { get; set; }
#endregion
#region Parameter DBClusterParameterGroupName
///
///
/// The name of the DB cluster parameter group to associate with the new DB cluster.Constraints:- If supplied, must match the name of an existing DBClusterParameterGroup.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String DBClusterParameterGroupName { get; set; }
#endregion
#region Parameter DBSubnetGroupName
///
///
/// The name of the DB subnet group to use for the new DB cluster.Constraints: If supplied, must match the name of an existing DBSubnetGroup.Example: mySubnetgroup
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String DBSubnetGroupName { get; set; }
#endregion
#region Parameter DeletionProtection
///
///
/// A value that indicates whether the DB cluster has deletion protection enabled. The
/// database can't be deleted when deletion protection is enabled. By default, deletion
/// protection is disabled.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? DeletionProtection { get; set; }
#endregion
#region Parameter EnableCloudwatchLogsExport
///
///
/// The list of logs that the restored DB cluster is to export to Amazon CloudWatch Logs.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("EnableCloudwatchLogsExports")]
public System.String[] EnableCloudwatchLogsExport { get; set; }
#endregion
#region Parameter EnableIAMDatabaseAuthentication
///
///
/// True to enable mapping of Amazon Identity and Access Management (IAM) accounts to
/// database accounts, and otherwise false.Default: false
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? EnableIAMDatabaseAuthentication { get; set; }
#endregion
#region Parameter Engine
///
///
/// The database engine to use for the new DB cluster.Default: The same as sourceConstraint: Must be compatible with the engine of the source
///
///
#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 Engine { get; set; }
#endregion
#region Parameter EngineVersion
///
///
/// The version of the database engine to use for the new DB cluster.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String EngineVersion { get; set; }
#endregion
#region Parameter KmsKeyId
///
///
/// The Amazon KMS key identifier to use when restoring an encrypted DB cluster from a
/// DB snapshot or DB cluster snapshot.The KMS key identifier is the Amazon Resource Name (ARN) for the KMS encryption key.
/// If you are restoring a DB cluster with the same Amazon account that owns the KMS encryption
/// key used to encrypt the new DB cluster, then you can use the KMS key alias instead
/// of the ARN for the KMS encryption key.If you do not specify a value for the KmsKeyId
parameter, then the following
/// will occur:- If the DB snapshot or DB cluster snapshot in
SnapshotIdentifier
is encrypted,
/// then the restored DB cluster is encrypted using the KMS key that was used to encrypt
/// the DB snapshot or DB cluster snapshot. - If the DB snapshot or DB cluster snapshot in
SnapshotIdentifier
is not
/// encrypted, then the restored DB cluster is not encrypted.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String KmsKeyId { get; set; }
#endregion
#region Parameter ServerlessV2ScalingConfiguration_MaxCapacity
///
///
/// The maximum number of Neptune capacity units (NCUs) for a DB instance in a Neptune
/// Serverless cluster. You can specify NCU values in half-step increments, such as 40,
/// 40.5, 41, and so on.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Double? ServerlessV2ScalingConfiguration_MaxCapacity { get; set; }
#endregion
#region Parameter ServerlessV2ScalingConfiguration_MinCapacity
///
///
/// The minimum number of Neptune capacity units (NCUs) for a DB instance in a Neptune
/// Serverless cluster. You can specify NCU values in half-step increments, such as 8,
/// 8.5, 9, and so on.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Double? ServerlessV2ScalingConfiguration_MinCapacity { get; set; }
#endregion
#region Parameter OptionGroupName
///
///
/// (Not supported by Neptune)
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String OptionGroupName { get; set; }
#endregion
#region Parameter Port
///
///
/// The port number on which the new DB cluster accepts connections.Constraints: Value must be 1150-65535
Default: The same port as the original DB cluster.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? Port { get; set; }
#endregion
#region Parameter SnapshotIdentifier
///
///
/// The identifier for the DB snapshot or DB cluster snapshot to restore from.You can use either the name or the Amazon Resource Name (ARN) to specify a DB cluster
/// snapshot. However, you can use only the ARN to specify a DB snapshot.Constraints:- Must match the identifier of an existing Snapshot.
///
///
#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 SnapshotIdentifier { get; set; }
#endregion
#region Parameter Tag
///
///
/// The tags to be assigned to the restored DB cluster.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.Neptune.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter VpcSecurityGroupId
///
///
/// A list of VPC security groups that the new DB cluster will belong to.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("VpcSecurityGroupIds")]
public System.String[] VpcSecurityGroupId { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'DBCluster'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Neptune.Model.RestoreDBClusterFromSnapshotResponse).
/// Specifying the name of a property of type Amazon.Neptune.Model.RestoreDBClusterFromSnapshotResponse 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; } = "DBCluster";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the DBClusterIdentifier parameter.
/// The -PassThru parameter is deprecated, use -Select '^DBClusterIdentifier' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^DBClusterIdentifier' 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.DBClusterIdentifier), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Restore-NPTDBClusterFromSnapshot (RestoreDBClusterFromSnapshot)"))
{
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.DBClusterIdentifier;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (this.AvailabilityZone != null)
{
context.AvailabilityZone = new List(this.AvailabilityZone);
}
context.CopyTagsToSnapshot = this.CopyTagsToSnapshot;
context.DatabaseName = this.DatabaseName;
context.DBClusterIdentifier = this.DBClusterIdentifier;
#if MODULAR
if (this.DBClusterIdentifier == null && ParameterWasBound(nameof(this.DBClusterIdentifier)))
{
WriteWarning("You are passing $null as a value for parameter DBClusterIdentifier 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.DBClusterParameterGroupName = this.DBClusterParameterGroupName;
context.DBSubnetGroupName = this.DBSubnetGroupName;
context.DeletionProtection = this.DeletionProtection;
if (this.EnableCloudwatchLogsExport != null)
{
context.EnableCloudwatchLogsExport = new List(this.EnableCloudwatchLogsExport);
}
context.EnableIAMDatabaseAuthentication = this.EnableIAMDatabaseAuthentication;
context.Engine = this.Engine;
#if MODULAR
if (this.Engine == null && ParameterWasBound(nameof(this.Engine)))
{
WriteWarning("You are passing $null as a value for parameter Engine 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.EngineVersion = this.EngineVersion;
context.KmsKeyId = this.KmsKeyId;
context.OptionGroupName = this.OptionGroupName;
context.Port = this.Port;
context.ServerlessV2ScalingConfiguration_MaxCapacity = this.ServerlessV2ScalingConfiguration_MaxCapacity;
context.ServerlessV2ScalingConfiguration_MinCapacity = this.ServerlessV2ScalingConfiguration_MinCapacity;
context.SnapshotIdentifier = this.SnapshotIdentifier;
#if MODULAR
if (this.SnapshotIdentifier == null && ParameterWasBound(nameof(this.SnapshotIdentifier)))
{
WriteWarning("You are passing $null as a value for parameter SnapshotIdentifier 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);
}
if (this.VpcSecurityGroupId != null)
{
context.VpcSecurityGroupId = new List(this.VpcSecurityGroupId);
}
// 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.Neptune.Model.RestoreDBClusterFromSnapshotRequest();
if (cmdletContext.AvailabilityZone != null)
{
request.AvailabilityZones = cmdletContext.AvailabilityZone;
}
if (cmdletContext.CopyTagsToSnapshot != null)
{
request.CopyTagsToSnapshot = cmdletContext.CopyTagsToSnapshot.Value;
}
if (cmdletContext.DatabaseName != null)
{
request.DatabaseName = cmdletContext.DatabaseName;
}
if (cmdletContext.DBClusterIdentifier != null)
{
request.DBClusterIdentifier = cmdletContext.DBClusterIdentifier;
}
if (cmdletContext.DBClusterParameterGroupName != null)
{
request.DBClusterParameterGroupName = cmdletContext.DBClusterParameterGroupName;
}
if (cmdletContext.DBSubnetGroupName != null)
{
request.DBSubnetGroupName = cmdletContext.DBSubnetGroupName;
}
if (cmdletContext.DeletionProtection != null)
{
request.DeletionProtection = cmdletContext.DeletionProtection.Value;
}
if (cmdletContext.EnableCloudwatchLogsExport != null)
{
request.EnableCloudwatchLogsExports = cmdletContext.EnableCloudwatchLogsExport;
}
if (cmdletContext.EnableIAMDatabaseAuthentication != null)
{
request.EnableIAMDatabaseAuthentication = cmdletContext.EnableIAMDatabaseAuthentication.Value;
}
if (cmdletContext.Engine != null)
{
request.Engine = cmdletContext.Engine;
}
if (cmdletContext.EngineVersion != null)
{
request.EngineVersion = cmdletContext.EngineVersion;
}
if (cmdletContext.KmsKeyId != null)
{
request.KmsKeyId = cmdletContext.KmsKeyId;
}
if (cmdletContext.OptionGroupName != null)
{
request.OptionGroupName = cmdletContext.OptionGroupName;
}
if (cmdletContext.Port != null)
{
request.Port = cmdletContext.Port.Value;
}
// populate ServerlessV2ScalingConfiguration
var requestServerlessV2ScalingConfigurationIsNull = true;
request.ServerlessV2ScalingConfiguration = new Amazon.Neptune.Model.ServerlessV2ScalingConfiguration();
System.Double? requestServerlessV2ScalingConfiguration_serverlessV2ScalingConfiguration_MaxCapacity = null;
if (cmdletContext.ServerlessV2ScalingConfiguration_MaxCapacity != null)
{
requestServerlessV2ScalingConfiguration_serverlessV2ScalingConfiguration_MaxCapacity = cmdletContext.ServerlessV2ScalingConfiguration_MaxCapacity.Value;
}
if (requestServerlessV2ScalingConfiguration_serverlessV2ScalingConfiguration_MaxCapacity != null)
{
request.ServerlessV2ScalingConfiguration.MaxCapacity = requestServerlessV2ScalingConfiguration_serverlessV2ScalingConfiguration_MaxCapacity.Value;
requestServerlessV2ScalingConfigurationIsNull = false;
}
System.Double? requestServerlessV2ScalingConfiguration_serverlessV2ScalingConfiguration_MinCapacity = null;
if (cmdletContext.ServerlessV2ScalingConfiguration_MinCapacity != null)
{
requestServerlessV2ScalingConfiguration_serverlessV2ScalingConfiguration_MinCapacity = cmdletContext.ServerlessV2ScalingConfiguration_MinCapacity.Value;
}
if (requestServerlessV2ScalingConfiguration_serverlessV2ScalingConfiguration_MinCapacity != null)
{
request.ServerlessV2ScalingConfiguration.MinCapacity = requestServerlessV2ScalingConfiguration_serverlessV2ScalingConfiguration_MinCapacity.Value;
requestServerlessV2ScalingConfigurationIsNull = false;
}
// determine if request.ServerlessV2ScalingConfiguration should be set to null
if (requestServerlessV2ScalingConfigurationIsNull)
{
request.ServerlessV2ScalingConfiguration = null;
}
if (cmdletContext.SnapshotIdentifier != null)
{
request.SnapshotIdentifier = cmdletContext.SnapshotIdentifier;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
if (cmdletContext.VpcSecurityGroupId != null)
{
request.VpcSecurityGroupIds = cmdletContext.VpcSecurityGroupId;
}
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.Neptune.Model.RestoreDBClusterFromSnapshotResponse CallAWSServiceOperation(IAmazonNeptune client, Amazon.Neptune.Model.RestoreDBClusterFromSnapshotRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Neptune", "RestoreDBClusterFromSnapshot");
try
{
#if DESKTOP
return client.RestoreDBClusterFromSnapshot(request);
#elif CORECLR
return client.RestoreDBClusterFromSnapshotAsync(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 AvailabilityZone { get; set; }
public System.Boolean? CopyTagsToSnapshot { get; set; }
public System.String DatabaseName { get; set; }
public System.String DBClusterIdentifier { get; set; }
public System.String DBClusterParameterGroupName { get; set; }
public System.String DBSubnetGroupName { get; set; }
public System.Boolean? DeletionProtection { get; set; }
public List EnableCloudwatchLogsExport { get; set; }
public System.Boolean? EnableIAMDatabaseAuthentication { get; set; }
public System.String Engine { get; set; }
public System.String EngineVersion { get; set; }
public System.String KmsKeyId { get; set; }
public System.String OptionGroupName { get; set; }
public System.Int32? Port { get; set; }
public System.Double? ServerlessV2ScalingConfiguration_MaxCapacity { get; set; }
public System.Double? ServerlessV2ScalingConfiguration_MinCapacity { get; set; }
public System.String SnapshotIdentifier { get; set; }
public List Tag { get; set; }
public List VpcSecurityGroupId { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.DBCluster;
}
}
}