EC2DescribeImagesResponse images = new EC2DescribeImagesResponse();
images = listTemplates( templateId, images );
EC2Image[] imageSet = images.getImageSet();
String osTypeId = imageSet[0].getOsTypeId();
CloudStackTemplate resp = getApi().createTemplate((request.getDescription() == null ? "" : request.getDescription()), request.getName(),
osTypeId, null, null, null, null, null, null, volumeId);
if (resp == null || resp.getId() == null) {
throw new EC2ServiceException(ServerError.InternalError, "An upexpected error occurred.");
}
//if template was created succesfully, create the new image response
response = new EC2CreateImageResponse();
response.setId(resp.getId());
// [C] If we stopped the virtual machine now we need to restart it
if (needsRestart) {
if (!startVirtualMachine( request.getInstanceId() ))
throw new EC2ServiceException(ServerError.InternalError,