public void Run() { try { var associateRequest = new AssociateAddressRequest { AllocationId = ipAddress.AllocationId, InstanceId = instance.InstanceId }; client.Ec2Client.AssociateAddress(associateRequest); instance.Address = ipAddress; instance.Ip = ipAddress.PublicIp; instance.Port = "10933"; FinishedSuccessfully = true; } catch (Exception ex) { Error = ex.Message; } }
/// <summary> /// The AssociateAddress operation associates an elastic IP address with an /// instance. /// If the IP address is currently assigned to another instance, the IP address is /// assigned to the new instance. This is an idempotent operation. If you enter it /// more than once, Amazon EC2 does not return an error. /// /// </summary> /// <param name="service">Instance of AmazonEC2 service</param> /// <param name="request">AssociateAddressRequest request</param> public static void InvokeAssociateAddress(AmazonEC2 service, AssociateAddressRequest request) { try { AssociateAddressResponse response = service.AssociateAddress(request); Console.WriteLine ("Service Response"); Console.WriteLine ("============================================================================="); Console.WriteLine (); Console.WriteLine(" AssociateAddressResponse"); 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); } }
protected override void ProcessRecord() { AmazonEC2 client = base.GetClient(); Amazon.EC2.Model.AssociateAddressRequest request = new Amazon.EC2.Model.AssociateAddressRequest(); request.InstanceId = this._InstanceId; request.PublicIp = this._PublicIp; Amazon.EC2.Model.AssociateAddressResponse response = client.AssociateAddress(request); }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.EC2.Model.AssociateAddressRequest(); if (cmdletContext.AllocationId != null) { request.AllocationId = cmdletContext.AllocationId; } if (cmdletContext.AllowReassociation != null) { request.AllowReassociation = cmdletContext.AllowReassociation.Value; } if (cmdletContext.InstanceId != null) { request.InstanceId = cmdletContext.InstanceId; } if (cmdletContext.NetworkInterfaceId != null) { request.NetworkInterfaceId = cmdletContext.NetworkInterfaceId; } if (cmdletContext.PrivateIpAddress != null) { request.PrivateIpAddress = cmdletContext.PrivateIpAddress; } if (cmdletContext.PublicIp != null) { request.PublicIp = cmdletContext.PublicIp; } 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 void AssociateIpToInstance(Ec2Key ec2Key, string instanceId, string ip) { AmazonEC2 ec2 = CreateAmazonEc2Client(ec2Key); var request = new AssociateAddressRequest { InstanceId = instanceId, PublicIp = ip }; ec2.AssociateAddress(request); }
/// <summary> /// Connect to an EC2 instance and associate a public IP address with it. /// </summary> protected override void AmazonExecute() { var request = new AssociateAddressRequest { InstanceId = this.InstanceId.Get(this.ActivityContext), PublicIp = this.PublicAddress.Get(this.ActivityContext) }; try { EC2Client.AssociateAddress(request); } catch (EndpointNotFoundException ex) { this.LogBuildMessage(ex.Message); } }
public void AssociateAddress(string vmInstanceId, string ipAddress) { try { AWSModel.AssociateAddressRequest request = new AWSModel.AssociateAddressRequest(); request.InstanceId = vmInstanceId; request.PublicIp = ipAddress; ec2.AssociateAddress(request); } catch (WebException e) { throw new MonoscapeEC2Exception(e.Message, e); } catch (AmazonEC2Exception e) { throw new MonoscapeEC2Exception(e.Message, e); } catch (XmlException e) { // There is an issue in Amazon EC2 API in processing the XML returned from euca_associate_address, // still the remote call has executed properly. Ignore the xml exception as an workaround Log.Debug(this, "AssociateAddress() XmlException raised", e); } }
/// <summary> /// Initiates the asynchronous execution of the AssociateAddress operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the AssociateAddress 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 EndAssociateAddress /// operation.</returns> public IAsyncResult BeginAssociateAddress(AssociateAddressRequest request, AsyncCallback callback, object state) { var marshaller = new AssociateAddressRequestMarshaller(); var unmarshaller = AssociateAddressResponseUnmarshaller.Instance; return BeginInvoke<AssociateAddressRequest>(request, marshaller, unmarshaller, callback, state); }
IAsyncResult invokeAssociateAddress(AssociateAddressRequest associateAddressRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new AssociateAddressRequestMarshaller().Marshall(associateAddressRequest); var unmarshaller = AssociateAddressResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// Initiates the asynchronous execution of the AssociateAddress operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.AssociateAddress"/> /// </summary> /// /// <param name="associateAddressRequest">Container for the necessary parameters to execute the AssociateAddress 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 EndAssociateAddress /// operation.</returns> public IAsyncResult BeginAssociateAddress(AssociateAddressRequest associateAddressRequest, AsyncCallback callback, object state) { return invokeAssociateAddress(associateAddressRequest, callback, state, false); }
/// <summary> /// <para>Associates an Elastic IP address with an instance or a network interface.</para> <para>An Elastic IP address is for use in either the /// EC2-Classic platform or in a VPC. For more information, see <a /// href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html" >Elastic IP Addresses</a> in the <i>Amazon Elastic /// Compute Cloud User Guide</i> .</para> <para>[EC2-Classic, default VPC] If the Elastic IP address is already associated with a different /// instance, it is disassociated from that instance and associated with the specified instance.</para> <para>[EC2-VPC] If you don't specify a /// private IP address, the Elastic IP address is associated with the primary IP address. If the Elastic IP address is already associated with a /// different instance or a network interface, you get an error unless you allow reassociation.</para> <para>This is an idempotent operation. If /// you perform the operation more than once, Amazon EC2 doesn't return an error.</para> /// </summary> /// /// <param name="associateAddressRequest">Container for the necessary parameters to execute the AssociateAddress service method on /// AmazonEC2.</param> /// /// <returns>The response from the AssociateAddress service method, as returned by AmazonEC2.</returns> /// public AssociateAddressResponse AssociateAddress(AssociateAddressRequest associateAddressRequest) { IAsyncResult asyncResult = invokeAssociateAddress(associateAddressRequest, null, null, true); return EndAssociateAddress(asyncResult); }
/// <summary> /// Associate a public IP Address with an EC2 instance /// </summary> /// <param name="instanceId"></param> /// <param name="publicIpAddress"></param> public void AssociateIpAddress(string instanceId, string publicIpAddress) { var request = new AssociateAddressRequest { InstanceId = instanceId, PublicIp = publicIpAddress }; Client.AssociateAddress(request); }
/// <summary> /// Initiates the asynchronous execution of the AssociateAddress operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.AssociateAddress"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the AssociateAddress 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<AssociateAddressResponse> AssociateAddressAsync(AssociateAddressRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new AssociateAddressRequestMarshaller(); var unmarshaller = AssociateAddressResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, AssociateAddressRequest, AssociateAddressResponse>(request, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
/// <summary> /// <para> The AssociateAddress operation associates an elastic IP address with an instance. </para> <para> If the IP address is currently /// assigned to another instance, the IP address is assigned to the new instance. This is an idempotent operation. If you enter it more than /// once, Amazon EC2 does not return an error. </para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the AssociateAddress service method on /// AmazonEC2.</param> /// /// <returns>The response from the AssociateAddress service method, as returned by AmazonEC2.</returns> public AssociateAddressResponse AssociateAddress(AssociateAddressRequest request) { var task = AssociateAddressAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
public void AssociateAddress(string vmInstanceId, string ipAddress) { try { AWSModel.AssociateAddressRequest request = new AWSModel.AssociateAddressRequest(); request.InstanceId = vmInstanceId; request.PublicIp = ipAddress; ec2.AssociateAddress(request); } catch (WebException e) { throw new MonoscapeEC2Exception(e.Message, e); } catch (AmazonEC2Exception e) { throw new MonoscapeEC2Exception(e.Message, e); } catch (XmlException e) { // There is an issue in Amazon EC2 API in processing the XML returned from euca_associate_address, // still the remote call has executed properly. Ignore the xml exception as an workaround Log.Debug(this, "AssociateAddress() XmlException raised", e); } }
/// <summary> /// Associates an Elastic IP address with an instance or a network interface. /// /// /// <para> /// An Elastic IP address is for use in either the EC2-Classic platform or in a VPC. For /// more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html">Elastic /// IP Addresses</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>. /// </para> /// /// <para> /// [EC2-Classic, VPC in an EC2-VPC-only account] If the Elastic IP address is already /// associated with a different instance, it is disassociated from that instance and associated /// with the specified instance. /// </para> /// /// <para> /// [VPC in an EC2-Classic account] If you don't specify a private IP address, the Elastic /// IP address is associated with the primary IP address. If the Elastic IP address is /// already associated with a different instance or a network interface, you get an error /// unless you allow reassociation. /// </para> /// /// <para> /// This is an idempotent operation. If you perform the operation more than once, Amazon /// EC2 doesn't return an error. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the AssociateAddress service method.</param> /// /// <returns>The response from the AssociateAddress service method, as returned by EC2.</returns> public AssociateAddressResponse AssociateAddress(AssociateAddressRequest request) { var marshaller = new AssociateAddressRequestMarshaller(); var unmarshaller = AssociateAddressResponseUnmarshaller.Instance; return Invoke<AssociateAddressRequest,AssociateAddressResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the AssociateAddress operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the AssociateAddress 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<AssociateAddressResponse> AssociateAddressAsync(AssociateAddressRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new AssociateAddressRequestMarshaller(); var unmarshaller = AssociateAddressResponseUnmarshaller.Instance; return InvokeAsync<AssociateAddressRequest,AssociateAddressResponse>(request, marshaller, unmarshaller, cancellationToken); }
internal AssociateAddressResponse AssociateAddress(AssociateAddressRequest request) { var task = AssociateAddressAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
private Amazon.EC2.Model.AssociateAddressResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.AssociateAddressRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "AssociateAddress"); try { #if DESKTOP return(client.AssociateAddress(request)); #elif CORECLR return(client.AssociateAddressAsync(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> /// <para>Associates an Elastic IP address with an instance or a network interface.</para> <para>An Elastic IP address is for use in either the /// EC2-Classic platform or in a VPC. For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html">Elastic IP Addresses</a> in the <i>Amazon Elastic /// Compute Cloud User Guide</i> .</para> <para>[EC2-Classic, default VPC] If the Elastic IP address is already associated with a different /// instance, it is disassociated from that instance and associated with the specified instance.</para> <para>[EC2-VPC] If you don't specify a /// private IP address, the Elastic IP address is associated with the primary IP address. If the Elastic IP address is already associated with a /// different instance or a network interface, you get an error unless you allow reassociation.</para> <para>This is an idempotent operation. If /// you perform the operation more than once, Amazon EC2 doesn't return an error.</para> /// </summary> /// /// <param name="associateAddressRequest">Container for the necessary parameters to execute the AssociateAddress service method on /// AmazonEC2.</param> /// /// <returns>The response from the AssociateAddress 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<AssociateAddressResponse> AssociateAddressAsync(AssociateAddressRequest associateAddressRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new AssociateAddressRequestMarshaller(); var unmarshaller = AssociateAddressResponseUnmarshaller.GetInstance(); return Invoke<IRequest, AssociateAddressRequest, AssociateAddressResponse>(associateAddressRequest, marshaller, unmarshaller, signer, cancellationToken); }