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

项目:primecloud-controller    文件:AwsCommonProcess.java   
public Address describeAddress(AwsProcessClient awsProcessClient, String publicIp) {
    // 単一アドレスの参照
    DescribeAddressesRequest request = new DescribeAddressesRequest();
    request.withPublicIps(publicIp);
    DescribeAddressesResult result = awsProcessClient.getEc2Client().describeAddresses(request);
    List<Address> addresses = result.getAddresses();

    // API実行結果チェック
    if (addresses.size() == 0) {
        // アドレスが存在しない場合
        throw new AutoException("EPROCESS-000117", publicIp);

    } else if (addresses.size() > 1) {
        // アドレスを複数参照できた場合
        AutoException exception = new AutoException("EPROCESS-000118", publicIp);
        exception.addDetailInfo("result=" + addresses);
        throw exception;
    }

    return addresses.get(0);
}
项目:cloudbreak    文件:AwsResourceConnector.java   
private void releaseReservedIp(AmazonEC2Client client, List<CloudResource> resources) {
    CloudResource elasticIpResource = getReservedIp(resources);
    if (elasticIpResource != null && elasticIpResource.getName() != null) {
        Address address;
        try {
            DescribeAddressesResult describeResult = client.describeAddresses(
                    new DescribeAddressesRequest().withAllocationIds(elasticIpResource.getName()));
            address = describeResult.getAddresses().get(0);
        } catch (AmazonServiceException e) {
            if (e.getErrorMessage().equals("The allocation ID '" + elasticIpResource.getName() + "' does not exist")) {
                LOGGER.warn("Elastic IP with allocation ID '{}' not found. Ignoring IP release.", elasticIpResource.getName());
                return;
            } else {
                throw e;
            }
        }
        if (address.getAssociationId() != null) {
            client.disassociateAddress(new DisassociateAddressRequest().withAssociationId(elasticIpResource.getName()));
        }
        client.releaseAddress(new ReleaseAddressRequest().withAllocationId(elasticIpResource.getName()));
    }
}
项目:ec2-util    文件:AwsEc2Client.java   
public static Address checkExistsAddress(AmazonEC2 ec2, String targetIp) {
    DescribeAddressesRequest addressRequest = new DescribeAddressesRequest().withPublicIps(targetIp);
    DescribeAddressesResult addressResult = ec2.describeAddresses(addressRequest);
    List<Address> addresses = addressResult.getAddresses();
    for (Address address : addresses) {
        String publicIp = address.getPublicIp();
        if (targetIp.equals(publicIp)) {
            return address;
        }
        break;
    }
    return null;
}
项目:cmn-project    文件:EC2VPC.java   
public void releaseEIP(List<String> instanceIds) {
    logger.info("release EIP for instances, instanceIds={}", instanceIds);

    DescribeAddressesResult result = ec2.describeAddresses(new DescribeAddressesRequest().withFilters(new Filter("instance-id").withValues(instanceIds)));
    for (Address address : result.getAddresses()) {
        logger.info("release EIP, ip={}, instanceId={}", address.getPublicIp(), address.getInstanceId());
        ec2.disassociateAddress(new DisassociateAddressRequest().withAssociationId(address.getAssociationId()));
        ec2.releaseAddress(new ReleaseAddressRequest().withAllocationId(address.getAllocationId()));
    }
}
项目:cmn-project    文件:EC2VPC.java   
public NatGateway createNATGateway(String subnetId, String ip) {
    logger.info("create nat gateway, subnetId={}, ip={}", subnetId, ip);

    List<Address> addresses = AWS.vpc.ec2.describeAddresses(new DescribeAddressesRequest().withPublicIps(ip)).getAddresses();
    if (addresses.isEmpty()) throw new Error("cannot find eip, ip=" + ip);
    Address address = addresses.get(0);
    if (address.getAssociationId() != null) throw new Error("eip must not associated with other resource, ip=" + ip);

    CreateNatGatewayRequest request = new CreateNatGatewayRequest()
        .withSubnetId(subnetId)
        .withAllocationId(address.getAllocationId());
    String gatewayId = ec2.createNatGateway(request).getNatGateway().getNatGatewayId();

    NatGateway gateway;
    while (true) {
        Threads.sleepRoughly(Duration.ofSeconds(30));
        gateway = describeNATGateway(gatewayId);
        String state = gateway.getState();
        if ("pending".equals(state)) continue;
        if ("available".equals(state)) {
            break;
        } else {
            throw new Error("failed to create nat gateway, gatewayId=" + gatewayId + ", state=" + state);
        }
    }
    return gateway;
}
项目:clouck    文件:Ec2WrapperImpl.java   
@Override
public List<AbstractResource<?>> describeElasticIPs(Account account, Region region, DateTime dt, Ec2Filter... filters) {
    AmazonEC2 ec2 = findClient(account, region);

    DescribeAddressesRequest req = new DescribeAddressesRequest();
    for (Ec2Filter filter : filters) {
        Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues());
        req.withFilters(f);
    }

    log.debug("start describing elastic ips for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region);
    DescribeAddressesResult res = ec2.describeAddresses(req);

    return converter.toEc2ElasticIPs(res.getAddresses(), account.getId(), region, dt);
}
项目:elasticsearch_my    文件:AmazonEC2Mock.java   
@Override
public DescribeAddressesResult describeAddresses(DescribeAddressesRequest describeAddressesRequest) throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Not supported in mock");
}
项目:cloudbreak    文件:AwsResourceConnector.java   
private List<String> getFreeIps(List<String> eips, AmazonEC2Client amazonEC2Client) {
    DescribeAddressesResult addresses = amazonEC2Client.describeAddresses(new DescribeAddressesRequest().withAllocationIds(eips));
    return addresses.getAddresses().stream().filter(address -> address.getInstanceId() == null)
            .map(Address::getAllocationId).collect(Collectors.toList());
}