/******************************************************************************* * 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.DataSync; using Amazon.DataSync.Model; namespace Amazon.PowerShell.Cmdlets.DSYN { /// /// Creates an endpoint for an Network File System (NFS) file server that DataSync can /// use for a data transfer. /// [Cmdlet("New", "DSYNLocationNfs", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("System.String")] [AWSCmdlet("Calls the AWS DataSync CreateLocationNfs API operation.", Operation = new[] {"CreateLocationNfs"}, SelectReturnType = typeof(Amazon.DataSync.Model.CreateLocationNfsResponse))] [AWSCmdletOutput("System.String or Amazon.DataSync.Model.CreateLocationNfsResponse", "This cmdlet returns a System.String object.", "The service call response (type Amazon.DataSync.Model.CreateLocationNfsResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewDSYNLocationNfsCmdlet : AmazonDataSyncClientCmdlet, IExecutor { #region Parameter OnPremConfig_AgentArn /// /// /// ARNs of the agents to use for an NFS location. /// /// #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("OnPremConfig_AgentArns")] public System.String[] OnPremConfig_AgentArn { get; set; } #endregion #region Parameter ServerHostname /// /// /// Specifies the IP address or domain name of your NFS file server. An agent that is /// installed on-premises uses this hostname to mount the NFS server in a network. If you are copying data to or from your Snowcone device, see NFS /// Server on Snowcone for more information.You must specify be an IP version 4 address or Domain Name System (DNS)-compliant /// name. /// /// #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 ServerHostname { get; set; } #endregion #region Parameter Subdirectory /// /// /// Specifies the subdirectory in the NFS file server that DataSync transfers to or from. /// The NFS path should be a path that's exported by the NFS server, or a subdirectory /// of that path. The path should be such that it can be mounted by other NFS clients /// in your network. To see all the paths exported by your NFS server, run "showmount -e nfs-server-name" /// from an NFS client that has access to your server. You can specify any directory that /// appears in the results, and any subdirectory of that directory. Ensure that the NFS /// export is accessible without Kerberos authentication. To transfer all the data in the folder you specified, DataSync needs to have permissions /// to read all the data. To ensure this, either configure the NFS export with no_root_squash, /// or ensure that the permissions for all of the files that you want DataSync allow read /// access for all users. Doing either enables the agent to read the files. For the agent /// to access directories, you must additionally enable all execute access.If you are copying data to or from your Snowcone device, see NFS /// Server on Snowcone for more information. /// /// #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 Subdirectory { get; set; } #endregion #region Parameter Tag /// /// /// Specifies labels that help you categorize, filter, and search for your Amazon Web /// Services resources. We recommend creating at least a name tag for your location. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.DataSync.Model.TagListEntry[] Tag { get; set; } #endregion #region Parameter MountOptions_Version /// /// /// Specifies the NFS version that you want DataSync to use when mounting your NFS share. /// If the server refuses to use the version specified, the task fails.You can specify the following options:DataSync currently only supports NFS version 3 with Amazon FSx for NetApp ONTAP locations. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.DataSync.NfsVersion")] public Amazon.DataSync.NfsVersion MountOptions_Version { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'LocationArn'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.DataSync.Model.CreateLocationNfsResponse). /// Specifying the name of a property of type Amazon.DataSync.Model.CreateLocationNfsResponse 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; } = "LocationArn"; #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 = string.Empty; if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-DSYNLocationNfs (CreateLocationNfs)")) { 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(Select) ?? throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select)); } context.MountOptions_Version = this.MountOptions_Version; if (this.OnPremConfig_AgentArn != null) { context.OnPremConfig_AgentArn = new List(this.OnPremConfig_AgentArn); } #if MODULAR if (this.OnPremConfig_AgentArn == null && ParameterWasBound(nameof(this.OnPremConfig_AgentArn))) { WriteWarning("You are passing $null as a value for parameter OnPremConfig_AgentArn 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.ServerHostname = this.ServerHostname; #if MODULAR if (this.ServerHostname == null && ParameterWasBound(nameof(this.ServerHostname))) { WriteWarning("You are passing $null as a value for parameter ServerHostname 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.Subdirectory = this.Subdirectory; #if MODULAR if (this.Subdirectory == null && ParameterWasBound(nameof(this.Subdirectory))) { WriteWarning("You are passing $null as a value for parameter Subdirectory 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); } // 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.DataSync.Model.CreateLocationNfsRequest(); // populate MountOptions var requestMountOptionsIsNull = true; request.MountOptions = new Amazon.DataSync.Model.NfsMountOptions(); Amazon.DataSync.NfsVersion requestMountOptions_mountOptions_Version = null; if (cmdletContext.MountOptions_Version != null) { requestMountOptions_mountOptions_Version = cmdletContext.MountOptions_Version; } if (requestMountOptions_mountOptions_Version != null) { request.MountOptions.Version = requestMountOptions_mountOptions_Version; requestMountOptionsIsNull = false; } // determine if request.MountOptions should be set to null if (requestMountOptionsIsNull) { request.MountOptions = null; } // populate OnPremConfig var requestOnPremConfigIsNull = true; request.OnPremConfig = new Amazon.DataSync.Model.OnPremConfig(); List requestOnPremConfig_onPremConfig_AgentArn = null; if (cmdletContext.OnPremConfig_AgentArn != null) { requestOnPremConfig_onPremConfig_AgentArn = cmdletContext.OnPremConfig_AgentArn; } if (requestOnPremConfig_onPremConfig_AgentArn != null) { request.OnPremConfig.AgentArns = requestOnPremConfig_onPremConfig_AgentArn; requestOnPremConfigIsNull = false; } // determine if request.OnPremConfig should be set to null if (requestOnPremConfigIsNull) { request.OnPremConfig = null; } if (cmdletContext.ServerHostname != null) { request.ServerHostname = cmdletContext.ServerHostname; } if (cmdletContext.Subdirectory != null) { request.Subdirectory = cmdletContext.Subdirectory; } 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.DataSync.Model.CreateLocationNfsResponse CallAWSServiceOperation(IAmazonDataSync client, Amazon.DataSync.Model.CreateLocationNfsRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS DataSync", "CreateLocationNfs"); try { #if DESKTOP return client.CreateLocationNfs(request); #elif CORECLR return client.CreateLocationNfsAsync(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 Amazon.DataSync.NfsVersion MountOptions_Version { get; set; } public List OnPremConfig_AgentArn { get; set; } public System.String ServerHostname { get; set; } public System.String Subdirectory { get; set; } public List Tag { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.LocationArn; } } }