本文整理匯總了Java中com.amazonaws.services.ec2.model.Reservation.getInstances方法的典型用法代碼示例。如果您正苦於以下問題:Java Reservation.getInstances方法的具體用法?Java Reservation.getInstances怎麽用?Java Reservation.getInstances使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.ec2.model.Reservation
的用法示例。
在下文中一共展示了Reservation.getInstances方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processResponse
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
private List<Instance> processResponse(DescribeInstancesResult response) {
List<Instance> returnedInstances = new ArrayList<>();
for (Reservation reservation : response.getReservations()) {
for (com.amazonaws.services.ec2.model.Instance instance : reservation.getInstances()) {
// Don't show dead servers or servers not tagged as belonging to Swordfish
if (instance.getState().getName().equals("terminated") || !instance.getTags().contains(new Tag().withKey("Swordfish").withValue("true"))) {
continue;
}
Instance instanceDetails = getInstanceDetails(instance);
returnedInstances.add(instanceDetails);
instanceRepository.save(instanceDetails);
refreshClient(instanceDetails);
}
}
return returnedInstances;
}
示例2: onSuccess
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Override
public void onSuccess(DescribeInstancesRequest request,
DescribeInstancesResult result) {
OperationContext.restoreOperationContext(this.opContext);
int totalNumberOfInstances = 0;
// Print the details of the instances discovered on the AWS endpoint
for (Reservation r : result.getReservations()) {
for (Instance i : r.getInstances()) {
++totalNumberOfInstances;
final int finalTotal1 = totalNumberOfInstances;
this.service.logFine(() -> String.format("%d=====Instance details %s =====",
finalTotal1, i.getInstanceId()));
this.aws.remoteInstanceIds.add(i.getInstanceId());
}
}
final int finalTotal2 = totalNumberOfInstances;
this.service.logFine(() -> String.format("Successfully enumerated %d instances on the"
+ " AWS host.", finalTotal2));
this.aws.subStage = this.next;
((AWSEnumerationAndDeletionAdapterService) this.service)
.deleteResourcesInLocalSystem(this.aws);
return;
}
示例3: forEachInstance
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
/**
* Iterates through the instances in the specified {@code DescribeInstancesResult}
* and calls the specified handler on each instance. This method will retrieve the
* follow-on {@code DescribeInstanceResult}s if the result holds a {@code nextToken}.
*
* @param result the {@code DescribeInstancesResult}
* @param instanceHandler the instance handler
*/
@VisibleForTesting
void forEachInstance(DescribeInstancesResult result, InstanceHandler instanceHandler) {
List<Reservation> reservations;
while (!(reservations = result.getReservations()).isEmpty()) {
for (Reservation reservation : reservations) {
for (Instance instance : reservation.getInstances()) {
LOG.debug("Calling instance handler with instance {}", instance);
instanceHandler.handle(instance);
}
}
if (result.getNextToken() != null) {
result = client.describeInstances(
new DescribeInstancesRequest().withNextToken(result.getNextToken()));
} else {
break;
}
}
}
示例4: describeInstances
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
/**
*
* @{inheritDoc
*/
@Override
public List<VMInformation> describeInstances(String... instanceIds) {
List<VMInformation> result = new ArrayList<VMInformation>();
try {
DescribeInstancesResult results = asynchEc2Client.describeInstances();
HashSet<String> ids = new HashSet<String>(Arrays.asList(instanceIds));
for (Reservation reservationDescription : results.getReservations()) {
for (com.amazonaws.services.ec2.model.Instance instance : reservationDescription.getInstances()) {
if (ids.contains(instance.getInstanceId())) {
result.add(new AmazonDataConverter().instanceToVmInformation(reservationDescription, instance, vmRegion));
}
}
// result.addAll(TypicaDataConverter.processReservationDescription(reservationDescription));
}
} catch (Exception e) {
LOG.error("Failed to retrieve instance from Amazon: " + e.getMessage());
throw new RuntimeException(e);
}
return result;
}
示例5: findInstancesOfType
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
/**
* @{inheritDoc
*/
@Override
public List<VMInformation> findInstancesOfType(VMRegion region, VMImageType type) {
List<VMInformation> ret = new ArrayList<VMInformation>();
try {
DescribeInstancesResult instances = asynchEc2Client.describeInstances();
InstanceDescription instanceForRegionAndType = new TankConfig().getVmManagerConfig().getInstanceForRegionAndType(region, type);
for (Reservation res : instances.getReservations()) {
if (res.getInstances() != null) {
for (com.amazonaws.services.ec2.model.Instance inst : res.getInstances()) {
if ((inst.getState().getName().equalsIgnoreCase("running") || inst.getState().getName().equalsIgnoreCase("pending"))
&& inst.getImageId().equals(instanceForRegionAndType.getAmi())) {
ret.add(new AmazonDataConverter().instanceToVmInformation(res, inst, region));
}
}
}
}
} catch (Exception e) {
LOG.error("Error getting instances: " + e.toString(), e);
throw new RuntimeException(e);
}
return ret;
}
示例6: findAllInstancesOfType
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
/**
* @{inheritDoc
*/
private List<VMInformation> findAllInstancesOfType(VMRegion region, VMImageType type) {
List<VMInformation> ret = new ArrayList<VMInformation>();
try {
DescribeInstancesResult instances = asynchEc2Client.describeInstances();
InstanceDescription instanceForRegionAndType = new TankConfig().getVmManagerConfig().getInstanceForRegionAndType(region, type);
for (Reservation res : instances.getReservations()) {
if (res.getInstances() != null) {
for (com.amazonaws.services.ec2.model.Instance inst : res.getInstances()) {
if (inst.getImageId().equals(instanceForRegionAndType.getAmi())) {
ret.add(new AmazonDataConverter().instanceToVmInformation(res, inst, region));
}
}
}
}
} catch (Exception e) {
LOG.error("Error getting instances: " + e.toString(), e);
throw new RuntimeException(e);
}
return ret;
}
示例7: getAllRunningInstances
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
public List<String> getAllRunningInstances() {
logger.info("Get running instances request");
DescribeInstancesRequest request = new DescribeInstancesRequest();
List<String> valuesT1 = new ArrayList<String>();
valuesT1.add(_defaultTag);
Filter filter1 = new Filter("tag:" + _tagKey, valuesT1);
List<String> valuesT2 = new ArrayList<String>();
valuesT2.add("running");
valuesT2.add("pending");
Filter filter2 = new Filter("instance-state-name",valuesT2);
DescribeInstancesResult result = _ec2.describeInstances(request.withFilters(filter1,filter2));
List<Reservation> reservations = result.getReservations();
List<String> instancesID = new ArrayList<String>();
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
for (Instance instance : instances) {
instancesID.add(instance.getInstanceId());
}
}
return instancesID;
}
示例8: findInstanceByName
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
/**
* Search Ec2 Instance by Name tag.
*
* @param ec2
* @param targetName
* Search Keyword for Name tag
* @return Instance with Name tag equals targetName. If it does't found,
* then return null.
*/
public static Instance findInstanceByName(AmazonEC2 ec2, String targetName) {
DescribeInstancesResult instanceResult = ec2.describeInstances();
List<Reservation> reservations = instanceResult.getReservations();
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
for (Instance instance : instances) {
List<Tag> tagList = instance.getTags();
String name = "";
for (Tag tag : tagList) {
String tagKey = tag.getKey();
String tagValue = tag.getValue();
if (tagKey.contains("Name")) {
name = tagValue;
if (targetName.equals(name)) {
return instance;
}
break;
}
}
}
}
return null;
}
示例9: checkTagsAws
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
protected static void checkTagsAws(Regions region, List<String> instanceIdList, Map<String, String> tagsToCheckMap) {
Map<String, String> extractedTagsToCheck = new HashMap<>();
List<Tag> extractedTags;
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(region).build();
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
describeInstancesRequest.withInstanceIds(instanceIdList);
DescribeInstancesResult describeInstancesResultAll = ec2.describeInstances(describeInstancesRequest);
List<Reservation> reservationsAll = describeInstancesResultAll.getReservations();
for (Reservation reservation : reservationsAll) {
for (Instance instance : reservation.getInstances()) {
extractedTags = instance.getTags();
Assert.assertNotNull(extractedTags);
for (Tag tag : extractedTags) {
extractedTagsToCheck.put(tag.getKey(), tag.getValue());
}
checkTags(tagsToCheckMap, extractedTagsToCheck);
extractedTags.clear();
}
}
}
示例10: getEnvironmentsByTag
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
public List<ServerEnvironment> getEnvironmentsByTag(Region region, String searchTag) {
LOGGER.info("getEnvironmentsByTag " + region + " tag: " + searchTag);
List<ServerEnvironment> environments = new ArrayList<ServerEnvironment>();
ec2.setRegion(region);
DescribeInstancesResult instances = ec2.describeInstances();
for (Reservation reservation : instances.getReservations()) {
for (Instance instance : reservation.getInstances()) {
for (Tag tag : instance.getTags()) {
if (tag.getValue().equalsIgnoreCase(searchTag)) {
environments.add(getEnvironmentFromInstance(instance));
}
}
}
}
return environments;
}
示例11: tagEnvironmentWithVersion
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Override
public boolean tagEnvironmentWithVersion(Region region, DeployJobVariables jobVariables) {
String searchTag = jobVariables.getEnvironment();
String version = jobVariables.getVersion();
LOGGER.info("tagEnvironmentWithVersion " + region + " Tag " + searchTag + " version " + version);
boolean environmentSuccessfulTagged = false;
ec2.setRegion(region);
DescribeInstancesResult instances = ec2.describeInstances();
for (Reservation reservation : instances.getReservations()) {
for (Instance instance : reservation.getInstances()) {
for (Tag tag : instance.getTags()) {
if (tag.getValue().equalsIgnoreCase(searchTag)) {
CreateTagsRequest createTagsRequest = new CreateTagsRequest();
createTagsRequest.withResources(instance.getInstanceId()).withTags(new Tag(VERSION_TAG, version));
LOGGER.info("Create Tag " + version + " for instance " + instance.getInstanceId());
ec2.createTags(createTagsRequest);
environmentSuccessfulTagged = true;
}
}
}
}
return environmentSuccessfulTagged;
}
示例12: describeInstances
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
private Instances describeInstances(DescribeInstancesRequest request)
{
final Instances instances = new Instances();
DescribeInstancesResult result = ec2_.describeInstances(request);
for (Reservation reservation : result.getReservations())
{
for (Instance instance : reservation.getInstances())
{
instances.addInstance(toExcaliburInstance(instance, null));
}
}
return instances;
}
示例13: getInstancesForGroup
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
/***
* Get list of EC2 {@link Instance}s for a auto scaling group
*
* @param groupName Auto scaling group name
* @param status Instance status (eg. running)
* @return List of EC2 instances found for the input auto scaling group
*/
public List<Instance> getInstancesForGroup(String groupName,
String status) {
final AmazonEC2 amazonEC2 = getEc2Client();
final DescribeInstancesResult instancesResult = amazonEC2.describeInstances(new DescribeInstancesRequest()
.withFilters(new Filter().withName("tag:aws:autoscaling:groupName").withValues(groupName)));
final List<Instance> instances = new ArrayList<>();
for (Reservation reservation : instancesResult.getReservations()) {
for (Instance instance : reservation.getInstances()) {
if (null == status|| null == instance.getState()
|| status.equals(instance.getState().getName())) {
instances.add(instance);
LOGGER.info("Found instance: " + instance + " which qualified filter: " + status);
} else {
LOGGER.info("Found instance: " + instance + " but did not qualify for filter: " + status);
}
}
}
return instances;
}
示例14: ifInstancePending
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
public boolean ifInstancePending(List<String> instanceIDs) {
System.out.println("Checking to determine if a Instance is in Pending state...");
DescribeInstancesRequest describeInstancesRequest=new DescribeInstancesRequest().withInstanceIds(instanceIDs);
List<Reservation> reservations = ec2.describeInstances(describeInstancesRequest)
.getReservations();
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
for (Instance instance : instances) {
System.out.println(" "
+ instance.getInstanceId()
+ " is in the " + instance.getState().getName()
+ " state.");
if (instance.getState().getName().equals("pending"))
return true;
}
}
return false;
}
示例15: getInstanceNumWithTag
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
public int getInstanceNumWithTag(Tag t) {
assert (t != null);
int num = 0;
List<Reservation> reservations = ec2.describeInstances()
.getReservations();
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
for (Instance instance : instances) {
if (!instance.getState().getName().equals("pending")
&& !instance.getState().getName().equals("running"))
continue;
List<Tag> tags = instance.getTags();
for (Tag tag : tags) {
if (tag.getKey().equals(t.getKey())
&& tag.getValue().equals(t.getValue())) {
num++;
break;
}
}
}
}
return num;
}