Search in sources :

Example 1 with Ec2VirtualMachine

use of net.solarnetwork.central.cloud.aws.domain.Ec2VirtualMachine in project solarnetwork-central by SolarNetwork.

the class AwsVirtualMachineBiz method virtualMachinesForIds.

@Override
public Iterable<VirtualMachine> virtualMachinesForIds(Set<String> ids) {
    AmazonEC2 client = getEc2Client();
    DescribeInstancesRequest req = new DescribeInstancesRequest().withInstanceIds(ids);
    DescribeInstancesResult res;
    List<VirtualMachine> results = new ArrayList<>(ids.size());
    do {
        res = client.describeInstances(req);
        for (Reservation reservation : res.getReservations()) {
            for (Instance inst : reservation.getInstances()) {
                results.add(new Ec2VirtualMachine(inst));
            }
        }
        req.setNextToken(res.getNextToken());
    } while (res.getNextToken() != null);
    return results;
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Ec2VirtualMachine(net.solarnetwork.central.cloud.aws.domain.Ec2VirtualMachine) VirtualMachine(net.solarnetwork.central.cloud.domain.VirtualMachine) Ec2VirtualMachine(net.solarnetwork.central.cloud.aws.domain.Ec2VirtualMachine)

Example 2 with Ec2VirtualMachine

use of net.solarnetwork.central.cloud.aws.domain.Ec2VirtualMachine in project solarnetwork-central by SolarNetwork.

the class AwsVirtualMachineBiz method virtualMachineForName.

@Override
public VirtualMachine virtualMachineForName(String name) {
    AmazonEC2 client = getEc2Client();
    DescribeTagsRequest tagReq = new DescribeTagsRequest().withFilters(new Filter("key").withValues("Name"), new Filter("resource-type").withValues("instance"));
    DescribeTagsResult tagRes;
    do {
        tagRes = client.describeTags(tagReq);
        for (TagDescription tag : tagRes.getTags()) {
            if (name.equalsIgnoreCase(tag.getValue())) {
                String instanceId = tag.getResourceId();
                return new Ec2VirtualMachine(instanceId, tag.getValue());
            }
        }
        tagReq.setNextToken(tagRes.getNextToken());
    } while (tagRes.getNextToken() != null);
    return null;
}
Also used : DescribeTagsRequest(com.amazonaws.services.ec2.model.DescribeTagsRequest) DescribeTagsResult(com.amazonaws.services.ec2.model.DescribeTagsResult) Filter(com.amazonaws.services.ec2.model.Filter) TagDescription(com.amazonaws.services.ec2.model.TagDescription) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) Ec2VirtualMachine(net.solarnetwork.central.cloud.aws.domain.Ec2VirtualMachine)

Aggregations

AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 Ec2VirtualMachine (net.solarnetwork.central.cloud.aws.domain.Ec2VirtualMachine)2 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)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 Instance (com.amazonaws.services.ec2.model.Instance)1 Reservation (com.amazonaws.services.ec2.model.Reservation)1 TagDescription (com.amazonaws.services.ec2.model.TagDescription)1 ArrayList (java.util.ArrayList)1 VirtualMachine (net.solarnetwork.central.cloud.domain.VirtualMachine)1