use of com.cloud.agent.api.to.DataStoreTO in project cloudstack by apache.
the class VmwareStorageManagerImpl method createOvaForTemplate.
@Override
public String createOvaForTemplate(TemplateObjectTO template) {
DataStoreTO storeTO = template.getDataStore();
if (!(storeTO instanceof NfsTO)) {
s_logger.debug("Can only handle NFS storage, while creating OVA from template");
return null;
}
NfsTO nfsStore = (NfsTO) storeTO;
String secStorageUrl = nfsStore.getUrl();
assert (secStorageUrl != null);
String installPath = template.getPath();
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, _nfsVersion);
String installFullPath = secondaryMountPoint + "/" + installPath;
try {
if (installFullPath.endsWith(".ova")) {
if (new File(installFullPath).exists()) {
s_logger.debug("OVA file found at: " + installFullPath);
} else {
if (new File(installFullPath + ".meta").exists()) {
createOVAFromMetafile(installFullPath + ".meta");
} else {
String msg = "Unable to find OVA or OVA MetaFile to prepare template.";
s_logger.error(msg);
throw new Exception(msg);
}
}
return installPath;
}
} catch (Throwable e) {
s_logger.debug("Failed to create OVA: " + e.toString());
}
return null;
}
use of com.cloud.agent.api.to.DataStoreTO 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 com.cloud.agent.api.to.DataStoreTO in project cloudstack by apache.
the class Ovm3StorageProcessor method execute.
public final Answer execute(final CopyCommand cmd) {
LOGGER.debug("execute: " + cmd.getClass());
DataTO srcData = cmd.getSrcTO();
DataStoreTO srcStore = srcData.getDataStore();
DataTO destData = cmd.getDestTO();
DataStoreTO destStore = destData.getDataStore();
String msg = "Not implemented yet";
try {
/* target and source are NFS and TEMPLATE */
if ((srcStore instanceof NfsTO) && (srcData.getObjectType() == DataObjectType.TEMPLATE) && (destData.getObjectType() == DataObjectType.TEMPLATE)) {
return copyTemplateToPrimaryStorage(cmd);
/* we assume the cache for templates is local */
} else if ((srcData.getObjectType() == DataObjectType.TEMPLATE) && (destData.getObjectType() == DataObjectType.VOLUME)) {
if (srcStore.getUrl().equals(destStore.getUrl())) {
return cloneVolumeFromBaseTemplate(cmd);
} else {
msg = "Primary to Primary doesn't match";
LOGGER.debug(msg);
}
} else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.SNAPSHOT)) {
return backupSnapshot(cmd);
} else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.TEMPLATE)) {
return createTemplateFromSnapshot(cmd);
} else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.VOLUME)) {
return createVolumeFromSnapshot(cmd);
} else {
msg = "Unable to do stuff for " + srcStore.getClass() + ":" + srcData.getObjectType() + " to " + destStore.getClass() + ":" + destData.getObjectType();
LOGGER.debug(msg);
}
} catch (Exception e) {
msg = "Catch Exception " + e.getClass().getName() + " for template due to " + e.toString();
LOGGER.warn(msg, e);
return new CopyCmdAnswer(msg);
}
LOGGER.warn(msg + " " + cmd.getClass());
return new CopyCmdAnswer(msg);
}
use of com.cloud.agent.api.to.DataStoreTO in project cloudstack by apache.
the class Ovm3StorageProcessor method copyTemplateToPrimaryStorage.
/**
* src is Nfs and Template from secondary storage to primary
*/
@Override
public CopyCmdAnswer copyTemplateToPrimaryStorage(CopyCommand cmd) {
LOGGER.debug("execute copyTemplateToPrimaryStorage: " + cmd.getClass());
DataTO srcData = cmd.getSrcTO();
DataStoreTO srcStore = srcData.getDataStore();
DataTO destData = cmd.getDestTO();
NfsTO srcImageStore = (NfsTO) srcStore;
TemplateObjectTO destTemplate = (TemplateObjectTO) destData;
try {
String secPoolUuid = pool.setupSecondaryStorage(srcImageStore.getUrl());
String primaryPoolUuid = destData.getDataStore().getUuid();
String destPath = config.getAgentOvmRepoPath() + "/" + ovmObject.deDash(primaryPoolUuid) + "/" + config.getTemplateDir();
String sourcePath = config.getAgentSecStoragePath() + "/" + secPoolUuid;
Linux host = new Linux(c);
String destUuid = destTemplate.getUuid();
/*
* Would love to add dynamic formats (tolower), to also support
* VHD and QCOW2, although Ovm3.2 does not have tapdisk2 anymore
* so we can forget about that.
*/
/* TODO: add checksumming */
String srcFile = sourcePath + "/" + srcData.getPath();
if (srcData.getPath().endsWith("/")) {
srcFile = sourcePath + "/" + srcData.getPath() + "/" + destUuid + ".raw";
}
String destFile = destPath + "/" + destUuid + ".raw";
LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
host.copyFile(srcFile, destFile);
TemplateObjectTO newVol = new TemplateObjectTO();
newVol.setUuid(destUuid);
// was destfile
newVol.setPath(destUuid);
newVol.setFormat(ImageFormat.RAW);
return new CopyCmdAnswer(newVol);
} catch (Ovm3ResourceException e) {
String msg = "Error while copying template to primary storage: " + e.getMessage();
LOGGER.info(msg);
return new CopyCmdAnswer(msg);
}
}
use of com.cloud.agent.api.to.DataStoreTO in project cloudstack by apache.
the class Ovm3StorageProcessor method createVolumeFromSnapshot.
/**
* SnapshotObjectTO secondary to VolumeObjectTO primary in xenserver,
*/
@Override
public Answer createVolumeFromSnapshot(CopyCommand cmd) {
LOGGER.debug("execute createVolumeFromSnapshot: " + cmd.getClass());
try {
DataTO srcData = cmd.getSrcTO();
DataStoreTO srcStore = srcData.getDataStore();
NfsTO srcImageStore = (NfsTO) srcStore;
// source, should contain snap dir/filename
SnapshotObjectTO srcSnap = (SnapshotObjectTO) srcData;
String secPoolUuid = pool.setupSecondaryStorage(srcImageStore.getUrl());
String srcFile = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + srcSnap.getPath();
// dest
DataTO destData = cmd.getDestTO();
VolumeObjectTO destVol = (VolumeObjectTO) destData;
String primaryPoolUuid = destData.getDataStore().getUuid();
String destFile = getVirtualDiskPath(destVol.getUuid(), ovmObject.deDash(primaryPoolUuid));
Linux host = new Linux(c);
host.copyFile(srcFile, destFile);
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setUuid(destVol.getUuid());
// newVol.setPath(destFile);
newVol.setPath(destVol.getUuid());
newVol.setFormat(ImageFormat.RAW);
return new CopyCmdAnswer(newVol);
/* we assume the cache for templates is local */
} catch (Ovm3ResourceException e) {
LOGGER.debug("Failed to createVolumeFromSnapshot: ", e);
return new CopyCmdAnswer(e.toString());
}
}
Aggregations