本文整理汇总了Java中com.amazonaws.services.ec2.model.Address类的典型用法代码示例。如果您正苦于以下问题:Java Address类的具体用法?Java Address怎么用?Java Address使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Address类属于com.amazonaws.services.ec2.model包,在下文中一共展示了Address类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllUnusedEIPs
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
/**
* This method returns all unused EIPs
* @return returns all unused EIPs
*/
public List<Address> getAllUnusedEIPs(List<Address> allEIPs) {
List<Address> allUnusedEIPs = new ArrayList<>();
if ( allEIPs != null || allEIPs.size() >0 ) {
for(Address address: allEIPs) {
if (address.getInstanceId() == null) {
allUnusedEIPs.add(address);
}
}
}
System.out.println("INFO : Number of Unused EIPs : " + allUnusedEIPs.size());
List<String> EIPs = allUnusedEIPs.stream().map( e -> e.getPublicIp()).collect(Collectors.toList());
System.out.println("INFO : Unused EIPs : " + EIPs);
return allUnusedEIPs;
}
示例2: createEvaluations
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
/**
* This method returns list of Evaluation objects.
* @param allUnusedEIPs
* @return List<Evaluation> returns list of Evaluation objects.
*/
private List<Evaluation> createEvaluations(List<Address> allUnusedEIPs) {
List<Evaluation> evaluations = new ArrayList<>();
if ( allUnusedEIPs == null || allUnusedEIPs.size() > 0 ) {
for(Address address: allUnusedEIPs) {
String EIP = address.getPublicIp();
Evaluation evaluation = new Evaluation();
evaluation.setComplianceResourceId(EIP);
evaluation.setComplianceResourceType(COMPLIANCE_RESOURCE_TYPE);
evaluation.setComplianceType(ComplianceType.NON_COMPLIANT);
evaluation.setOrderingTimestamp(new Date());
evaluations.add(evaluation);
}
}
System.out.println("INFO : Number of evaluations : " + evaluations.size());
return evaluations;
}
示例3: main
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
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());
}
}
示例4: itShouldStartAnEC2InstanceFromAnAMI
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Test
public void itShouldStartAnEC2InstanceFromAnAMI()
throws ServiceBrokerException {
when(
ec2Client.runInstances(awsRqst(r -> r.getImageId().equals(
"test_image")))).thenReturn(runInstanceResult);
when(ec2Client.describeAddresses()).thenReturn(
new DescribeAddressesResult().withAddresses(Collections
.singleton(new Address().withPublicIp("10.10.10.10"))));
when(ec2Client.describeInstanceStatus(any())).thenReturn(
new DescribeInstanceStatusResult()
.withInstanceStatuses(Collections
.singleton(new InstanceStatus()
.withInstanceState(new InstanceState()
.withName("running")))));
when(hostUtils.waitForBoot(anyString(), anyInt())).thenReturn(true);
assertThat(aws.startEC2Instance("test_image"),
is(equalTo("test_instance")));
}
示例5: checkAssociatedAddress
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public Address checkAssociatedAddress(AwsProcessClient awsProcessClient, Long instanceNo, Long addressNo) {
AwsAddress awsAddress = awsAddressDao.read(addressNo);
String publicIp = awsAddress.getPublicIp();
String instanceId = awsAddress.getInstanceId();
// アドレスが関連付けられているかどうかのチェック
Address address = awsCommonProcess.describeAddress(awsProcessClient, publicIp);
if (StringUtils.isEmpty(address.getInstanceId())) {
// アドレスがどのインスタンスにも関連付けられていない場合
throw new AutoException("EPROCESS-000120", publicIp, instanceId);
} else if (!StringUtils.equals(instanceId, address.getInstanceId())) {
// アドレスが他インスタンスに関連付けられている場合
throw new AutoException("EPROCESS-000121", publicIp, instanceId, address.getInstanceId());
}
return address;
}
示例6: describeAddress
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
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);
}
示例7: releaseReservedIp
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
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()));
}
}
示例8: testGetAllUnusedEIPs
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Test
public void testGetAllUnusedEIPs() {
EC2UtilsImpl ec2UtilsImpl = new EC2UtilsImpl();
List<Address> allUnusedEIPs = ec2UtilsImpl.getAllUnusedEIPs(allEIPs);
assertEquals(2, allUnusedEIPs.size());
}
示例9: itShouldReturnAFreeElasticIp
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Test
public void itShouldReturnAFreeElasticIp() throws ServiceBrokerException {
when(ec2Client.describeAddresses()).thenReturn(
new DescribeAddressesResult().withAddresses(Collections
.singleton(new Address().withPublicIp("10.10.10.10"))));
assertThat("10.10.10.10", is(aws.getAvaliableElasticIp()));
}
示例10: itShouldReturnOnlyOneFreeElasticIp
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Test
public void itShouldReturnOnlyOneFreeElasticIp()
throws ServiceBrokerException {
when(ec2Client.describeAddresses()).thenReturn(
new DescribeAddressesResult().withAddresses(Arrays.asList(
new Address().withPublicIp("10.10.10.10")
.withInstanceId(null),
new Address().withPublicIp("10.10.10.11")
.withInstanceId(null))));
assertThat("10.10.10.10", is(aws.getAvaliableElasticIp()));
}
示例11: itShouldFilterOutAttachedElasticIPs
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Test
public void itShouldFilterOutAttachedElasticIPs()
throws ServiceBrokerException {
when(ec2Client.describeAddresses()).thenReturn(
new DescribeAddressesResult().withAddresses(Arrays.asList(
new Address().withPublicIp("10.10.10.10")
.withInstanceId("the-instance"),
new Address().withPublicIp("10.10.10.11")
.withInstanceId(null))));
assertThat("10.10.10.11", is(aws.getAvaliableElasticIp()));
}
示例12: checkExistsAddress
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
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;
}
示例13: allocateAddress
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public static Address allocateAddress(AmazonEC2 ec2, DomainType domainType) {
AllocateAddressRequest addressRequest = new AllocateAddressRequest().withDomain(domainType);
AllocateAddressResult addressResult = ec2.allocateAddress(addressRequest);
Address address = new Address().withAllocationId(addressResult.getAllocationId())
.withDomain(addressResult.getDomain()).withPublicIp(addressResult.getPublicIp());
return address;
}
示例14: associateAddress
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
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;
}
示例15: execute
import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
/**
* Stop Ec2 Instance. Realease EIP for Ec2 Instance. Disassociate EIP.
*/
public int execute(Ec2CommandOptions options) throws FileNotFoundException {
System.out.println(getClass().getName());
String name = options.getName();
InputStream inputStream = new FileInputStream(new File(options.getCredentialsPath()));
ConfigProvider.loadConfigure(inputStream);
AmazonEC2 ec2 = AwsEc2Client.getEc2();
// Check Exists Instance
Instance instance = AwsEc2Client.findInstanceByName(ec2, name);
if (instance == null) {
System.err.println("Not exists instance (name = " + name + ").");
return 2;
}
String instanceId = instance.getInstanceId();
String publicIp = instance.getPublicIpAddress();
System.out.println("Exists instance (id = " + instanceId + ")");
// Stop Ec2 Instance
InstanceStateChange stateChange = AwsEc2Client.stopInstance(ec2, instanceId);
AwsEc2Client.showStateChange(stateChange, "Stopping Instance");
// Disassociate and Release Address
if (publicIp != null) {
Address address = AwsEc2Client.checkExistsAddress(ec2, publicIp);
if (address != null) {
AwsEc2Client.disassociateAddress(ec2, address);
System.out.println("Disassociated Address (" + publicIp + ")");
AwsEc2Client.releaseAddress(ec2, address);
System.out.println("Released Address (" + publicIp + ")");
}
} else {
System.out.println("No EIP.");
}
return 0;
}