secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
installPath = "template/tmpl/" + accountId + "/" + newTemplateId;
if( !createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath)) {
details = " Filed to create folder " + installPath + " in secondary storage";
s_logger.warn(details);
return new CreatePrivateTemplateAnswer(cmd, false, details);
}
String templatePath = secondaryStorageMountPath + "/" + installPath;
// create snapshot SR
String filename = backedUpSnapshotUuid;
if ( !filename.startsWith("VHD-") && !filename.endsWith(".vhd")) {
filename = backedUpSnapshotUuid + ".vhd";
}
String snapshotPath = secondaryStorageMountPath + "/snapshots/" + accountId + "/" + volumeId + "/" + filename;
String results = createTemplateFromSnapshot(conn, templatePath, snapshotPath, wait);
String[] tmp = results.split("#");
String tmpltUuid = tmp[1];
long physicalSize = Long.parseLong(tmp[2]);
long virtualSize = Long.parseLong(tmp[3]) * 1024 * 1024;
String tmpltFilename = tmpltUuid + ".vhd";
// create the template.properties file
result = postCreatePrivateTemplate(conn, templatePath, tmpltFilename, tmpltUuid, userSpecifiedName, null, physicalSize, virtualSize, newTemplateId);
if (!result) {
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + templatePath);
}
installPath = installPath + "/" + tmpltFilename;
return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, physicalSize, tmpltUuid, ImageFormat.VHD);
} catch (Exception e) {
if (secondaryStorageMountPath != null) {
deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath);
}
details = "Creating template from snapshot " + backedUpSnapshotUuid + " failed due to " + e.toString();
s_logger.error(details, e);
}
return new CreatePrivateTemplateAnswer(cmd, result, details);
}