Search in sources :

Example 6 with CreateTagsRequest

use of com.amazonaws.services.ec2.model.CreateTagsRequest in project SimianArmy by Netflix.

the class AWSClient method createTagsForResources.

@Override
public void createTagsForResources(Map<String, String> keyValueMap, String... resourceIds) {
    Validate.notNull(keyValueMap);
    Validate.notEmpty(keyValueMap);
    Validate.notNull(resourceIds);
    Validate.notEmpty(resourceIds);
    AmazonEC2 ec2Client = ec2Client();
    List<Tag> tags = new ArrayList<Tag>();
    for (Map.Entry<String, String> entry : keyValueMap.entrySet()) {
        tags.add(new Tag(entry.getKey(), entry.getValue()));
    }
    CreateTagsRequest req = new CreateTagsRequest(Arrays.asList(resourceIds), tags);
    ec2Client.createTags(req);
}
Also used : AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) Tag(com.amazonaws.services.ec2.model.Tag)

Example 7 with CreateTagsRequest

use of com.amazonaws.services.ec2.model.CreateTagsRequest in project GNS by MobilityFirst.

the class AWSEC2 method addInstanceTag.

/**
   * Adds the key and value as a 'tag' for the instance.
   *
   * @param ec2
   * @param createdInstanceId
   * @param key
   * @param value
   */
public static void addInstanceTag(AmazonEC2 ec2, String createdInstanceId, String key, String value) {
    List<String> resources = new LinkedList<>();
    resources.add(createdInstanceId);
    List<Tag> tags = new LinkedList<>();
    Tag nameTag = new Tag(key, value);
    tags.add(nameTag);
    CreateTagsRequest ctr = new CreateTagsRequest(resources, tags);
    ec2.createTags(ctr);
}
Also used : CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) Tag(com.amazonaws.services.ec2.model.Tag) LinkedList(java.util.LinkedList)

Example 8 with CreateTagsRequest

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

the class AWSUtils method tagResources.

/**
 * Synchronous Tagging of one or many AWS resources with the provided tags.
 */
public static void tagResources(AmazonEC2AsyncClient client, Collection<Tag> tags, String... resourceIds) {
    if (isAwsClientMock()) {
        return;
    }
    CreateTagsRequest req = new CreateTagsRequest().withResources(resourceIds).withTags(tags);
    client.createTags(req);
}
Also used : CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest)

Example 9 with CreateTagsRequest

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

the class AwsMetadataCollector method addTag.

private void addTag(AmazonEC2 amazonEC2Client, CloudInstance cloudInstance, Instance instance) {
    String tagName = awsClient.getCbName(cloudInstance.getTemplate().getGroupName(), cloudInstance.getTemplate().getPrivateId());
    Tag t = new Tag();
    t.setKey(TAG_NAME);
    t.setValue(tagName);
    CreateTagsRequest ctr = new CreateTagsRequest();
    ctr.setTags(Collections.singletonList(t));
    ctr.withResources(instance.getInstanceId());
    amazonEC2Client.createTags(ctr);
}
Also used : CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) Tag(com.amazonaws.services.ec2.model.Tag)

Aggregations

CreateTagsRequest (com.amazonaws.services.ec2.model.CreateTagsRequest)8 Tag (com.amazonaws.services.ec2.model.Tag)7 CreateTagsResult (com.amazonaws.services.ec2.model.CreateTagsResult)3 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 LinkedList (java.util.LinkedList)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 RunInstancesRequest (com.amazonaws.services.ec2.model.RunInstancesRequest)1 RunInstancesResult (com.amazonaws.services.ec2.model.RunInstancesResult)1 Collection (java.util.Collection)1 Message (org.apache.camel.Message)1