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;
}
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;
}
Aggregations