Search in sources :

Example 1 with DataStoreTO

use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResource method getVolumePath.

public String getVolumePath(final Connect conn, final DiskTO volume) throws LibvirtException, URISyntaxException {
    final DataTO data = volume.getData();
    final DataStoreTO store = data.getDataStore();
    if (volume.getType() == VolumeType.ISO && data.getPath() != null) {
        final NfsTO nfsStore = (NfsTO) store;
        final String isoPath = nfsStore.getUrl() + File.separator + data.getPath();
        final int index = isoPath.lastIndexOf("/");
        final String path = isoPath.substring(0, index);
        final String name = isoPath.substring(index + 1);
        final KvmStoragePool secondaryPool = this.storagePoolMgr.getStoragePoolByUri(path);
        final KvmPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
        return isoVol.getPath();
    } else {
        return data.getPath();
    }
}
Also used : PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) NfsTO(com.cloud.legacymodel.to.NfsTO)

Example 2 with DataStoreTO

use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method createTemplateFromSnapshot.

protected Answer createTemplateFromSnapshot(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final DataStoreTO srcDataStore = srcData.getDataStore();
    final DataStoreTO destDataStore = destData.getDataStore();
    if (srcDataStore.getRole() == DataStoreRole.Image || srcDataStore.getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Primary) {
        if (!(srcDataStore instanceof NfsTO)) {
            s_logger.debug("only support nfs storage as src, when create template from snapshot");
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
        if (destDataStore instanceof NfsTO) {
            return copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore, (TemplateObjectTO) destData, (NfsTO) destDataStore);
        }
    }
    s_logger.debug("Failed to create templat from snapshot");
    return new CopyCmdAnswer("Unsupported prototcol");
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) NfsTO(com.cloud.legacymodel.to.NfsTO) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Example 3 with DataStoreTO

use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method deleteSnapshot.

protected Answer deleteSnapshot(final DeleteCommand cmd) {
    final DataTO obj = cmd.getData();
    final DataStoreTO dstore = obj.getDataStore();
    if (dstore instanceof NfsTO) {
        final NfsTO nfs = (NfsTO) dstore;
        String parent = getRootDir(nfs.getUrl());
        if (!parent.endsWith(File.separator)) {
            parent += File.separator;
        }
        String snapshotPath = obj.getPath();
        if (snapshotPath.startsWith(File.separator)) {
            snapshotPath = snapshotPath.substring(1);
        }
        // check if the passed snapshot path is a directory or not. For ImageCache, path is stored as a directory instead of
        // snapshot file name. If so, since backupSnapshot process has already deleted snapshot in cache, so we just do nothing
        // and return true.
        final String fullSnapPath = parent + snapshotPath;
        final File snapDir = new File(fullSnapPath);
        if (snapDir.exists() && snapDir.isDirectory()) {
            s_logger.debug("snapshot path " + snapshotPath + " is a directory, already deleted during backup snapshot, so no need to delete");
            return new Answer(cmd, true, null);
        }
        // passed snapshot path is a snapshot file path, then get snapshot directory first
        final int index = snapshotPath.lastIndexOf("/");
        final String snapshotName = snapshotPath.substring(index + 1);
        snapshotPath = snapshotPath.substring(0, index);
        final String absoluteSnapshotPath = parent + snapshotPath;
        // check if snapshot directory exists
        final File snapshotDir = new File(absoluteSnapshotPath);
        String details = null;
        if (!snapshotDir.exists()) {
            details = "snapshot directory " + snapshotDir.getName() + " doesn't exist";
            s_logger.debug(details);
            return new Answer(cmd, true, details);
        }
        // delete snapshot in the directory if exists
        final String lPath = absoluteSnapshotPath + "/*" + snapshotName + "*";
        final String result = deleteLocalFile(lPath);
        if (result != null) {
            details = "failed to delete snapshot " + lPath + " , err=" + result;
            s_logger.warn(details);
            return new Answer(cmd, false, details);
        }
        return new Answer(cmd, true, null);
    } else {
        return new Answer(cmd, false, "Unsupported image data store: " + dstore);
    }
}
Also used : ListTemplateAnswer(com.cloud.legacymodel.communication.answer.ListTemplateAnswer) GetStorageStatsAnswer(com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) CheckHealthAnswer(com.cloud.legacymodel.communication.answer.CheckHealthAnswer) UploadStatusAnswer(com.cloud.legacymodel.communication.answer.UploadStatusAnswer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) NfsTO(com.cloud.legacymodel.to.NfsTO) File(java.io.File)

Example 4 with DataStoreTO

use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method execute.

private Answer execute(final ListVolumeCommand cmd) {
    if (!this._inSystemVM) {
        return new ListVolumeAnswer(cmd.getSecUrl(), null);
    }
    final DataStoreTO store = cmd.getDataStore();
    if (store instanceof NfsTO) {
        final String root = getRootDir(cmd.getSecUrl());
        final Map<Long, TemplateProp> templateInfos = this._dlMgr.gatherVolumeInfo(root);
        return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
    } else {
        return new Answer(cmd, false, "Unsupported image data store: " + store);
    }
}
Also used : TemplateProp(com.cloud.legacymodel.storage.TemplateProp) ListTemplateAnswer(com.cloud.legacymodel.communication.answer.ListTemplateAnswer) GetStorageStatsAnswer(com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) CheckHealthAnswer(com.cloud.legacymodel.communication.answer.CheckHealthAnswer) UploadStatusAnswer(com.cloud.legacymodel.communication.answer.UploadStatusAnswer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) NfsTO(com.cloud.legacymodel.to.NfsTO)

Example 5 with DataStoreTO

use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method execute.

protected Answer execute(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final DataStoreTO srcDataStore = srcData.getDataStore();
    final DataStoreTO destDataStore = destData.getDataStore();
    if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
        return createTemplateFromSnapshot(cmd);
    }
    return Answer.createUnsupportedCommandAnswer(cmd);
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO)

Aggregations

DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)49 NfsTO (com.cloud.legacymodel.to.NfsTO)36 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)30 DataTO (com.cloud.legacymodel.to.DataTO)30 PrimaryDataStoreTO (com.cloud.legacymodel.to.PrimaryDataStoreTO)25 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)24 Answer (com.cloud.legacymodel.communication.answer.Answer)19 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)17 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)15 XenAPIException (com.xensource.xenapi.Types.XenAPIException)15 XmlRpcException (org.apache.xmlrpc.XmlRpcException)15 Connection (com.xensource.xenapi.Connection)14 SR (com.xensource.xenapi.SR)13 VDI (com.xensource.xenapi.VDI)13 URI (java.net.URI)12 TemplateObjectTO (com.cloud.legacymodel.to.TemplateObjectTO)11 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)9 GetStorageStatsAnswer (com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer)9 CheckHealthAnswer (com.cloud.legacymodel.communication.answer.CheckHealthAnswer)8 ListTemplateAnswer (com.cloud.legacymodel.communication.answer.ListTemplateAnswer)8