/******************************************************************************* * 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.Lightsail; using Amazon.Lightsail.Model; namespace Amazon.PowerShell.Cmdlets.LS { /// /// Creates a new database from an existing database snapshot in Amazon Lightsail. /// /// /// /// You can create a new database from a snapshot in if something goes wrong with your /// original database, or to change it to a different plan, such as a high availability /// or standard plan. /// /// The create relational database from snapshot operation supports tag-based /// access control via request tags and resource tags applied to the resource identified /// by relationalDatabaseSnapshotName. For more information, see the Amazon /// Lightsail Developer Guide. /// /// [Cmdlet("New", "LSRelationalDatabaseFromSnapshot", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.Lightsail.Model.Operation")] [AWSCmdlet("Calls the Amazon Lightsail CreateRelationalDatabaseFromSnapshot API operation.", Operation = new[] {"CreateRelationalDatabaseFromSnapshot"}, SelectReturnType = typeof(Amazon.Lightsail.Model.CreateRelationalDatabaseFromSnapshotResponse))] [AWSCmdletOutput("Amazon.Lightsail.Model.Operation or Amazon.Lightsail.Model.CreateRelationalDatabaseFromSnapshotResponse", "This cmdlet returns a collection of Amazon.Lightsail.Model.Operation objects.", "The service call response (type Amazon.Lightsail.Model.CreateRelationalDatabaseFromSnapshotResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewLSRelationalDatabaseFromSnapshotCmdlet : AmazonLightsailClientCmdlet, IExecutor { #region Parameter AvailabilityZone /// /// /// The Availability Zone in which to create your new database. Use the us-east-2a /// case-sensitive format.You can get a list of Availability Zones by using the get regions operation. /// Be sure to add the include relational database Availability Zones parameter /// to your request. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String AvailabilityZone { get; set; } #endregion #region Parameter PubliclyAccessible /// /// /// Specifies the accessibility options for your new database. A value of true /// specifies a database that is available to resources outside of your Lightsail account. /// A value of false specifies a database that is available only to your /// Lightsail resources in the same region as your database. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? PubliclyAccessible { get; set; } #endregion #region Parameter RelationalDatabaseBundleId /// /// /// The bundle ID for your new database. A bundle describes the performance specifications /// for your database.You can get a list of database bundle IDs by using the get relational database /// bundles operation.When creating a new database from a snapshot, you cannot choose a bundle that is smaller /// than the bundle of the source database. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String RelationalDatabaseBundleId { get; set; } #endregion #region Parameter RelationalDatabaseName /// /// /// The name to use for your new Lightsail database resource.Constraints: /// /// #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 RelationalDatabaseName { get; set; } #endregion #region Parameter RelationalDatabaseSnapshotName /// /// /// The name of the database snapshot from which to create your new database. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String RelationalDatabaseSnapshotName { get; set; } #endregion #region Parameter RestoreTime /// /// /// The date and time to restore your database from.Constraints: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.DateTime? RestoreTime { get; set; } #endregion #region Parameter SourceRelationalDatabaseName /// /// /// The name of the source database. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SourceRelationalDatabaseName { get; set; } #endregion #region Parameter Tag /// /// /// The tag keys and optional values to add to the resource during create.Use the TagResource action to tag a resource after it's created. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.Lightsail.Model.Tag[] Tag { get; set; } #endregion #region Parameter UseLatestRestorableTime /// /// /// Specifies whether your database is restored from the latest backup time. A value of /// true restores from the latest backup time. Default: falseConstraints: Cannot be specified if the restore time parameter is provided. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? UseLatestRestorableTime { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'Operations'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Lightsail.Model.CreateRelationalDatabaseFromSnapshotResponse). /// Specifying the name of a property of type Amazon.Lightsail.Model.CreateRelationalDatabaseFromSnapshotResponse 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; } = "Operations"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the RelationalDatabaseName parameter. /// The -PassThru parameter is deprecated, use -Select '^RelationalDatabaseName' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^RelationalDatabaseName' 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.RelationalDatabaseName), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-LSRelationalDatabaseFromSnapshot (CreateRelationalDatabaseFromSnapshot)")) { 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.RelationalDatabaseName; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.AvailabilityZone = this.AvailabilityZone; context.PubliclyAccessible = this.PubliclyAccessible; context.RelationalDatabaseBundleId = this.RelationalDatabaseBundleId; context.RelationalDatabaseName = this.RelationalDatabaseName; #if MODULAR if (this.RelationalDatabaseName == null && ParameterWasBound(nameof(this.RelationalDatabaseName))) { WriteWarning("You are passing $null as a value for parameter RelationalDatabaseName 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.RelationalDatabaseSnapshotName = this.RelationalDatabaseSnapshotName; context.RestoreTime = this.RestoreTime; context.SourceRelationalDatabaseName = this.SourceRelationalDatabaseName; if (this.Tag != null) { context.Tag = new List(this.Tag); } context.UseLatestRestorableTime = this.UseLatestRestorableTime; // 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.Lightsail.Model.CreateRelationalDatabaseFromSnapshotRequest(); if (cmdletContext.AvailabilityZone != null) { request.AvailabilityZone = cmdletContext.AvailabilityZone; } if (cmdletContext.PubliclyAccessible != null) { request.PubliclyAccessible = cmdletContext.PubliclyAccessible.Value; } if (cmdletContext.RelationalDatabaseBundleId != null) { request.RelationalDatabaseBundleId = cmdletContext.RelationalDatabaseBundleId; } if (cmdletContext.RelationalDatabaseName != null) { request.RelationalDatabaseName = cmdletContext.RelationalDatabaseName; } if (cmdletContext.RelationalDatabaseSnapshotName != null) { request.RelationalDatabaseSnapshotName = cmdletContext.RelationalDatabaseSnapshotName; } if (cmdletContext.RestoreTime != null) { request.RestoreTime = cmdletContext.RestoreTime.Value; } if (cmdletContext.SourceRelationalDatabaseName != null) { request.SourceRelationalDatabaseName = cmdletContext.SourceRelationalDatabaseName; } if (cmdletContext.Tag != null) { request.Tags = cmdletContext.Tag; } if (cmdletContext.UseLatestRestorableTime != null) { request.UseLatestRestorableTime = cmdletContext.UseLatestRestorableTime.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.Lightsail.Model.CreateRelationalDatabaseFromSnapshotResponse CallAWSServiceOperation(IAmazonLightsail client, Amazon.Lightsail.Model.CreateRelationalDatabaseFromSnapshotRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Lightsail", "CreateRelationalDatabaseFromSnapshot"); try { #if DESKTOP return client.CreateRelationalDatabaseFromSnapshot(request); #elif CORECLR return client.CreateRelationalDatabaseFromSnapshotAsync(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 AvailabilityZone { get; set; } public System.Boolean? PubliclyAccessible { get; set; } public System.String RelationalDatabaseBundleId { get; set; } public System.String RelationalDatabaseName { get; set; } public System.String RelationalDatabaseSnapshotName { get; set; } public System.DateTime? RestoreTime { get; set; } public System.String SourceRelationalDatabaseName { get; set; } public List Tag { get; set; } public System.Boolean? UseLatestRestorableTime { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.Operations; } } }