use of org.apache.cloudstack.storage.to.PrimaryDataStoreTO in project cloudstack by apache.
the class AncientDataMotionStrategy method addFullCloneFlagOnVMwareDest.
/**
* Adds {@code 'vmware.create.full.clone'} value for a given primary storage, whose HV is VMware, on datastore's {@code fullCloneFlag} field
* @param dataTO Dest data store TO
* @return dataTO including fullCloneFlag, if provided
*/
protected DataTO addFullCloneFlagOnVMwareDest(DataTO dataTO) {
if (dataTO != null && dataTO.getHypervisorType().equals(Hypervisor.HypervisorType.VMware)) {
DataStoreTO dataStoreTO = dataTO.getDataStore();
if (dataStoreTO != null && dataStoreTO instanceof PrimaryDataStoreTO) {
PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStoreTO;
Boolean value = CapacityManager.VmwareCreateCloneFull.valueIn(primaryDataStoreTO.getId());
primaryDataStoreTO.setFullCloneFlag(value);
}
}
return dataTO;
}
use of org.apache.cloudstack.storage.to.PrimaryDataStoreTO in project cloudstack by apache.
the class KVMStorageProcessor method handleDownloadTemplateToPrimaryStorage.
@Override
public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd) {
final PrimaryDataStoreTO pool = cmd.getDestPool();
DirectTemplateDownloader downloader;
KVMPhysicalDisk template;
KVMStoragePool destPool = null;
try {
s_logger.debug("Verifying temporary location for downloading the template exists on the host");
String temporaryDownloadPath = resource.getDirectDownloadTemporaryDownloadPath();
if (!isLocationAccessible(temporaryDownloadPath)) {
String msg = "The temporary location path for downloading templates does not exist: " + temporaryDownloadPath + " on this host";
s_logger.error(msg);
return new DirectDownloadAnswer(false, msg, true);
}
Long templateSize = null;
if (StringUtils.isNotBlank(cmd.getUrl())) {
String url = cmd.getUrl();
templateSize = UriUtils.getRemoteSize(url);
}
s_logger.debug("Checking for free space on the host for downloading the template with physical size: " + templateSize + " and virtual size: " + cmd.getTemplateSize());
if (!isEnoughSpaceForDownloadTemplateOnTemporaryLocation(templateSize)) {
String msg = "Not enough space on the defined temporary location to download the template " + cmd.getTemplateId();
s_logger.error(msg);
return new DirectDownloadAnswer(false, msg, true);
}
destPool = storagePoolMgr.getStoragePool(pool.getPoolType(), pool.getUuid());
downloader = getDirectTemplateDownloaderFromCommand(cmd, destPool, temporaryDownloadPath);
s_logger.debug("Trying to download template");
Pair<Boolean, String> result = downloader.downloadTemplate();
if (!result.first()) {
s_logger.warn("Couldn't download template");
return new DirectDownloadAnswer(false, "Unable to download template", true);
}
String tempFilePath = result.second();
if (!downloader.validateChecksum()) {
s_logger.warn("Couldn't validate template checksum");
return new DirectDownloadAnswer(false, "Checksum validation failed", false);
}
final TemplateObjectTO destTemplate = cmd.getDestData();
String destTemplatePath = (destTemplate != null) ? destTemplate.getPath() : null;
if (!storagePoolMgr.connectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath, null)) {
s_logger.warn("Unable to connect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid());
}
template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds());
if (!storagePoolMgr.disconnectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath)) {
s_logger.warn("Unable to disconnect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid());
}
} catch (CloudRuntimeException e) {
s_logger.warn("Error downloading template " + cmd.getTemplateId() + " due to: " + e.getMessage());
return new DirectDownloadAnswer(false, "Unable to download template: " + e.getMessage(), true);
} catch (IllegalArgumentException e) {
return new DirectDownloadAnswer(false, "Unable to create direct downloader: " + e.getMessage(), true);
}
return new DirectDownloadAnswer(true, template.getSize(), template.getName());
}
use of org.apache.cloudstack.storage.to.PrimaryDataStoreTO in project cloudstack by apache.
the class KVMStorageProcessor method deleteSnapshot.
@Override
public Answer deleteSnapshot(final DeleteCommand cmd) {
String snap_full_name = "";
try {
SnapshotObjectTO snapshotTO = (SnapshotObjectTO) cmd.getData();
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) snapshotTO.getDataStore();
VolumeObjectTO volume = snapshotTO.getVolume();
KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
KVMPhysicalDisk disk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), volume.getPath());
String snapshotFullPath = snapshotTO.getPath();
String snapshotName = snapshotFullPath.substring(snapshotFullPath.lastIndexOf("/") + 1);
snap_full_name = disk.getName() + "@" + snapshotName;
if (primaryPool.getType() == StoragePoolType.RBD) {
Rados r = radosConnect(primaryPool);
IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
Rbd rbd = new Rbd(io);
RbdImage image = rbd.open(disk.getName());
try {
s_logger.info("Attempting to remove RBD snapshot " + snap_full_name);
if (image.snapIsProtected(snapshotName)) {
s_logger.debug("Unprotecting RBD snapshot " + snap_full_name);
image.snapUnprotect(snapshotName);
}
image.snapRemove(snapshotName);
s_logger.info("Snapshot " + snap_full_name + " successfully removed from " + primaryPool.getType().toString() + " pool.");
} catch (RbdException e) {
s_logger.error("Failed to remove snapshot " + snap_full_name + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue()));
} finally {
rbd.close(image);
r.ioCtxDestroy(io);
}
} else if (primaryPool.getType() == StoragePoolType.NetworkFilesystem || primaryPool.getType() == StoragePoolType.Filesystem) {
s_logger.info(String.format("Deleting snapshot (id=%s, name=%s, path=%s, storage type=%s) on primary storage", snapshotTO.getId(), snapshotTO.getName(), snapshotTO.getPath(), primaryPool.getType()));
deleteSnapshotViaManageSnapshotScript(snapshotName, disk);
} else {
s_logger.warn("Operation not implemented for storage pool type of " + primaryPool.getType().toString());
throw new InternalErrorException("Operation not implemented for storage pool type of " + primaryPool.getType().toString());
}
return new Answer(cmd, true, "Snapshot " + snap_full_name + " removed successfully.");
} catch (RadosException e) {
s_logger.error("Failed to remove snapshot " + snap_full_name + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue()));
return new Answer(cmd, false, "Failed to remove snapshot " + snap_full_name);
} catch (RbdException e) {
s_logger.error("Failed to remove snapshot " + snap_full_name + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue()));
return new Answer(cmd, false, "Failed to remove snapshot " + snap_full_name);
} catch (Exception e) {
s_logger.error("Failed to remove snapshot " + snap_full_name + ", with exception: " + e.toString());
return new Answer(cmd, false, "Failed to remove snapshot " + snap_full_name);
}
}
use of org.apache.cloudstack.storage.to.PrimaryDataStoreTO in project cloudstack by apache.
the class KVMStorageProcessor method copyVolumeFromImageCacheToPrimary.
@Override
public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) {
final DataTO srcData = cmd.getSrcTO();
final DataTO destData = cmd.getDestTO();
final DataStoreTO srcStore = srcData.getDataStore();
final DataStoreTO destStore = destData.getDataStore();
final VolumeObjectTO srcVol = (VolumeObjectTO) srcData;
final ImageFormat srcFormat = srcVol.getFormat();
final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destStore;
if (!(srcStore instanceof NfsTO)) {
return new CopyCmdAnswer("can only handle nfs storage");
}
final NfsTO nfsStore = (NfsTO) srcStore;
final String srcVolumePath = srcData.getPath();
final String secondaryStorageUrl = nfsStore.getUrl();
KVMStoragePool secondaryStoragePool = null;
KVMStoragePool primaryPool = null;
try {
try {
primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
} catch (final CloudRuntimeException e) {
if (e.getMessage().contains("not found")) {
primaryPool = storagePoolMgr.createStoragePool(primaryStore.getUuid(), primaryStore.getHost(), primaryStore.getPort(), primaryStore.getPath(), null, primaryStore.getPoolType());
} else {
return new CopyCmdAnswer(e.getMessage());
}
}
Map<String, String> details = cmd.getOptions2();
String path = details != null ? details.get(DiskTO.IQN) : null;
storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path, details);
final String volumeName = UUID.randomUUID().toString();
final int index = srcVolumePath.lastIndexOf(File.separator);
final String volumeDir = srcVolumePath.substring(0, index);
String srcVolumeName = srcVolumePath.substring(index + 1);
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + File.separator + volumeDir);
if (!srcVolumeName.endsWith(".qcow2") && srcFormat == ImageFormat.QCOW2) {
srcVolumeName = srcVolumeName + ".qcow2";
}
final KVMPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(srcVolumeName);
volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString()));
final KVMPhysicalDisk newDisk = storagePoolMgr.copyPhysicalDisk(volume, path != null ? path : volumeName, primaryPool, cmd.getWaitInMillSeconds());
storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase()));
newVol.setPath(path != null ? path : volumeName);
return new CopyCmdAnswer(newVol);
} catch (final CloudRuntimeException e) {
s_logger.debug("Failed to copyVolumeFromImageCacheToPrimary: ", e);
return new CopyCmdAnswer(e.toString());
} finally {
if (secondaryStoragePool != null) {
storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
}
}
}
use of org.apache.cloudstack.storage.to.PrimaryDataStoreTO in project cloudstack by apache.
the class KVMStorageProcessor method createVolumeFromSnapshot.
@Override
public Answer createVolumeFromSnapshot(final CopyCommand cmd) {
try {
final DataTO srcData = cmd.getSrcTO();
final SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
final DataTO destData = cmd.getDestTO();
final PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore();
final DataStoreTO imageStore = srcData.getDataStore();
final VolumeObjectTO volume = snapshot.getVolume();
if (!(imageStore instanceof NfsTO || imageStore instanceof PrimaryDataStoreTO)) {
return new CopyCmdAnswer("unsupported protocol");
}
final String snapshotFullPath = snapshot.getPath();
final int index = snapshotFullPath.lastIndexOf("/");
final String snapshotPath = snapshotFullPath.substring(0, index);
final String snapshotName = snapshotFullPath.substring(index + 1);
KVMPhysicalDisk disk = null;
if (imageStore instanceof NfsTO) {
disk = createVolumeFromSnapshotOnNFS(cmd, pool, imageStore, volume, snapshotPath, snapshotName);
} else {
disk = createVolumeFromRBDSnapshot(cmd, destData, pool, imageStore, volume, snapshotName, disk);
}
if (disk == null) {
return new CopyCmdAnswer("Could not create volume from snapshot");
}
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(disk.getName());
newVol.setSize(disk.getVirtualSize());
newVol.setFormat(ImageFormat.valueOf(disk.getFormat().toString().toUpperCase()));
return new CopyCmdAnswer(newVol);
} catch (final CloudRuntimeException e) {
s_logger.debug("Failed to createVolumeFromSnapshot: ", e);
return new CopyCmdAnswer(e.toString());
}
}
Aggregations