CLOUDSTACK-4108: fix create template from snapshot for vmware& s3

This commit is contained in:
Edison Su 2013-08-07 19:11:28 -07:00
parent e851f4a930
commit 9bce985f62
2 changed files with 25 additions and 3 deletions

View File

@ -806,9 +806,17 @@ public class VmwareStorageProcessor implements StorageProcessor {
private Ternary<String, Long, Long> createTemplateFromSnapshot(String installPath, String templateUniqueName,
String secStorageUrl, String snapshotPath, Long templateId) throws Exception {
//Snapshot path is decoded in this form: /snapshots/account/volumeId/uuid/uuid
String[] tokens = snapshotPath.split(File.separator);
String backupSSUuid = tokens[tokens.length - 1];
String snapshotFolder = StringUtils.join(tokens, File.separator, 0, tokens.length -1);
String backupSSUuid;
String snapshotFolder;
if (snapshotPath.endsWith(".ova")) {
int index = snapshotPath.lastIndexOf(File.separator);
backupSSUuid = snapshotPath.substring(index + 1).replace(".ova", "");
snapshotFolder = snapshotPath.substring(0, index);
} else {
String[] tokens = snapshotPath.split(File.separator);
backupSSUuid = tokens[tokens.length - 1];
snapshotFolder = StringUtils.join(tokens, File.separator, 0, tokens.length -1);
}
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl);
String installFullPath = secondaryMountPoint + "/" + installPath;

View File

@ -30,6 +30,7 @@ import com.cloud.storage.DataStoreRole;
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
import org.apache.cloudstack.storage.command.CopyCommand;
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import java.io.File;
@ -87,6 +88,19 @@ public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemComman
String name = path.substring(index + 1);
storageManager.createOva(parentPath + File.separator + path, name);
vol.setPath(path + File.separator + name + ".ova");
} else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
//create template from snapshot on src at first, then copy it to s3
TemplateObjectTO cacheTemplate = (TemplateObjectTO)destData;
cacheTemplate.setDataStore(srcDataStore);
CopyCmdAnswer answer = (CopyCmdAnswer)processor.createTemplateFromSnapshot(cmd);
if (!answer.getResult()) {
return answer;
}
cacheTemplate.setDataStore(destDataStore);
TemplateObjectTO template = (TemplateObjectTO)answer.getNewData();
template.setDataStore(srcDataStore);
CopyCommand newCmd = new CopyCommand(template, destData, cmd.getWait(), cmd.executeInSequence());
return storageResource.defaultAction(newCmd);
}
needDelegation = true;
}