Search in sources :

Example 1 with TagDescription

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

the class TestAWSUtils method testResourceNaming.

@Test
public void testResourceNaming() throws Throwable {
    boolean tagFound = false;
    AmazonEC2AsyncClient client = TestUtils.getClient(this.privateKeyId, this.privateKey, this.region, false);
    // create something to name
    AWSNetworkClient svc = new AWSNetworkClient(client);
    String vpcID = svc.createVPC("10.20.0.0/16");
    AWSUtils.tagResourcesWithName(client, TEST_NAME, vpcID);
    List<TagDescription> tags = AWSUtils.getResourceTags(vpcID, client);
    for (TagDescription tagDesc : tags) {
        if (tagDesc.getKey().equalsIgnoreCase(AWS_TAG_NAME)) {
            assertTrue(tagDesc.getValue().equalsIgnoreCase(TEST_NAME));
            tagFound = true;
            break;
        }
    }
    // ensure we found the tag
    assertTrue(tagFound);
    svc.deleteVPC(vpcID);
}
Also used : AWSNetworkClient(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSNetworkClient) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) TagDescription(com.amazonaws.services.ec2.model.TagDescription) Test(org.junit.Test)

Example 2 with TagDescription

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

the class AWSUtils method getResourceTags.

/*
     * Return the tags for a giving resource
     */
public static List<TagDescription> getResourceTags(String resourceID, AmazonEC2AsyncClient client) {
    Filter resource = new Filter().withName(AWS_FILTER_RESOURCE_ID).withValues(resourceID);
    DescribeTagsRequest req = new DescribeTagsRequest().withFilters(resource);
    DescribeTagsResult result = client.describeTags(req);
    return result.getTags();
}
Also used : DescribeTagsRequest(com.amazonaws.services.ec2.model.DescribeTagsRequest) DescribeTagsResult(com.amazonaws.services.ec2.model.DescribeTagsResult) Filter(com.amazonaws.services.ec2.model.Filter)

Aggregations

AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 DescribeTagsRequest (com.amazonaws.services.ec2.model.DescribeTagsRequest)1 DescribeTagsResult (com.amazonaws.services.ec2.model.DescribeTagsResult)1 Filter (com.amazonaws.services.ec2.model.Filter)1 TagDescription (com.amazonaws.services.ec2.model.TagDescription)1 AWSNetworkClient (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSNetworkClient)1 Test (org.junit.Test)1