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();
}
}
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");
}
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);
}
}
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);
}
}
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);
}
Aggregations