use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class VmwareStorageManagerImpl method setVolumeToPathAndSize.
private void setVolumeToPathAndSize(List<VolumeObjectTO> volumeTOs, Map<String, String> mapNewDisk, VmwareContext context, VmwareHypervisorHost hyperHost, String vmName) throws Exception {
for (VolumeObjectTO volumeTO : volumeTOs) {
String oldPath = volumeTO.getPath();
final String baseName;
// if this is managed storage
if (oldPath.startsWith("[-iqn.")) {
// ex. [-iqn.2010-01.com.company:3y8w.vol-10.64-0] -iqn.2010-01.com.company:3y8w.vol-10.64-0-000001.vmdk
// ex. [-iqn.2010-01.com.company:3y8w.vol-10.64-0]
oldPath = oldPath.split(" ")[0];
// remove '[' and ']'
baseName = oldPath.substring(1, oldPath.length() - 1);
} else {
baseName = VmwareHelper.trimSnapshotDeltaPostfix(volumeTO.getPath());
}
String newPath = mapNewDisk.get(baseName);
// get volume's chain size for this VM snapshot; exclude current volume vdisk
DataStoreTO store = volumeTO.getDataStore();
ManagedObjectReference morDs = getDatastoreAsManagedObjectReference(baseName, hyperHost, store);
long size = getVMSnapshotChainSize(context, hyperHost, baseName + "*.vmdk", morDs, newPath);
if (volumeTO.getVolumeType() == Volume.Type.ROOT) {
// add memory snapshot size
size += getVMSnapshotChainSize(context, hyperHost, vmName + "*.vmsn", morDs, null);
}
volumeTO.setSize(size);
volumeTO.setPath(newPath);
}
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class VmwareStorageManagerImpl method execute.
@Override
public boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCommand cmd) {
DataTO data = cmd.getData();
if (data == null) {
return false;
}
String newPath = null;
if (data.getObjectType() == DataObjectType.VOLUME) {
newPath = createOvaForVolume((VolumeObjectTO) data);
} else if (data.getObjectType() == DataObjectType.TEMPLATE) {
newPath = createOvaForTemplate((TemplateObjectTO) data);
}
if (newPath != null) {
cmd.setInstallPath(newPath);
}
return true;
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class XenServerStorageMotionStrategy method updateVolumePathsAfterMigration.
private void updateVolumePathsAfterMigration(Map<VolumeInfo, DataStore> volumeToPool, List<VolumeObjectTO> volumeTos, Host srcHost) {
for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
VolumeInfo volumeInfo = entry.getKey();
StoragePool storagePool = (StoragePool) entry.getValue();
boolean updated = false;
for (VolumeObjectTO volumeTo : volumeTos) {
if (volumeInfo.getId() == volumeTo.getId()) {
if (storagePool.isManaged()) {
handleManagedVolumePostMigration(volumeInfo, srcHost, volumeTo);
} else {
VolumeVO volumeVO = volDao.findById(volumeInfo.getId());
Long oldPoolId = volumeVO.getPoolId();
volumeVO.setPath(volumeTo.getPath());
volumeVO.setFolder(storagePool.getPath());
volumeVO.setPodId(storagePool.getPodId());
volumeVO.setPoolId(storagePool.getId());
volumeVO.setLastPoolId(oldPoolId);
volDao.update(volumeInfo.getId(), volumeVO);
}
updated = true;
break;
}
}
if (!updated) {
s_logger.error("The volume path wasn't updated for volume '" + volumeInfo + "' after it was migrated.");
}
}
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class Ovm3StorageProcessor method cloneVolumeFromBaseTemplate.
/**
* dest is VolumeObject, src is a template
*/
@Override
public CopyCmdAnswer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
LOGGER.debug("execute cloneVolumeFromBaseTemplate: " + cmd.getClass());
try {
// src
DataTO srcData = cmd.getSrcTO();
TemplateObjectTO src = (TemplateObjectTO) srcData;
String srcFile = getVirtualDiskPath(src.getUuid(), src.getDataStore().getUuid());
srcFile = srcFile.replace(config.getVirtualDiskDir(), config.getTemplateDir());
DataTO destData = cmd.getDestTO();
VolumeObjectTO dest = (VolumeObjectTO) destData;
String destFile = getVirtualDiskPath(dest.getUuid(), dest.getDataStore().getUuid());
Linux host = new Linux(c);
LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
host.copyFile(srcFile, destFile);
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setUuid(dest.getUuid());
// was destfile
newVol.setPath(dest.getUuid());
newVol.setFormat(ImageFormat.RAW);
return new CopyCmdAnswer(newVol);
} catch (Ovm3ResourceException e) {
String msg = "Error cloneVolumeFromBaseTemplate: " + e.getMessage();
LOGGER.info(msg);
return new CopyCmdAnswer(msg);
}
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class Ovm3StorageProcessor method createVolume.
/**
* Creates a volume, just a normal empty volume.
*/
@Override
public Answer createVolume(CreateObjectCommand cmd) {
LOGGER.debug("execute createVolume: " + cmd.getClass());
DataTO data = cmd.getData();
VolumeObjectTO volume = (VolumeObjectTO) data;
try {
/*
* public Boolean storagePluginCreate(String uuid, String ssuuid,
* String host, String file, Integer size)
*/
String poolUuid = data.getDataStore().getUuid();
String storeUrl = data.getDataStore().getUrl();
URI uri = new URI(storeUrl);
String host = uri.getHost();
String file = getVirtualDiskPath(volume.getUuid(), poolUuid);
Long size = volume.getSize();
StoragePlugin sp = new StoragePlugin(c);
FileProperties fp = sp.storagePluginCreate(poolUuid, host, file, size, false);
if (!fp.getName().equals(file)) {
return new CreateObjectAnswer("Filename mismatch: " + fp.getName() + " != " + file);
}
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setName(volume.getName());
newVol.setSize(fp.getSize());
newVol.setPath(volume.getUuid());
return new CreateObjectAnswer(newVol);
} catch (Ovm3ResourceException | URISyntaxException e) {
LOGGER.info("Volume creation failed: " + e.toString(), e);
return new CreateObjectAnswer(e.toString());
}
}
Aggregations