Search in sources :

Example 6 with StoragePlugin

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.

the class Ovm3StorageProcessor method backupSnapshot.

/**
     * use the cache, or the normal nfs, also delete the leftovers for us
     * also contains object store storage in xenserver.
     */
@Override
public CopyCmdAnswer backupSnapshot(CopyCommand cmd) {
    LOGGER.debug("execute backupSnapshot: " + cmd.getClass());
    try {
        DataTO srcData = cmd.getSrcTO();
        DataTO destData = cmd.getDestTO();
        SnapshotObjectTO src = (SnapshotObjectTO) srcData;
        SnapshotObjectTO dest = (SnapshotObjectTO) destData;
        // src.getPath contains the uuid of the snapshot.
        String srcFile = getVirtualDiskPath(src.getPath(), src.getDataStore().getUuid());
        // destination
        String storeUrl = dest.getDataStore().getUrl();
        String secPoolUuid = pool.setupSecondaryStorage(storeUrl);
        String destDir = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + dest.getPath();
        String destFile = destDir + "/" + src.getPath();
        destFile = destFile.concat(".raw");
        // copy
        Linux host = new Linux(c);
        CloudstackPlugin csp = new CloudstackPlugin(c);
        csp.ovsMkdirs(destDir);
        LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
        host.copyFile(srcFile, destFile);
        StoragePlugin sp = new StoragePlugin(c);
        sp.storagePluginDestroy(secPoolUuid, srcFile);
        SnapshotObjectTO newSnap = new SnapshotObjectTO();
        // newSnap.setPath(destFile);
        // damnit frickin crap, no reference whatsoever... could use parent ?
        newSnap.setPath(dest.getPath() + "/" + src.getPath() + ".raw");
        newSnap.setParentSnapshotPath(null);
        return new CopyCmdAnswer(newSnap);
    } catch (Ovm3ResourceException e) {
        String msg = "Error backupSnapshot: " + e.getMessage();
        LOGGER.info(msg);
        return new CopyCmdAnswer(msg);
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) DataTO(com.cloud.agent.api.to.DataTO) Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 7 with StoragePlugin

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.

the class Ovm3StorageProcessor method deleteVolume.

@Override
public Answer deleteVolume(DeleteCommand cmd) {
    LOGGER.debug("execute deleteVolume: " + cmd.getClass());
    DataTO data = cmd.getData();
    VolumeObjectTO volume = (VolumeObjectTO) data;
    try {
        String poolUuid = data.getDataStore().getUuid();
        String uuid = volume.getUuid();
        String path = getVirtualDiskPath(uuid, poolUuid);
        StoragePlugin sp = new StoragePlugin(c);
        sp.storagePluginDestroy(poolUuid, path);
        LOGGER.debug("Volume deletion success: " + path);
    } catch (Ovm3ResourceException e) {
        LOGGER.info("Volume deletion failed: " + e.toString(), e);
        return new CreateObjectAnswer(e.toString());
    }
    return new Answer(cmd);
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) DataTO(com.cloud.agent.api.to.DataTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Example 8 with StoragePlugin

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.

the class Ovm3StorageProcessor method execute.

public CreateAnswer execute(CreateCommand cmd) {
    LOGGER.debug("execute: " + cmd.getClass());
    StorageFilerTO primaryStorage = cmd.getPool();
    DiskProfile disk = cmd.getDiskCharacteristics();
    /* disk should have a uuid */
    // should also be replaced with getVirtualDiskPath ?
    String fileName = UUID.randomUUID().toString() + ".raw";
    String dst = primaryStorage.getPath() + "/" + primaryStorage.getUuid() + "/" + fileName;
    try {
        StoragePlugin store = new StoragePlugin(c);
        if (cmd.getTemplateUrl() != null) {
            LOGGER.debug("CreateCommand " + cmd.getTemplateUrl() + " " + dst);
            Linux host = new Linux(c);
            host.copyFile(cmd.getTemplateUrl(), dst);
        } else {
            /* this is a dup with the createVolume ? */
            LOGGER.debug("CreateCommand " + dst);
            store.storagePluginCreate(primaryStorage.getUuid(), primaryStorage.getHost(), dst, disk.getSize(), false);
        }
        FileProperties fp = store.storagePluginGetFileInfo(primaryStorage.getUuid(), primaryStorage.getHost(), dst);
        VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(), primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(), fileName, fp.getName(), fp.getSize(), null);
        return new CreateAnswer(cmd, volume);
    } catch (Exception e) {
        LOGGER.debug("CreateCommand failed", e);
        return new CreateAnswer(cmd, e.getMessage());
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) VolumeTO(com.cloud.agent.api.to.VolumeTO) Linux(com.cloud.hypervisor.ovm3.objects.Linux) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) URISyntaxException(java.net.URISyntaxException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 9 with StoragePlugin

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.

the class Ovm3StoragePool method setupNfsStorage.

/**
     * Sets up NFS Storage
     *
     * @param uri
     * @param uuid
     * @return
     * @throws Ovm3ResourceException
     */
private String setupNfsStorage(URI uri, String uuid) throws Ovm3ResourceException {
    String fsUri = "nfs";
    String msg = "";
    String mountPoint = config.getAgentSecStoragePath() + "/" + uuid;
    Linux host = new Linux(c);
    Map<String, Linux.FileSystem> fsList = host.getFileSystemMap(fsUri);
    Linux.FileSystem fs = fsList.get(uuid);
    if (fs == null || !fs.getRemoteDir().equals(mountPoint)) {
        try {
            StoragePlugin sp = new StoragePlugin(c);
            sp.storagePluginMountNFS(uri.getHost(), uri.getPath(), uuid, mountPoint);
            msg = "Nfs storage " + uri + " mounted on " + mountPoint;
            return uuid;
        } catch (Ovm3ResourceException ec) {
            msg = "Nfs storage " + uri + " mount on " + mountPoint + " FAILED " + ec.getMessage();
            LOGGER.error(msg);
            throw ec;
        }
    } else {
        msg = "NFS storage " + uri + " already mounted on " + mountPoint;
        return uuid;
    }
}
Also used : Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Example 10 with StoragePlugin

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.

the class Ovm3StorageProcessor method execute.

/* Destroy a volume (image) */
public Answer execute(DestroyCommand cmd) {
    LOGGER.debug("execute: " + cmd.getClass());
    VolumeTO vol = cmd.getVolume();
    String vmName = cmd.getVmName();
    try {
        StoragePlugin store = new StoragePlugin(c);
        store.storagePluginDestroy(vol.getPoolUuid(), vol.getPath());
        return new Answer(cmd, true, "Success");
    } catch (Ovm3ResourceException e) {
        LOGGER.debug("Destroy volume " + vol.getName() + " failed for " + vmName + " ", e);
        return new Answer(cmd, false, e.getMessage());
    }
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Aggregations

Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)10 StoragePlugin (com.cloud.hypervisor.ovm3.objects.StoragePlugin)10 Answer (com.cloud.agent.api.Answer)4 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)4 DataTO (com.cloud.agent.api.to.DataTO)4 Linux (com.cloud.hypervisor.ovm3.objects.Linux)4 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)4 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)4 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)3 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)3 FileProperties (com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties)3 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)3 ResignatureAnswer (org.apache.cloudstack.storage.command.ResignatureAnswer)3 SnapshotAndCopyAnswer (org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer)3 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)2 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)2 VolumeTO (com.cloud.agent.api.to.VolumeTO)2 StorageDetails (com.cloud.hypervisor.ovm3.objects.StoragePlugin.StorageDetails)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 URISyntaxException (java.net.URISyntaxException)2