use of org.platformlayer.ops.images.CloudImage in project platformlayer by platformlayer.
the class DiskImageController method build.
@Handler
public void build(DiskImage image) throws OpsException, IOException {
String imageId = Tag.IMAGE_ID.findUnique(image.getTags());
if (imageId == null) {
// Check for existing image
MachineProvider targetCloud = cloudHelpers.getCloud(image.cloud);
DiskImageRecipe recipe = platformLayer.getItem(image.recipeId, DiskImageRecipe.class);
ImageStore imageStore = cloud.getImageStore(targetCloud);
List<CloudImage> existingImages = imageStore.findImages(Collections.<Tag>emptyList());
for (CloudImage existingImage : existingImages) {
// TODO: Fetch the parent, fetch the description, see if it's a match??
log.info("Image found, but not know whether we can re-use: " + existingImage);
}
}
if (imageId == null) {
buildImage(image);
}
}
use of org.platformlayer.ops.images.CloudImage in project platformlayer by platformlayer.
the class GlanceImageStore method findImages.
@Override
public List<CloudImage> findImages(List<Tag> tags) throws OpsException {
List<CloudImage> matches = Lists.newArrayList();
OpenstackImageClient glanceClient = getOpenstackImageClient();
Iterable<Image> images;
try {
images = glanceClient.root().images().list(true);
} catch (OpenstackException e) {
throw new OpsException("Error listing images", e);
}
for (Image image : images) {
boolean match = true;
for (Tag tag : tags) {
match = false;
String tagKey = tag.getKey();
String tagValue = tag.getValue();
boolean checked = false;
if (ImageFormat.isImageFormatTag(tag)) {
ImageFormat format = ImageFormat.fromTag(tag);
// if ("qcow2".equals(tagValue)) {
// format = ImageFormat.DiskQcow2;
// } else {
// throw new UnsupportedOperationException("Unknown glance disk_format: " + tagValue);
// }
//
// Tag mappedTag = format.toTag();
//
// match = Objects.equal(mappedTag.getValue().getDiskFormat(), glanceDiskFormat);
// checked = true;
String glanceDiskFormat = mapToGlanceDiskFormat(format);
if (glanceDiskFormat != null) {
match = Objects.equal(image.getDiskFormat(), glanceDiskFormat);
checked = true;
}
}
if (!checked) {
for (Entry<String, Object> meta : image.getProperties().asMap().entrySet()) {
if (Objects.equal(tagKey, meta.getKey())) {
String content = (String) meta.getValue();
// OS BUG #885044: Content contains whitespace
content = content.trim();
if (content.equals(tagValue)) {
match = true;
}
}
}
}
if (!match) {
break;
}
}
if (match) {
matches.add(new GlanceImage(image));
}
}
return matches;
}
use of org.platformlayer.ops.images.CloudImage in project platformlayer by platformlayer.
the class ImageFactory method findBootstrapImage.
private CloudImage findBootstrapImage(ImageFormat format, ImageStore imageStore) throws OpsException {
// Tag formatTag = buildImageFormatTag(format);
//
// CloudImage image = imageStore.findImage(Lists.newArrayList(formatTag, BOOTSTRAP_IMAGE_TAG));
// if (image != null) {
// return image;
// }
Tag osDebian = Tag.build(Tag.IMAGE_OS_DISTRIBUTION, "debian.org");
Tag osSqueeze = Tag.build(Tag.IMAGE_OS_VERSION, "6.0.4");
Tag diskFormatTag;
switch(format) {
case DiskQcow2:
diskFormatTag = format.toTag();
break;
default:
log.warn("Unsupported format: " + format);
return null;
}
List<CloudImage> images = imageStore.findImages(Arrays.asList(diskFormatTag, osDebian, osSqueeze));
for (CloudImage candidate : images) {
return candidate;
}
return null;
}
Aggregations