/******************************************************************************* * 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.FSx; using Amazon.FSx.Model; namespace Amazon.PowerShell.Cmdlets.FSX { /// /// Creates an Amazon FSx for Lustre data repository association (DRA). A data repository /// association is a link between a directory on the file system and an Amazon S3 bucket /// or prefix. You can have a maximum of 8 data repository associations on a file system. /// Data repository associations are supported on all FSx for Lustre 2.12 and newer file /// systems, excluding scratch_1 deployment type. /// /// /// /// Each data repository association must have a unique Amazon FSx file system directory /// and a unique S3 bucket or prefix associated with it. You can configure a data repository /// association for automatic import only, for automatic export only, or for both. To /// learn more about linking a data repository to your file system, see Linking /// your file system to an S3 bucket. /// CreateDataRepositoryAssociation isn't supported on Amazon File Cache /// resources. To create a DRA on Amazon File Cache, use the CreateFileCache /// operation. /// /// [Cmdlet("New", "FSXDataRepositoryAssociation", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.FSx.Model.DataRepositoryAssociation")] [AWSCmdlet("Calls the Amazon FSx CreateDataRepositoryAssociation API operation.", Operation = new[] {"CreateDataRepositoryAssociation"}, SelectReturnType = typeof(Amazon.FSx.Model.CreateDataRepositoryAssociationResponse))] [AWSCmdletOutput("Amazon.FSx.Model.DataRepositoryAssociation or Amazon.FSx.Model.CreateDataRepositoryAssociationResponse", "This cmdlet returns an Amazon.FSx.Model.DataRepositoryAssociation object.", "The service call response (type Amazon.FSx.Model.CreateDataRepositoryAssociationResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewFSXDataRepositoryAssociationCmdlet : AmazonFSxClientCmdlet, IExecutor { #region Parameter BatchImportMetaDataOnCreate /// /// /// Set to true to run an import data repository task to import metadata /// from the data repository to the file system after the data repository association /// is created. Default is false. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? BatchImportMetaDataOnCreate { get; set; } #endregion #region Parameter ClientRequestToken /// /// /// The service has not provided documentation for this parameter; please refer to the service's API reference documentation for the latest available information. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String ClientRequestToken { get; set; } #endregion #region Parameter DataRepositoryPath /// /// /// The path to the Amazon S3 data repository that will be linked to the file system. /// The path can be an S3 bucket or prefix in the format s3://myBucket/myPrefix/. /// This path specifies where in the S3 data repository files will be imported from or /// exported to. /// /// #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 DataRepositoryPath { get; set; } #endregion #region Parameter AutoExportPolicy_Event /// /// /// The AutoExportPolicy can have the following event values:You can define any combination of event types for your AutoExportPolicy. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("S3_AutoExportPolicy_Events")] public System.String[] AutoExportPolicy_Event { get; set; } #endregion #region Parameter AutoImportPolicy_Event /// /// /// The AutoImportPolicy can have the following event values:You can define any combination of event types for your AutoImportPolicy. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("S3_AutoImportPolicy_Events")] public System.String[] AutoImportPolicy_Event { get; set; } #endregion #region Parameter FileSystemId /// /// /// The service has not provided documentation for this parameter; please refer to the service's API reference documentation for the latest available information. /// /// #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 FileSystemId { get; set; } #endregion #region Parameter FileSystemPath /// /// /// A path on the file system that points to a high-level directory (such as /ns1/) /// or subdirectory (such as /ns1/subdir/) that will be mapped 1-1 with DataRepositoryPath. /// The leading forward slash in the name is required. Two data repository associations /// cannot have overlapping file system paths. For example, if a data repository is associated /// with file system path /ns1/, then you cannot link another data repository /// with file system path /ns1/ns2.This path specifies where in your file system files will be exported from or imported /// to. This file system directory can be linked to only one Amazon S3 bucket, and no /// other S3 bucket can be linked to the directory.If you specify only a forward slash (/) as the file system path, you /// can link only one data repository to the file system. You can only specify "/" as /// the file system path for the first data repository associated with a file system. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String FileSystemPath { get; set; } #endregion #region Parameter ImportedFileChunkSize /// /// /// For files imported from a data repository, this value determines the stripe count /// and maximum amount of data per file (in MiB) stored on a single physical disk. The /// maximum number of disks that a single file can be striped across is limited by the /// total number of disks that make up the file system.The default chunk size is 1,024 MiB (1 GiB) and can go as high as 512,000 MiB (500 /// GiB). Amazon S3 objects have a maximum size of 5 TB. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? ImportedFileChunkSize { get; set; } #endregion #region Parameter Tag /// /// /// The service has not provided documentation for this parameter; please refer to the service's API reference documentation for the latest available information. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.FSx.Model.Tag[] Tag { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'Association'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.FSx.Model.CreateDataRepositoryAssociationResponse). /// Specifying the name of a property of type Amazon.FSx.Model.CreateDataRepositoryAssociationResponse 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; } = "Association"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the FileSystemId parameter. /// The -PassThru parameter is deprecated, use -Select '^FileSystemId' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^FileSystemId' 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.FileSystemId), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-FSXDataRepositoryAssociation (CreateDataRepositoryAssociation)")) { 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.FileSystemId; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.BatchImportMetaDataOnCreate = this.BatchImportMetaDataOnCreate; context.ClientRequestToken = this.ClientRequestToken; context.DataRepositoryPath = this.DataRepositoryPath; #if MODULAR if (this.DataRepositoryPath == null && ParameterWasBound(nameof(this.DataRepositoryPath))) { WriteWarning("You are passing $null as a value for parameter DataRepositoryPath 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.FileSystemId = this.FileSystemId; #if MODULAR if (this.FileSystemId == null && ParameterWasBound(nameof(this.FileSystemId))) { WriteWarning("You are passing $null as a value for parameter FileSystemId 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.FileSystemPath = this.FileSystemPath; context.ImportedFileChunkSize = this.ImportedFileChunkSize; if (this.AutoExportPolicy_Event != null) { context.AutoExportPolicy_Event = new List(this.AutoExportPolicy_Event); } if (this.AutoImportPolicy_Event != null) { context.AutoImportPolicy_Event = new List(this.AutoImportPolicy_Event); } if (this.Tag != null) { context.Tag = new List(this.Tag); } // 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.FSx.Model.CreateDataRepositoryAssociationRequest(); if (cmdletContext.BatchImportMetaDataOnCreate != null) { request.BatchImportMetaDataOnCreate = cmdletContext.BatchImportMetaDataOnCreate.Value; } if (cmdletContext.ClientRequestToken != null) { request.ClientRequestToken = cmdletContext.ClientRequestToken; } if (cmdletContext.DataRepositoryPath != null) { request.DataRepositoryPath = cmdletContext.DataRepositoryPath; } if (cmdletContext.FileSystemId != null) { request.FileSystemId = cmdletContext.FileSystemId; } if (cmdletContext.FileSystemPath != null) { request.FileSystemPath = cmdletContext.FileSystemPath; } if (cmdletContext.ImportedFileChunkSize != null) { request.ImportedFileChunkSize = cmdletContext.ImportedFileChunkSize.Value; } // populate S3 var requestS3IsNull = true; request.S3 = new Amazon.FSx.Model.S3DataRepositoryConfiguration(); Amazon.FSx.Model.AutoExportPolicy requestS3_s3_AutoExportPolicy = null; // populate AutoExportPolicy var requestS3_s3_AutoExportPolicyIsNull = true; requestS3_s3_AutoExportPolicy = new Amazon.FSx.Model.AutoExportPolicy(); List requestS3_s3_AutoExportPolicy_autoExportPolicy_Event = null; if (cmdletContext.AutoExportPolicy_Event != null) { requestS3_s3_AutoExportPolicy_autoExportPolicy_Event = cmdletContext.AutoExportPolicy_Event; } if (requestS3_s3_AutoExportPolicy_autoExportPolicy_Event != null) { requestS3_s3_AutoExportPolicy.Events = requestS3_s3_AutoExportPolicy_autoExportPolicy_Event; requestS3_s3_AutoExportPolicyIsNull = false; } // determine if requestS3_s3_AutoExportPolicy should be set to null if (requestS3_s3_AutoExportPolicyIsNull) { requestS3_s3_AutoExportPolicy = null; } if (requestS3_s3_AutoExportPolicy != null) { request.S3.AutoExportPolicy = requestS3_s3_AutoExportPolicy; requestS3IsNull = false; } Amazon.FSx.Model.AutoImportPolicy requestS3_s3_AutoImportPolicy = null; // populate AutoImportPolicy var requestS3_s3_AutoImportPolicyIsNull = true; requestS3_s3_AutoImportPolicy = new Amazon.FSx.Model.AutoImportPolicy(); List requestS3_s3_AutoImportPolicy_autoImportPolicy_Event = null; if (cmdletContext.AutoImportPolicy_Event != null) { requestS3_s3_AutoImportPolicy_autoImportPolicy_Event = cmdletContext.AutoImportPolicy_Event; } if (requestS3_s3_AutoImportPolicy_autoImportPolicy_Event != null) { requestS3_s3_AutoImportPolicy.Events = requestS3_s3_AutoImportPolicy_autoImportPolicy_Event; requestS3_s3_AutoImportPolicyIsNull = false; } // determine if requestS3_s3_AutoImportPolicy should be set to null if (requestS3_s3_AutoImportPolicyIsNull) { requestS3_s3_AutoImportPolicy = null; } if (requestS3_s3_AutoImportPolicy != null) { request.S3.AutoImportPolicy = requestS3_s3_AutoImportPolicy; requestS3IsNull = false; } // determine if request.S3 should be set to null if (requestS3IsNull) { request.S3 = null; } if (cmdletContext.Tag != null) { request.Tags = cmdletContext.Tag; } 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.FSx.Model.CreateDataRepositoryAssociationResponse CallAWSServiceOperation(IAmazonFSx client, Amazon.FSx.Model.CreateDataRepositoryAssociationRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon FSx", "CreateDataRepositoryAssociation"); try { #if DESKTOP return client.CreateDataRepositoryAssociation(request); #elif CORECLR return client.CreateDataRepositoryAssociationAsync(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? BatchImportMetaDataOnCreate { get; set; } public System.String ClientRequestToken { get; set; } public System.String DataRepositoryPath { get; set; } public System.String FileSystemId { get; set; } public System.String FileSystemPath { get; set; } public System.Int32? ImportedFileChunkSize { get; set; } public List AutoExportPolicy_Event { get; set; } public List AutoImportPolicy_Event { get; set; } public List Tag { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.Association; } } }