com.amazonaws.services.ec2.model.DescribeAddressesResult Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.DescribeAddressesResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EC2InventoryUtilTest.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch elastic IP addresses test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchElasticIPAddressesTest() throws Exception { mockStatic(AmazonEC2ClientBuilder.class); AmazonEC2 ec2Client = PowerMockito.mock(AmazonEC2.class); AmazonEC2ClientBuilder amazonEC2ClientBuilder = PowerMockito.mock(AmazonEC2ClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonEC2ClientBuilder.standard()).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.withCredentials(anyObject())).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.withRegion(anyString())).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.build()).thenReturn(ec2Client); DescribeAddressesResult describeAddressesResult = new DescribeAddressesResult(); List<Address> elasticIPList = new ArrayList<>(); elasticIPList.add(new Address()); describeAddressesResult.setAddresses(elasticIPList); when(ec2Client.describeAddresses()).thenReturn(describeAddressesResult); assertThat(ec2InventoryUtil.fetchElasticIPAddresses(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(1)); }
Example #2
Source File: DescribeAddresses.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DescribeAddressesResult response = ec2.describeAddresses(); for(Address address : response.getAddresses()) { System.out.printf( "Found address with public IP %s, " + "domain %s, " + "allocation id %s " + "and NIC id %s", address.getPublicIp(), address.getDomain(), address.getAllocationId(), address.getNetworkInterfaceId()); } }
Example #3
Source File: AwsCommonProcess.java From primecloud-controller with GNU General Public License v2.0 | 6 votes |
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); }
Example #4
Source File: AwsElasticIpService.java From cloudbreak with Apache License 2.0 | 4 votes |
public List<String> getFreeIps(Collection<String> eips, AmazonEC2 amazonEC2Client) { DescribeAddressesResult addresses = amazonEC2Client.describeAddresses(new DescribeAddressesRequest().withAllocationIds(eips)); return addresses.getAddresses().stream().filter(address -> address.getInstanceId() == null) .map(Address::getAllocationId).collect(Collectors.toList()); }