public GetImageForVirtualGuest(SoftLayerClient client) {
this.client = client;
}
public Image getImage(VirtualGuest guest) {
ProductOrder order = null;
// 'bad' orders have no start cpu's and cause the order lookup to fail.
if (guest.getStartCpus() < 1)
return null;
try {
order = client.getVirtualGuestClient().getOrderTemplate(guest.getId());
} catch (SoftLayerOrderItemDuplicateException e) {
// this is a workaround because SoftLayer throws sometimes 500 internal server errors for the above method call
logger.warn(e, "Cannot get order template for virtualGuestId(%s)", guest.getId());
}
if (order == null)
return null;
Iterable<ProductItem> items = Iterables.transform(order.getPrices(), ProductItems.item());
ProductItem os = Iterables.find(items, ProductItemPredicates.categoryCode("os"));
if (os.getPrices().isEmpty())
return null;
return new ProductItemToImage().apply(os);
}