public void testCreateRunningInstance() throws Exception {
instance = createInstance(IMAGE_ID);
}
private RunningInstance createInstance(String imageId) throws UnknownHostException {
RunningInstance instance = null;
while (instance == null) {
try {
System.out.printf("%d: running instance%n", System.currentTimeMillis());
Reservation<? extends RunningInstance> reservation = client.getInstanceApi().get().runInstancesInRegion(
null, null, // allow
// ec2
// to
// chose
// an
// availability
// zone
imageId, 1, // minimum instances
1, // maximum instances
withKeyName(keyPair.getKeyName())// key I created above
.asType(InstanceType.M1_SMALL)// smallest instance
// size
.withSecurityGroup(securityGroupName));// group I
// created
// above
instance = Iterables.getOnlyElement(reservation);
} catch (HttpResponseException htpe) {
if (htpe.getResponse().getStatusCode() == 400)
continue;
throw htpe;
}
}
assertNotNull(instance.getId());
assertEquals(instance.getInstanceState(), InstanceState.PENDING);
instance = blockUntilWeCanSshIntoInstance(instance);
return instance;
}