Search in sources :

Example 1 with DirectCloud

use of org.platformlayer.service.cloud.direct.model.DirectCloud in project platformlayer by platformlayer.

the class DirectCloudUtils method getSharedNetworkKey.

private static PlatformLayerKey getSharedNetworkKey() {
    DirectCloud cloud = OpsContext.get().getInstance(DirectCloud.class);
    DirectHost host = OpsContext.get().getInstance(DirectHost.class);
    PlatformLayerKey sharedNetwork = host.network;
    if (sharedNetwork == null) {
        sharedNetwork = cloud.network;
    }
    return sharedNetwork;
}
Also used : DirectCloud(org.platformlayer.service.cloud.direct.model.DirectCloud) DirectHost(org.platformlayer.service.cloud.direct.model.DirectHost) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 2 with DirectCloud

use of org.platformlayer.service.cloud.direct.model.DirectCloud in project platformlayer by platformlayer.

the class DownloadImage method handler.

@Handler
public void handler(OpsTarget target) throws OpsException {
    if (target.getFilesystemInfoFile(imageFile) == null) {
        DirectCloud cloud = OpsContext.get().getInstance(DirectCloud.class);
        if (cloud == null) {
            throw new IllegalStateException("Cloud instance not found");
        }
        ImageStore imageStore = cloudHelpers.getImageStore(cloud);
        MachineProvider machineProvider = providers.toInterface(cloud, MachineProvider.class);
        CloudImage imageInfo = imageFactory.getOrCreateImageId(machineProvider, imageFormats, recipeKey);
        if (imageStore == null) {
            throw new OpsException("Image store not configured");
        }
        String fileName = imageInfo.getId() + ".image." + imageInfo.getFormat().name();
        // TODO: We don't need rawImage; delete or just request a read-only version
        File rawImage = new File(IMAGES_DIR, fileName);
        target.mkdir(IMAGES_DIR);
        // TODO: Caching / reuse ... need to check md5 though
        imageStore.bringToMachine(imageInfo.getId(), target, rawImage);
        ImageFormat imageFormat = imageInfo.getFormat();
        switch(imageFormat) {
            case Tar:
                {
                    target.mkdir(imageFile);
                    target.executeCommand(Command.build("cd {0}; tar jxf {1}", imageFile, rawImage).setTimeout(TimeSpan.FIVE_MINUTES));
                    break;
                }
            case DiskRaw:
                {
                    Command expand = Command.build("gunzip -c {0} | cp --sparse=always /proc/self/fd/0 {1}", rawImage, imageFile);
                    target.executeCommand(expand.setTimeout(TimeSpan.FIVE_MINUTES));
                    break;
                }
            case DiskQcow2:
                {
                    Command expand = Command.build("cp {0} {1}", rawImage, imageFile);
                    target.executeCommand(expand.setTimeout(TimeSpan.FIVE_MINUTES));
                    break;
                }
            default:
                throw new OpsException("Unknown image format: " + imageFormat);
        }
    }
}
Also used : DirectCloud(org.platformlayer.service.cloud.direct.model.DirectCloud) MachineProvider(org.platformlayer.ops.machines.MachineProvider) OpsException(org.platformlayer.ops.OpsException) Command(org.platformlayer.ops.Command) CloudImage(org.platformlayer.ops.images.CloudImage) File(java.io.File) ImageStore(org.platformlayer.ops.images.ImageStore) ImageFormat(org.platformlayer.ops.images.ImageFormat) Handler(org.platformlayer.ops.Handler)

Aggregations

DirectCloud (org.platformlayer.service.cloud.direct.model.DirectCloud)2 File (java.io.File)1 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)1 Command (org.platformlayer.ops.Command)1 Handler (org.platformlayer.ops.Handler)1 OpsException (org.platformlayer.ops.OpsException)1 CloudImage (org.platformlayer.ops.images.CloudImage)1 ImageFormat (org.platformlayer.ops.images.ImageFormat)1 ImageStore (org.platformlayer.ops.images.ImageStore)1 MachineProvider (org.platformlayer.ops.machines.MachineProvider)1 DirectHost (org.platformlayer.service.cloud.direct.model.DirectHost)1