Search in sources :

Example 26 with AmazonEC2

use of com.amazonaws.services.ec2.AmazonEC2 in project photon-model by vmware.

the class AWSRemoteCleanup method disassociateAndDeleteNetworkACLs.

private void disassociateAndDeleteNetworkACLs(String vpcId, AmazonEC2 usEastEc2Client) {
    DescribeNetworkAclsRequest networkAclsRequest = new DescribeNetworkAclsRequest().withFilters(new Filter(VPC_KEY, Collections.singletonList(vpcId)));
    DescribeNetworkAclsResult networkAclsResult = usEastEc2Client.describeNetworkAcls(networkAclsRequest);
    networkAclsResult.getNetworkAcls().stream().filter(networkAcl -> !(networkAcl.getIsDefault())).forEach(networkAcl -> {
        DeleteNetworkAclRequest deleteNetworkAclRequest = new DeleteNetworkAclRequest().withNetworkAclId(networkAcl.getNetworkAclId());
        this.host.log("Terminating stale network acl: %s", networkAcl.getNetworkAclId());
        usEastEc2Client.deleteNetworkAcl(deleteNetworkAclRequest);
    });
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) DescribeNetworkAclsResult(com.amazonaws.services.ec2.model.DescribeNetworkAclsResult) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) DeleteVpnGatewayRequest(com.amazonaws.services.ec2.model.DeleteVpnGatewayRequest) TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) ReleaseAddressRequest(com.amazonaws.services.ec2.model.ReleaseAddressRequest) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Utils(com.vmware.xenon.common.Utils) DescribeNetworkAclsRequest(com.amazonaws.services.ec2.model.DescribeNetworkAclsRequest) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) DescribeNetworkInterfacesResult(com.amazonaws.services.ec2.model.DescribeNetworkInterfacesResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) Reservation(com.amazonaws.services.ec2.model.Reservation) DeleteVpcRequest(com.amazonaws.services.ec2.model.DeleteVpcRequest) DescribeInternetGatewaysResult(com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) DeleteNetworkInterfaceRequest(com.amazonaws.services.ec2.model.DeleteNetworkInterfaceRequest) List(java.util.List) Tag(com.amazonaws.services.ec2.model.Tag) DeleteInternetGatewayRequest(com.amazonaws.services.ec2.model.DeleteInternetGatewayRequest) BasicTestCase(com.vmware.xenon.common.BasicTestCase) HashMap(java.util.HashMap) DeleteNetworkAclRequest(com.amazonaws.services.ec2.model.DeleteNetworkAclRequest) DescribeNetworkInterfacesRequest(com.amazonaws.services.ec2.model.DescribeNetworkInterfacesRequest) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Regions(com.amazonaws.regions.Regions) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) DisassociateAddressRequest(com.amazonaws.services.ec2.model.DisassociateAddressRequest) DescribeSecurityGroupsResult(com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DescribeSecurityGroupsRequest(com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest) Filter(com.amazonaws.services.ec2.model.Filter) Volume(com.amazonaws.services.ec2.model.Volume) DescribeVpnGatewaysResult(com.amazonaws.services.ec2.model.DescribeVpnGatewaysResult) Instance(com.amazonaws.services.ec2.model.Instance) Before(org.junit.Before) Vpc(com.amazonaws.services.ec2.model.Vpc) DescribeNatGatewaysResult(com.amazonaws.services.ec2.model.DescribeNatGatewaysResult) Test(org.junit.Test) DescribeAddressesRequest(com.amazonaws.services.ec2.model.DescribeAddressesRequest) DetachInternetGatewayRequest(com.amazonaws.services.ec2.model.DetachInternetGatewayRequest) DetachVpnGatewayRequest(com.amazonaws.services.ec2.model.DetachVpnGatewayRequest) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest) DeleteNatGatewayRequest(com.amazonaws.services.ec2.model.DeleteNatGatewayRequest) Bucket(com.amazonaws.services.s3.model.Bucket) DeleteSecurityGroupRequest(com.amazonaws.services.ec2.model.DeleteSecurityGroupRequest) DescribeNatGatewaysRequest(com.amazonaws.services.ec2.model.DescribeNatGatewaysRequest) TimeUnit(java.util.concurrent.TimeUnit) DescribeVpnGatewaysRequest(com.amazonaws.services.ec2.model.DescribeVpnGatewaysRequest) DeleteVolumeRequest(com.amazonaws.services.ec2.model.DeleteVolumeRequest) DescribeAddressesResult(com.amazonaws.services.ec2.model.DescribeAddressesResult) Collections(java.util.Collections) DescribeInternetGatewaysRequest(com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest) DeleteNetworkAclRequest(com.amazonaws.services.ec2.model.DeleteNetworkAclRequest) DescribeNetworkAclsRequest(com.amazonaws.services.ec2.model.DescribeNetworkAclsRequest) Filter(com.amazonaws.services.ec2.model.Filter) DescribeNetworkAclsResult(com.amazonaws.services.ec2.model.DescribeNetworkAclsResult)

Example 27 with AmazonEC2

