Search in sources :

Example 6 with CloudImage

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);
    }
}
Also used : MachineProvider(org.platformlayer.ops.machines.MachineProvider) DiskImageRecipe(org.platformlayer.images.model.DiskImageRecipe) CloudImage(org.platformlayer.ops.images.CloudImage) ImageStore(org.platformlayer.ops.images.ImageStore) Handler(org.platformlayer.ops.Handler)

Example 7 with CloudImage

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;
}
Also used : OpsException(org.platformlayer.ops.OpsException) CloudImage(org.platformlayer.ops.images.CloudImage) Image(org.openstack.model.image.Image) CloudImage(org.platformlayer.ops.images.CloudImage) OpenstackException(org.openstack.client.OpenstackException) ImageFormat(org.platformlayer.ops.images.ImageFormat) OpenstackImageClient(org.openstack.client.common.OpenstackImageClient) JSONObject(org.json.JSONObject) Tag(org.platformlayer.core.model.Tag)

Example 8 with CloudImage

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;
}
Also used : CloudImage(org.platformlayer.ops.images.CloudImage) Tag(org.platformlayer.core.model.Tag)

Aggregations

CloudImage (org.platformlayer.ops.images.CloudImage)8 OpsException (org.platformlayer.ops.OpsException)5 ImageFormat (org.platformlayer.ops.images.ImageFormat)5 Tag (org.platformlayer.core.model.Tag)3 OpenstackException (org.openstack.client.OpenstackException)2 DiskImageRecipe (org.platformlayer.images.model.DiskImageRecipe)2 Handler (org.platformlayer.ops.Handler)2 ImageStore (org.platformlayer.ops.images.ImageStore)2 MachineProvider (org.platformlayer.ops.machines.MachineProvider)2 File (java.io.File)1 Properties (java.util.Properties)1 JSONObject (org.json.JSONObject)1 OpenstackComputeClient (org.openstack.client.common.OpenstackComputeClient)1 OpenstackImageClient (org.openstack.client.common.OpenstackImageClient)1 AsyncServerOperation (org.openstack.client.compute.AsyncServerOperation)1 CreateSecurityGroupRuleRequest (org.openstack.model.compute.CreateSecurityGroupRuleRequest)1 Flavor (org.openstack.model.compute.Flavor)1 Image (org.openstack.model.compute.Image)1 KeyPair (org.openstack.model.compute.KeyPair)1 Metadata (org.openstack.model.compute.Metadata)1