Search in sources :

Example 86 with AmazonEC2

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

the class AWSRemoteCleanup method deleteSubnets.

private void deleteSubnets(String vpcId, AmazonEC2 usEastEc2Client) {
    DescribeSubnetsRequest subnetsRequest = new DescribeSubnetsRequest().withFilters(new Filter(VPC_KEY, Collections.singletonList(vpcId)));
    DescribeSubnetsResult securityGroupsResult = usEastEc2Client.describeSubnets(subnetsRequest);
    securityGroupsResult.getSubnets().forEach(subnet -> {
        DeleteSubnetRequest deleteSubnetRequest = new DeleteSubnetRequest().withSubnetId(subnet.getSubnetId());
        this.host.log("Terminating stale subnet: %s", subnet.getSubnetId());
        usEastEc2Client.deleteSubnet(deleteSubnetRequest);
    });
}
Also used : Filter(com.amazonaws.services.ec2.model.Filter) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest)

Example 87 with AmazonEC2

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

the class AWSRemoteCleanup method deleteStaleAwsVolumes.

@Test
public void deleteStaleAwsVolumes() {
    AmazonEC2 usEastEc2Client = this.ec2Clients.get(US_EAST_1_TAG);
    DescribeVolumesResult volumesResult = usEastEc2Client.describeVolumes();
    List<Volume> volumeList = volumesResult.getVolumes();
    for (Volume volume : volumeList) {
        long volumeCreationTimeMicros = TimeUnit.MILLISECONDS.toMicros(volume.getCreateTime().getTime());
        long timeDifference = Utils.getNowMicrosUtc() - volumeCreationTimeMicros;
        if (timeDifference > TimeUnit.HOURS.toMicros(1) && volume.getState().equalsIgnoreCase("available")) {
            this.host.log("Terminating stale volume: %s", volume.getVolumeId());
            DeleteVolumeRequest deleteVolumeRequest = new DeleteVolumeRequest().withVolumeId(volume.getVolumeId());
            usEastEc2Client.deleteVolume(deleteVolumeRequest);
        }
    }
}
Also used : DeleteVolumeRequest(com.amazonaws.services.ec2.model.DeleteVolumeRequest) Volume(com.amazonaws.services.ec2.model.Volume) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) Test(org.junit.Test)

Example 88 with AmazonEC2

use of com.amazonaws.services.ec2.AmazonEC2 in project checker-framework by typetools.

the class SimpleFalsePositive method test.

void test(AmazonEC2 ec2Client, String namePrefix) {
    DescribeImagesRequest request = new DescribeImagesRequest().withOwners("martin").withFilters(Arrays.asList(new Filter("platform", Arrays.asList("windows")), new Filter("name", Arrays.asList(String.format("%s*", namePrefix)))));
    DescribeImagesResult result = ec2Client.describeImages(request);
}
Also used : Filter(com.amazonaws.services.ec2.model.Filter) DescribeImagesResult(com.amazonaws.services.ec2.model.DescribeImagesResult) DescribeImagesRequest(com.amazonaws.services.ec2.model.DescribeImagesRequest)

Example 89 with AmazonEC2

use of com.amazonaws.services.ec2.AmazonEC2 in project checker-framework by typetools.

the class Cve2 method correct1.

public static void correct1(AmazonEC2 client) {
    DescribeImagesRequest request = new DescribeImagesRequest();
    request.withFilters(new Filter("name").withValues(IMG_NAME));
    request.withOwners("martin");
    DescribeImagesResult result = client.describeImages(request);
}
Also used : Filter(com.amazonaws.services.ec2.model.Filter) DescribeImagesResult(com.amazonaws.services.ec2.model.DescribeImagesResult) DescribeImagesRequest(com.amazonaws.services.ec2.model.DescribeImagesRequest)

Example 90 with AmazonEC2

use of com.amazonaws.services.ec2.AmazonEC2 in project checker-framework by typetools.

the class Cve2 method correct2.

public static void correct2(AmazonEC2 client) {
    DescribeImagesRequest request = new DescribeImagesRequest();
    request.withImageIds("myImageId");
    DescribeImagesResult result = client.describeImages(request);
}
Also used : DescribeImagesResult(com.amazonaws.services.ec2.model.DescribeImagesResult) DescribeImagesRequest(com.amazonaws.services.ec2.model.DescribeImagesRequest)

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