Java 类com.amazonaws.services.ec2.model.AssociateAddressRequest 实例源码

项目:data-lifecycle-service-broker    文件:AWSHelper.java   
/**
 * Associate the next available elastic IP with an instance.
 * 
 * @param instanceId
 * @throws ServiceBrokerException
 */
public void addElasticIp(String instanceId) throws ServiceBrokerException {
    AssociateAddressRequest addressRequest = new AssociateAddressRequest()
            .withInstanceId(instanceId).withPublicIp(
                    getAvaliableElasticIp());
    log.info("Associating " + addressRequest.getPublicIp()
            + " with instance " + instanceId);
    if (waitForInstance(instanceId)) {
        ec2Client.associateAddress(addressRequest);
    } else {
        throw new ServiceBrokerException(
                "Instance did not transition to 'running' in alotted time.");
    }
    // We need the machine to boot before this will work.
    if (!hostUtils.waitForBoot(addressRequest.getPublicIp(), bootCheckPort)) {
        throw new ServiceBrokerException(
                "Host failed to boot in time alotted");
    }
}
项目:vpc2vpc    文件:CreateConnection.java   
private void associatePublicIP(List<VPNEndpoint> vpnEndpoints) throws Exception {
  for (VPNEndpoint vpnEndpoint : vpnEndpoints) {
    ec2Client.setEndpoint(vpnEndpoint.getRegion().getEndpoint());

    Instance instance = vpnEndpoint.getInstance();

    // Associate Elastic IP (Public IP)
    AssociateAddressRequest assocAddrReq = new AssociateAddressRequest();
    assocAddrReq.setInstanceId(instance.getInstanceId());
    assocAddrReq.setAllocationId(vpnEndpoint.getElasticIPAllocationId());
    String associationId =
            ec2Client.associateAddress(assocAddrReq).getAssociationId();
    LOG.debug("Associated public IP " + vpnEndpoint.getElasticIPAddress() + " with instance " + instance);

  }

}
项目:aws-doc-sdk-examples    文件:AllocateAddress.java   
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply an instance id\n" +
        "Ex: AllocateAddress <instance_id>\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String instance_id = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    AllocateAddressRequest allocate_request = new AllocateAddressRequest()
        .withDomain(DomainType.Vpc);

    AllocateAddressResult allocate_response =
        ec2.allocateAddress(allocate_request);

    String allocation_id = allocate_response.getAllocationId();

    AssociateAddressRequest associate_request =
        new AssociateAddressRequest()
            .withInstanceId(instance_id)
            .withAllocationId(allocation_id);

    AssociateAddressResult associate_response =
        ec2.associateAddress(associate_request);

    System.out.printf(
        "Successfully associated Elastic IP address %s " +
        "with instance %s",
        associate_response.getAssociationId(),
        instance_id);
}
项目:ec2-util    文件:AwsEc2Client.java   
public static String associateAddress(AmazonEC2 ec2, Address address, String instanceId) {
    AssociateAddressRequest addressRequest = new AssociateAddressRequest()
            .withAllocationId(address.getAllocationId()).withInstanceId(instanceId);
    AssociateAddressResult addressResult = ec2.associateAddress(addressRequest);
    String associationId = addressResult.getAssociationId();
    return associationId;
}
项目:cmn-project    文件:EC2VPC.java   
public String assignEIP(final String instanceId) throws Exception {
    final AllocateAddressResult address = ec2.allocateAddress(new AllocateAddressRequest().withDomain("vpc"));
    logger.info("associate eip to instance, instanceId={}, ip={}", instanceId, address.getPublicIp());

    new Runner<>()
        .retryInterval(Duration.ofSeconds(10))
        .maxAttempts(3)
        .retryOn(e -> e instanceof AmazonServiceException)
        .run(() -> {
            ec2.associateAddress(new AssociateAddressRequest().withInstanceId(instanceId).withAllocationId(address.getAllocationId()));
            return null;
        });

    return address.getPublicIp();
}
项目:primecloud-controller    文件:AwsAddressProcess.java   
public void associateAddress(AwsProcessClient awsProcessClient, Long instanceNo, Long addressNo, Address address) {
    AwsAddress awsAddress = awsAddressDao.read(addressNo);
    AwsInstance awsInstance = awsInstanceDao.read(instanceNo);

    // アドレスの関連付け
    AssociateAddressRequest request = new AssociateAddressRequest();
    request.withInstanceId(awsInstance.getInstanceId());

    // VPCの場合
    if (BooleanUtils.isTrue(awsProcessClient.getPlatformAws().getVpc())) {
        // 割り当てIDを指定する
        request.withAllocationId(address.getAllocationId());
    }
    // 非VPCの場合
    else {
        request.withPublicIp(awsAddress.getPublicIp());
    }

    awsProcessClient.getEc2Client().associateAddress(request);

    // ログ出力
    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100131", awsAddress.getPublicIp(), awsInstance.getInstanceId()));
    }

    // イベントログ出力
    Instance instance2 = instanceDao.read(instanceNo);
    processLogger.debug(null, instance2, "AwsElasticIpAssociate", new Object[] { awsInstance.getInstanceId(),
            awsAddress.getPublicIp() });

    // データベースの更新
    awsAddress.setInstanceId(awsInstance.getInstanceId());
    awsAddressDao.update(awsAddress);
}
项目:DeployMan    文件:Ec2.java   
public void associate(String instanceId, String elasticIp) {
  Instance instance = getEC2InstanceById(instanceId);

  console.write("Associate " + instance.getInstanceId() + " with IP " + elasticIp); //$NON-NLS-1$ //$NON-NLS-2$
  console.newLine();

  getClient().associateAddress(
      new AssociateAddressRequest().withInstanceId(instance.getInstanceId()).withPublicIp(
          elasticIp));

}
项目:roboconf-platform    文件:Ec2MachineConfigurator.java   
/**
 * Associates an elastic IP with the VM.
 * @return true if there is nothing more to do about elastic IP configuration, false otherwise
 */
private boolean associateElasticIp() {

    String elasticIp = this.targetProperties.get( Ec2Constants.ELASTIC_IP );
    if( ! Utils.isEmptyOrWhitespaces( elasticIp )) {
        this.logger.fine( "Associating an elastic IP with the instance. IP = " + elasticIp );
        AssociateAddressRequest associateAddressRequest = new AssociateAddressRequest( this.machineId, elasticIp );
        this.ec2Api.associateAddress( associateAddressRequest );
    }

    return true;
}
项目:elasticsearch_my    文件:AmazonEC2Mock.java   
@Override
public AssociateAddressResult associateAddress(AssociateAddressRequest associateAddressRequest) throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Not supported in mock");
}
项目:cloudbreak    文件:AwsResourceConnector.java   
private void associateElasticIpToInstance(AmazonEC2Client amazonEC2Client, String eipAllocationId, String instanceId) {
    AssociateAddressRequest associateAddressRequest = new AssociateAddressRequest()
            .withAllocationId(eipAllocationId)
            .withInstanceId(instanceId);
    amazonEC2Client.associateAddress(associateAddressRequest);
}