public GetImageForVirtualGuest(SoftLayerApi api) {
this.api = api;
}
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 = api.getVirtualGuestApi().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"));
return new ProductItemToImage().apply(os);
}