CLOUDSTACK-3741: generate template.properties so that KVM processor will

not fail with FileNotFound.
This commit is contained in:
Min Chen 2013-07-24 17:49:10 -07:00
parent 2b1266e276
commit 44cae46014
1 changed files with 19 additions and 4 deletions

View File

@ -423,11 +423,26 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
String destFileFullPath = destFile.getAbsolutePath() + File.separator + templateName + "." + ImageFormat.QCOW2.getFileExtension();
s_logger.debug("copy snapshot " + srcFile.getAbsolutePath() + " to template " + destFileFullPath);
Script.runSimpleBashScript("cp " + srcFile.getAbsolutePath() + " " + destFileFullPath);
// template post processing
QCOW2Processor processor = new QCOW2Processor();
Map<String, Object> params = new HashMap<String, Object>();
params.put(StorageLayer.InstanceConfigKey, _storage);
try {
// generate template.properties file
String metaFileName = destFile.getAbsolutePath() + File.separator + "template.properties";
_storage.create(destFile.getAbsolutePath(), "template.properties");
File metaFile = new File(metaFileName);
FileWriter writer = new FileWriter(metaFile);
BufferedWriter bufferWriter = new BufferedWriter(writer);
bufferWriter.write("uniquename=" + destData.getName());
bufferWriter.write("\n");
bufferWriter.write("filename=" + templateName + "." + ImageFormat.QCOW2.getFileExtension());
bufferWriter.write("\n");
long size = this._storage.getSize(destFileFullPath);
bufferWriter.write("size=" + size);
bufferWriter.close();
writer.close();
// template post processing
QCOW2Processor processor = new QCOW2Processor();
Map<String, Object> params = new HashMap<String, Object>();
params.put(StorageLayer.InstanceConfigKey, _storage);
processor.configure("qcow2 processor", params);
String destPath = destFile.getAbsolutePath();
FormatInfo info = processor.process(destPath, null, templateName);