/*******************************************************************************
* 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.Mgn;
using Amazon.Mgn.Model;
namespace Amazon.PowerShell.Cmdlets.MGN
{
///
/// Updates multiple LaunchConfigurations by Source Server ID.
///
[Cmdlet("Update", "MGNLaunchConfiguration", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.Mgn.Model.UpdateLaunchConfigurationResponse")]
[AWSCmdlet("Calls the Application Migration Service UpdateLaunchConfiguration API operation.", Operation = new[] {"UpdateLaunchConfiguration"}, SelectReturnType = typeof(Amazon.Mgn.Model.UpdateLaunchConfigurationResponse))]
[AWSCmdletOutput("Amazon.Mgn.Model.UpdateLaunchConfigurationResponse",
"This cmdlet returns an Amazon.Mgn.Model.UpdateLaunchConfigurationResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class UpdateMGNLaunchConfigurationCmdlet : AmazonMgnClientCmdlet, IExecutor
{
#region Parameter AccountID
///
///
/// Update Launch configuration Account ID.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String AccountID { get; set; }
#endregion
#region Parameter BootMode
///
///
/// Update Launch configuration boot mode request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.Mgn.BootMode")]
public Amazon.Mgn.BootMode BootMode { get; set; }
#endregion
#region Parameter PostLaunchActions_CloudWatchLogGroupName
///
///
/// AWS Systems Manager Command's CloudWatch log group name.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PostLaunchActions_CloudWatchLogGroupName { get; set; }
#endregion
#region Parameter CopyPrivateIp
///
///
/// Update Launch configuration copy Private IP request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? CopyPrivateIp { get; set; }
#endregion
#region Parameter CopyTag
///
///
/// Update Launch configuration copy Tags request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("CopyTags")]
public System.Boolean? CopyTag { get; set; }
#endregion
#region Parameter PostLaunchActions_Deployment
///
///
/// Deployment type in which AWS Systems Manager Documents will be executed.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.Mgn.PostLaunchActionsDeploymentType")]
public Amazon.Mgn.PostLaunchActionsDeploymentType PostLaunchActions_Deployment { get; set; }
#endregion
#region Parameter EnableMapAutoTagging
///
///
/// Enable map auto tagging.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? EnableMapAutoTagging { get; set; }
#endregion
#region Parameter LaunchDisposition
///
///
/// Update Launch configuration launch disposition request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.Mgn.LaunchDisposition")]
public Amazon.Mgn.LaunchDisposition LaunchDisposition { get; set; }
#endregion
#region Parameter MapAutoTaggingMpeID
///
///
/// Launch configuration map auto tagging MPE ID.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String MapAutoTaggingMpeID { get; set; }
#endregion
#region Parameter Name
///
///
/// Update Launch configuration name request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Name { get; set; }
#endregion
#region Parameter Licensing_OsByol
///
///
/// Configure BYOL OS licensing.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? Licensing_OsByol { get; set; }
#endregion
#region Parameter PostLaunchActions_S3LogBucket
///
///
/// AWS Systems Manager Command's logs S3 log bucket.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PostLaunchActions_S3LogBucket { get; set; }
#endregion
#region Parameter PostLaunchActions_S3OutputKeyPrefix
///
///
/// AWS Systems Manager Command's logs S3 output key prefix.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PostLaunchActions_S3OutputKeyPrefix { get; set; }
#endregion
#region Parameter SourceServerID
///
///
/// Update Launch configuration by Source Server ID request.
///
///
#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 SourceServerID { get; set; }
#endregion
#region Parameter PostLaunchActions_SsmDocument
///
///
/// AWS Systems Manager Documents.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("PostLaunchActions_SsmDocuments")]
public Amazon.Mgn.Model.SsmDocument[] PostLaunchActions_SsmDocument { get; set; }
#endregion
#region Parameter TargetInstanceTypeRightSizingMethod
///
///
/// Update Launch configuration Target instance right sizing request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.Mgn.TargetInstanceTypeRightSizingMethod")]
public Amazon.Mgn.TargetInstanceTypeRightSizingMethod TargetInstanceTypeRightSizingMethod { 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.Mgn.Model.UpdateLaunchConfigurationResponse).
/// Specifying the name of a property of type Amazon.Mgn.Model.UpdateLaunchConfigurationResponse 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 SourceServerID parameter.
/// The -PassThru parameter is deprecated, use -Select '^SourceServerID' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^SourceServerID' 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.SourceServerID), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Update-MGNLaunchConfiguration (UpdateLaunchConfiguration)"))
{
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.SourceServerID;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AccountID = this.AccountID;
context.BootMode = this.BootMode;
context.CopyPrivateIp = this.CopyPrivateIp;
context.CopyTag = this.CopyTag;
context.EnableMapAutoTagging = this.EnableMapAutoTagging;
context.LaunchDisposition = this.LaunchDisposition;
context.Licensing_OsByol = this.Licensing_OsByol;
context.MapAutoTaggingMpeID = this.MapAutoTaggingMpeID;
context.Name = this.Name;
context.PostLaunchActions_CloudWatchLogGroupName = this.PostLaunchActions_CloudWatchLogGroupName;
context.PostLaunchActions_Deployment = this.PostLaunchActions_Deployment;
context.PostLaunchActions_S3LogBucket = this.PostLaunchActions_S3LogBucket;
context.PostLaunchActions_S3OutputKeyPrefix = this.PostLaunchActions_S3OutputKeyPrefix;
if (this.PostLaunchActions_SsmDocument != null)
{
context.PostLaunchActions_SsmDocument = new List(this.PostLaunchActions_SsmDocument);
}
context.SourceServerID = this.SourceServerID;
#if MODULAR
if (this.SourceServerID == null && ParameterWasBound(nameof(this.SourceServerID)))
{
WriteWarning("You are passing $null as a value for parameter SourceServerID 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.TargetInstanceTypeRightSizingMethod = this.TargetInstanceTypeRightSizingMethod;
// 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.Mgn.Model.UpdateLaunchConfigurationRequest();
if (cmdletContext.AccountID != null)
{
request.AccountID = cmdletContext.AccountID;
}
if (cmdletContext.BootMode != null)
{
request.BootMode = cmdletContext.BootMode;
}
if (cmdletContext.CopyPrivateIp != null)
{
request.CopyPrivateIp = cmdletContext.CopyPrivateIp.Value;
}
if (cmdletContext.CopyTag != null)
{
request.CopyTags = cmdletContext.CopyTag.Value;
}
if (cmdletContext.EnableMapAutoTagging != null)
{
request.EnableMapAutoTagging = cmdletContext.EnableMapAutoTagging.Value;
}
if (cmdletContext.LaunchDisposition != null)
{
request.LaunchDisposition = cmdletContext.LaunchDisposition;
}
// populate Licensing
var requestLicensingIsNull = true;
request.Licensing = new Amazon.Mgn.Model.Licensing();
System.Boolean? requestLicensing_licensing_OsByol = null;
if (cmdletContext.Licensing_OsByol != null)
{
requestLicensing_licensing_OsByol = cmdletContext.Licensing_OsByol.Value;
}
if (requestLicensing_licensing_OsByol != null)
{
request.Licensing.OsByol = requestLicensing_licensing_OsByol.Value;
requestLicensingIsNull = false;
}
// determine if request.Licensing should be set to null
if (requestLicensingIsNull)
{
request.Licensing = null;
}
if (cmdletContext.MapAutoTaggingMpeID != null)
{
request.MapAutoTaggingMpeID = cmdletContext.MapAutoTaggingMpeID;
}
if (cmdletContext.Name != null)
{
request.Name = cmdletContext.Name;
}
// populate PostLaunchActions
var requestPostLaunchActionsIsNull = true;
request.PostLaunchActions = new Amazon.Mgn.Model.PostLaunchActions();
System.String requestPostLaunchActions_postLaunchActions_CloudWatchLogGroupName = null;
if (cmdletContext.PostLaunchActions_CloudWatchLogGroupName != null)
{
requestPostLaunchActions_postLaunchActions_CloudWatchLogGroupName = cmdletContext.PostLaunchActions_CloudWatchLogGroupName;
}
if (requestPostLaunchActions_postLaunchActions_CloudWatchLogGroupName != null)
{
request.PostLaunchActions.CloudWatchLogGroupName = requestPostLaunchActions_postLaunchActions_CloudWatchLogGroupName;
requestPostLaunchActionsIsNull = false;
}
Amazon.Mgn.PostLaunchActionsDeploymentType requestPostLaunchActions_postLaunchActions_Deployment = null;
if (cmdletContext.PostLaunchActions_Deployment != null)
{
requestPostLaunchActions_postLaunchActions_Deployment = cmdletContext.PostLaunchActions_Deployment;
}
if (requestPostLaunchActions_postLaunchActions_Deployment != null)
{
request.PostLaunchActions.Deployment = requestPostLaunchActions_postLaunchActions_Deployment;
requestPostLaunchActionsIsNull = false;
}
System.String requestPostLaunchActions_postLaunchActions_S3LogBucket = null;
if (cmdletContext.PostLaunchActions_S3LogBucket != null)
{
requestPostLaunchActions_postLaunchActions_S3LogBucket = cmdletContext.PostLaunchActions_S3LogBucket;
}
if (requestPostLaunchActions_postLaunchActions_S3LogBucket != null)
{
request.PostLaunchActions.S3LogBucket = requestPostLaunchActions_postLaunchActions_S3LogBucket;
requestPostLaunchActionsIsNull = false;
}
System.String requestPostLaunchActions_postLaunchActions_S3OutputKeyPrefix = null;
if (cmdletContext.PostLaunchActions_S3OutputKeyPrefix != null)
{
requestPostLaunchActions_postLaunchActions_S3OutputKeyPrefix = cmdletContext.PostLaunchActions_S3OutputKeyPrefix;
}
if (requestPostLaunchActions_postLaunchActions_S3OutputKeyPrefix != null)
{
request.PostLaunchActions.S3OutputKeyPrefix = requestPostLaunchActions_postLaunchActions_S3OutputKeyPrefix;
requestPostLaunchActionsIsNull = false;
}
List requestPostLaunchActions_postLaunchActions_SsmDocument = null;
if (cmdletContext.PostLaunchActions_SsmDocument != null)
{
requestPostLaunchActions_postLaunchActions_SsmDocument = cmdletContext.PostLaunchActions_SsmDocument;
}
if (requestPostLaunchActions_postLaunchActions_SsmDocument != null)
{
request.PostLaunchActions.SsmDocuments = requestPostLaunchActions_postLaunchActions_SsmDocument;
requestPostLaunchActionsIsNull = false;
}
// determine if request.PostLaunchActions should be set to null
if (requestPostLaunchActionsIsNull)
{
request.PostLaunchActions = null;
}
if (cmdletContext.SourceServerID != null)
{
request.SourceServerID = cmdletContext.SourceServerID;
}
if (cmdletContext.TargetInstanceTypeRightSizingMethod != null)
{
request.TargetInstanceTypeRightSizingMethod = cmdletContext.TargetInstanceTypeRightSizingMethod;
}
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.Mgn.Model.UpdateLaunchConfigurationResponse CallAWSServiceOperation(IAmazonMgn client, Amazon.Mgn.Model.UpdateLaunchConfigurationRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Application Migration Service", "UpdateLaunchConfiguration");
try
{
#if DESKTOP
return client.UpdateLaunchConfiguration(request);
#elif CORECLR
return client.UpdateLaunchConfigurationAsync(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 AccountID { get; set; }
public Amazon.Mgn.BootMode BootMode { get; set; }
public System.Boolean? CopyPrivateIp { get; set; }
public System.Boolean? CopyTag { get; set; }
public System.Boolean? EnableMapAutoTagging { get; set; }
public Amazon.Mgn.LaunchDisposition LaunchDisposition { get; set; }
public System.Boolean? Licensing_OsByol { get; set; }
public System.String MapAutoTaggingMpeID { get; set; }
public System.String Name { get; set; }
public System.String PostLaunchActions_CloudWatchLogGroupName { get; set; }
public Amazon.Mgn.PostLaunchActionsDeploymentType PostLaunchActions_Deployment { get; set; }
public System.String PostLaunchActions_S3LogBucket { get; set; }
public System.String PostLaunchActions_S3OutputKeyPrefix { get; set; }
public List PostLaunchActions_SsmDocument { get; set; }
public System.String SourceServerID { get; set; }
public Amazon.Mgn.TargetInstanceTypeRightSizingMethod TargetInstanceTypeRightSizingMethod { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}