String script = new ScriptBuilder() // lamp install script
.addStatement(exec("runurl run.alestic.com/apt/upgrade"))//
.addStatement(exec("runurl run.alestic.com/install/lamp"))//
.render(OsFamily.UNIX);
RunningInstance instance = null;
while (instance == null) {
try {
System.out.printf("%d: running instance%n", System.currentTimeMillis());
Reservation<? extends RunningInstance> reservation = client.getInstanceServices().runInstancesInRegion(
null, null, // allow
// ec2
// to
// chose
// an
// availability
// zone
"ami-ccf615a5", // alestic ami allows auto-invoke of
// user data scripts
1, // minimum instances
1, // maximum instances
asType(InstanceType.M1_SMALL) // smallest instance size
.withKeyName(keyPair.getKeyName()) // key I
// created
// above
.withSecurityGroup(securityGroupName) // group I
// created
// above
.withUserData(script.getBytes())); // script to
// run as root
instance = Iterables.getOnlyElement(reservation);
} catch (HttpResponseException htpe) {
if (htpe.getResponse().getStatusCode() == 400)
continue;
throw htpe;
}
}
assertNotNull(instance.getId());
instanceId = instance.getId();
assertEquals(instance.getInstanceState(), InstanceState.PENDING);
instance = blockUntilWeCanSshIntoInstance(instance);
verifyInstanceProperties(script);
tryToChangeStuff();
sshPing(instance);