protected override void ProcessRecord() { AmazonEC2 client = base.GetClient(); Amazon.EC2.Model.AttachVolumeRequest request = new Amazon.EC2.Model.AttachVolumeRequest(); request.VolumeId = this._VolumeId; request.InstanceId = this._InstanceId; request.Device = this._Device; Amazon.EC2.Model.AttachVolumeResponse response = client.AttachVolume(request); base.WriteObject(response.AttachVolumeResult, true); }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.EC2.Model.AttachVolumeRequest(); if (cmdletContext.Device != null) { request.Device = cmdletContext.Device; } if (cmdletContext.InstanceId != null) { request.InstanceId = cmdletContext.InstanceId; } if (cmdletContext.VolumeId != null) { request.VolumeId = cmdletContext.VolumeId; } 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); }
/// <summary> /// Initiates the asynchronous execution of the AttachVolume operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the AttachVolume operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<AttachVolumeResponse> AttachVolumeAsync(AttachVolumeRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new AttachVolumeRequestMarshaller(); var unmarshaller = AttachVolumeResponseUnmarshaller.Instance; return InvokeAsync<AttachVolumeRequest,AttachVolumeResponse>(request, marshaller, unmarshaller, cancellationToken); }
/// <summary> /// Attaches an EBS volume to a running or stopped instance and exposes it to the instance /// with the specified device name. /// /// /// <para> /// Encrypted EBS volumes may only be attached to instances that support Amazon EBS encryption. /// For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html">Amazon /// EBS Encryption</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>. /// </para> /// /// <para> /// For a list of supported device names, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html">Attaching /// an EBS Volume to an Instance</a>. Any device names that aren't reserved for instance /// store volumes can be used for EBS volumes. For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html">Amazon /// EC2 Instance Store</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>. /// </para> /// /// <para> /// If a volume has an AWS Marketplace product code: /// </para> /// <ul> <li>The volume can be attached only to a stopped instance.</li> <li>AWS Marketplace /// product codes are copied from the volume to the instance.</li> <li>You must be subscribed /// to the product.</li> <li>The instance type and operating system of the instance must /// support the product. For example, you can't detach a volume from a Windows instance /// and attach it to a Linux instance.</li> </ul> /// <para> /// For an overview of the AWS Marketplace, see <a href="https://aws.amazon.com/marketplace/help/200900000">Introducing /// AWS Marketplace</a>. /// </para> /// /// <para> /// For more information about EBS volumes, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html">Attaching /// Amazon EBS Volumes</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the AttachVolume service method.</param> /// /// <returns>The response from the AttachVolume service method, as returned by EC2.</returns> public AttachVolumeResponse AttachVolume(AttachVolumeRequest request) { var marshaller = new AttachVolumeRequestMarshaller(); var unmarshaller = AttachVolumeResponseUnmarshaller.Instance; return Invoke<AttachVolumeRequest,AttachVolumeResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the AttachVolume operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the AttachVolume operation on AmazonEC2Client.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndAttachVolume /// operation.</returns> public IAsyncResult BeginAttachVolume(AttachVolumeRequest request, AsyncCallback callback, object state) { var marshaller = new AttachVolumeRequestMarshaller(); var unmarshaller = AttachVolumeResponseUnmarshaller.Instance; return BeginInvoke<AttachVolumeRequest>(request, marshaller, unmarshaller, callback, state); }
IAsyncResult invokeAttachVolume(AttachVolumeRequest attachVolumeRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new AttachVolumeRequestMarshaller().Marshall(attachVolumeRequest); var unmarshaller = AttachVolumeResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// Initiates the asynchronous execution of the AttachVolume operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.AttachVolume"/> /// </summary> /// /// <param name="attachVolumeRequest">Container for the necessary parameters to execute the AttachVolume operation on AmazonEC2.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndAttachVolume /// operation.</returns> public IAsyncResult BeginAttachVolume(AttachVolumeRequest attachVolumeRequest, AsyncCallback callback, object state) { return invokeAttachVolume(attachVolumeRequest, callback, state, false); }
/// <summary> /// <para>Attaches an Amazon EBS volume to a running or stopped instance and exposes it to the instance with the specified device name.</para> /// <para>For a list of supported device names, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html" /// >Attaching an Amazon EBS Volume to an Instance</a> . Any device names that aren't reserved for instance store volumes can be used for Amazon /// EBS volumes. For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html" >Amazon EC2 /// Instance Store</a> in the <i>Amazon Elastic Compute Cloud User Guide</i> .</para> <para>If a volume has an AWS Marketplace product /// code:</para> /// <ul> /// <li>The volume can only be attached as the root device of a stopped instance.</li> /// <li>You must be subscribed to the AWS Marketplace code that is on the volume.</li> /// <li>The configuration (instance type, operating system) of the instance must support that specific AWS Marketplace code. For example, you /// cannot take a volume from a Windows instance and attach it to a Linux instance.</li> /// <li>AWS Marketplace product codes are copied from the volume to the instance.</li> /// /// </ul> /// <para>For an overview of the AWS Marketplace, see <a href="https://aws.amazon.com/marketplace/help/200900000" /// >https://aws.amazon.com/marketplace/help/200900000</a> . For more information about how to use the AWS Marketplace, see <a /// href="https://aws.amazon.com/marketplace" >AWS Marketplace</a> .</para> <para>For more information about Amazon EBS volumes, see <a /// href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html" >Attaching Amazon EBS Volumes</a> in the <i>Amazon /// Elastic Compute Cloud User Guide</i> .</para> /// </summary> /// /// <param name="attachVolumeRequest">Container for the necessary parameters to execute the AttachVolume service method on AmazonEC2.</param> /// /// <returns>The response from the AttachVolume service method, as returned by AmazonEC2.</returns> /// public AttachVolumeResponse AttachVolume(AttachVolumeRequest attachVolumeRequest) { IAsyncResult asyncResult = invokeAttachVolume(attachVolumeRequest, null, null, true); return EndAttachVolume(asyncResult); }
/// <summary> /// <para>Attaches an Amazon EBS volume to a running or stopped instance and exposes it to the instance with the specified device name.</para> /// <para>For a list of supported device names, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html">Attaching an Amazon EBS Volume to an Instance</a> . Any device names that aren't reserved for instance store volumes can be used for Amazon /// EBS volumes. For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html">Amazon EC2 /// Instance Store</a> in the <i>Amazon Elastic Compute Cloud User Guide</i> .</para> <para>If a volume has an AWS Marketplace product /// code:</para> /// <ul> /// <li>The volume can only be attached as the root device of a stopped instance.</li> /// <li>You must be subscribed to the AWS Marketplace code that is on the volume.</li> /// <li>The configuration (instance type, operating system) of the instance must support that specific AWS Marketplace code. For example, you /// cannot take a volume from a Windows instance and attach it to a Linux instance.</li> /// <li>AWS Marketplace product codes are copied from the volume to the instance.</li> /// /// </ul> /// <para>For an overview of the AWS Marketplace, see <a href="https://aws.amazon.com/marketplace/help/200900000">https://aws.amazon.com/marketplace/help/200900000</a> . For more information about how to use the AWS Marketplace, see <a href="https://aws.amazon.com/marketplace">AWS Marketplace</a> .</para> <para>For more information about Amazon EBS volumes, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html">Attaching Amazon EBS Volumes</a> in the <i>Amazon /// Elastic Compute Cloud User Guide</i> .</para> /// </summary> /// /// <param name="attachVolumeRequest">Container for the necessary parameters to execute the AttachVolume service method on AmazonEC2.</param> /// /// <returns>The response from the AttachVolume service method, as returned by AmazonEC2.</returns> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public Task<AttachVolumeResponse> AttachVolumeAsync(AttachVolumeRequest attachVolumeRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new AttachVolumeRequestMarshaller(); var unmarshaller = AttachVolumeResponseUnmarshaller.GetInstance(); return Invoke<IRequest, AttachVolumeRequest, AttachVolumeResponse>(attachVolumeRequest, marshaller, unmarshaller, signer, cancellationToken); }
internal AttachVolumeResponse AttachVolume(AttachVolumeRequest request) { var task = AttachVolumeAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// Initiates the asynchronous execution of the AttachVolume operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.AttachVolume"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the AttachVolume operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public async Task<AttachVolumeResponse> AttachVolumeAsync(AttachVolumeRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new AttachVolumeRequestMarshaller(); var unmarshaller = AttachVolumeResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, AttachVolumeRequest, AttachVolumeResponse>(request, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
/// <summary> /// <para> Attach a previously created volume to a running instance. </para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the AttachVolume service method on AmazonEC2.</param> /// /// <returns>The response from the AttachVolume service method, as returned by AmazonEC2.</returns> public AttachVolumeResponse AttachVolume(AttachVolumeRequest request) { var task = AttachVolumeAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
/// <summary> /// Attach a previously created volume to a running instance. /// /// </summary> /// <param name="service">Instance of AmazonEC2 service</param> /// <param name="request">AttachVolumeRequest request</param> public static void InvokeAttachVolume(AmazonEC2 service, AttachVolumeRequest request) { try { AttachVolumeResponse response = service.AttachVolume(request); Console.WriteLine ("Service Response"); Console.WriteLine ("============================================================================="); Console.WriteLine (); Console.WriteLine(" AttachVolumeResponse"); if (response.IsSetAttachVolumeResult()) { Console.WriteLine(" AttachVolumeResult"); AttachVolumeResult attachVolumeResult = response.AttachVolumeResult; if (attachVolumeResult.IsSetAttachment()) { Console.WriteLine(" Attachment"); Attachment attachment = attachVolumeResult.Attachment; if (attachment.IsSetVolumeId()) { Console.WriteLine(" VolumeId"); Console.WriteLine(" {0}", attachment.VolumeId); } if (attachment.IsSetInstanceId()) { Console.WriteLine(" InstanceId"); Console.WriteLine(" {0}", attachment.InstanceId); } if (attachment.IsSetDevice()) { Console.WriteLine(" Device"); Console.WriteLine(" {0}", attachment.Device); } if (attachment.IsSetStatus()) { Console.WriteLine(" Status"); Console.WriteLine(" {0}", attachment.Status); } if (attachment.IsSetAttachTime()) { Console.WriteLine(" AttachTime"); Console.WriteLine(" {0}", attachment.AttachTime); } } } if (response.IsSetResponseMetadata()) { Console.WriteLine(" ResponseMetadata"); ResponseMetadata responseMetadata = response.ResponseMetadata; if (responseMetadata.IsSetRequestId()) { Console.WriteLine(" RequestId"); Console.WriteLine(" {0}", responseMetadata.RequestId); } } } catch (AmazonEC2Exception ex) { Console.WriteLine("Caught Exception: " + ex.Message); Console.WriteLine("Response Status Code: " + ex.StatusCode); Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine("Error Type: " + ex.ErrorType); Console.WriteLine("Request ID: " + ex.RequestId); Console.WriteLine("XML: " + ex.XML); } }
private Amazon.EC2.Model.AttachVolumeResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.AttachVolumeRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "AttachVolume"); try { #if DESKTOP return(client.AttachVolume(request)); #elif CORECLR return(client.AttachVolumeAsync(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; } }
/// <summary> /// Attaches a volume to a EC2 instance. /// </summary> /// <param name="device">xvdf through xvdp</param> /// <param name="instanceId"></param> /// <param name="volumeId"></param> public void AttachVolume(string device, string instanceId, string volumeId) { var request = new AttachVolumeRequest { Device = device, InstanceId = instanceId, VolumeId = volumeId }; Client.AttachVolume(request); }