use of com.amazonaws.services.ec2.AmazonEC2 in project photon-model by vmware.

the class TestUtils method getEC2SynchronousClient.

public static AmazonEC2 getEC2SynchronousClient(AuthCredentialsServiceState credentials, String region) {
    ClientConfiguration configuration = AWSUtils.createClientConfiguration();
    AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(credentials.privateKeyId, EncryptionUtils.decrypt(credentials.privateKey)));
    AmazonEC2ClientBuilder ec2ClientBuilder = AmazonEC2ClientBuilder.standard().withCredentials(awsStaticCredentialsProvider).withRegion(region).withClientConfiguration(configuration);
    return ec2ClientBuilder.build();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonEC2ClientBuilder(com.amazonaws.services.ec2.AmazonEC2ClientBuilder) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 28 with AmazonEC2

use of com.amazonaws.services.ec2.AmazonEC2 in project iep by Netflix.

the class AwsClientFactoryTest method getInstanceName.

@Test
public void getInstanceName() throws Exception {
    AwsClientFactory factory = new AwsClientFactory(config);
    AmazonEC2 ec2 = factory.getInstance("ec2-test", AmazonEC2.class);
    Assert.assertNotNull(ec2);
    Assert.assertSame(ec2, factory.getInstance("ec2-test", AmazonEC2.class));
    Assert.assertNotSame(ec2, factory.getInstance(AmazonEC2.class));
}
Also used : AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) Test(org.junit.Test)

Example 29 with AmazonEC2

use of com.amazonaws.services.ec2.AmazonEC2 in project iep by Netflix.

the class AwsClientFactoryTest method newInstanceInterface.

@Test
public void newInstanceInterface() throws Exception {
    AwsClientFactory factory = new AwsClientFactory(config);
    AmazonEC2 ec2 = factory.newInstance(AmazonEC2.class);
    Assert.assertNotNull(ec2);
}
Also used : AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) Test(org.junit.Test)

Example 30 with AmazonEC2

use of com.amazonaws.services.ec2.AmazonEC2 in project cloudbreak by hortonworks.

the class AwsMetadataCollector method collectGroupMetaData.

private Collection<CloudVmMetaDataStatus> collectGroupMetaData(AuthenticatedContext ac, AmazonAutoScaling amazonASClient, AmazonEC2 amazonEC2Client, AmazonCloudFormation amazonCFClient, String groupName, Iterable<CloudInstance> cloudInstances) {
    Collection<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
    String asGroupName = cloudFormationStackUtil.getAutoscalingGroupName(ac, amazonCFClient, groupName);
    List<String> instanceIds = cloudFormationStackUtil.getInstanceIds(amazonASClient, asGroupName);
    DescribeInstancesRequest instancesRequest = cloudFormationStackUtil.createDescribeInstancesRequest(instanceIds);
    DescribeInstancesResult instancesResult = amazonEC2Client.describeInstances(instancesRequest);
    // contains instances with instanceId
    Map<String, CloudInstance> mapByInstanceId = mapByInstanceId(cloudInstances);
    // contains instances with privateId (without instanceId)
    Queue<CloudInstance> untrackedInstances = untrackedInstances(cloudInstances);
    for (Reservation reservation : instancesResult.getReservations()) {
        LOGGER.info("Number of instances found in reservation: {}", reservation.getInstances().size());
        for (Instance instance : reservation.getInstances()) {
            String instanceId = instance.getInstanceId();
            CloudInstance cloudInstance = ensureInstanceTag(mapByInstanceId, instance, instanceId, untrackedInstances, amazonEC2Client);
            if (cloudInstance != null) {
                CloudInstanceMetaData md = new CloudInstanceMetaData(instance.getPrivateIpAddress(), instance.getPublicIpAddress());
                CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
                CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, md);
                cloudVmMetaDataStatuses.add(cloudVmMetaDataStatus);
            }
        }
    }
    return cloudVmMetaDataStatuses;
}
Also used : CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Instance(com.amazonaws.services.ec2.model.Instance) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)

Aggregations

AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)65 Filter (com.amazonaws.services.ec2.model.Filter)25 Instance (com.amazonaws.services.ec2.model.Instance)20 DescribeImagesRequest (com.amazonaws.services.ec2.model.DescribeImagesRequest)17 DescribeImagesResult (com.amazonaws.services.ec2.model.DescribeImagesResult)15 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)12 Reservation (com.amazonaws.services.ec2.model.Reservation)12 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)10 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)9 DescribeAddressesResult (com.amazonaws.services.ec2.model.DescribeAddressesResult)8 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)8 Tag (com.amazonaws.services.ec2.model.Tag)8 AWSCredentials (com.amazonaws.auth.AWSCredentials)6 DescribeAddressesRequest (com.amazonaws.services.ec2.model.DescribeAddressesRequest)6 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)5 DescribeSecurityGroupsResult (com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)5 DisassociateAddressRequest (com.amazonaws.services.ec2.model.DisassociateAddressRequest)5 ReleaseAddressRequest (com.amazonaws.services.ec2.model.ReleaseAddressRequest)5 AmazonServiceException (com.amazonaws.AmazonServiceException)4