public void testSaveServerToImage() throws IOException {
Predicate<Server> serverLatestJobCompleted = retry(new ServerLatestJobCompleted(api
.getJobServices()), 800, 20, SECONDS);
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
ServerImage image = null;
try {
Set<Ip> availableIps = api.getIpServices().getUnassignedPublicIpList();
Ip availableIp = Iterables.getLast(availableIps);
Server createdServer = api.getServerServices()
.addServer(nameOfServer, "5489", "1", availableIp.getIp());
assertNotNull(createdServer);
assert serverLatestJobCompleted.apply(createdServer);
image = api
.getImageServices()
.saveImageFromServer("friendlyName", createdServer.getName(),
SaveImageOptions.Builder.withDescription("description"));
assertEquals(image.getFriendlyName(), "friendlyName");
assertEquals(image.getDescription(), "description");
assertFalse(image.isPublic());
assertEventuallyImageStateEquals(image, ServerImageState.AVAILABLE);
api.getImageServices().deleteById(image.getId());
assertEventuallyImageStateEquals(image, ServerImageState.TRASH);
image = null;
} finally {
if (image != null)
try {
api.getImageServices().deleteById(image.getId());
} catch (Exception e) {
// not failing so that we can ensure server below deletes
e.printStackTrace();
}
// delete the server