CLOUDSTACK-4468:template created from snapshot is destroyed once we

restart management server.
This commit is contained in:
Min Chen 2013-08-26 11:53:40 -07:00
parent 474b966bc1
commit 49dd7289c0
5 changed files with 12 additions and 3 deletions

View File

@ -207,6 +207,10 @@ public class TemplateObject implements TemplateInfo {
if (newTemplate.getFormat() != null) {
templateVO.setFormat(newTemplate.getFormat());
}
if (newTemplate.getName() != null ){
// For template created from snapshot, template name is determine by resource code.
templateVO.setUniqueName(newTemplate.getName());
}
templateVO.setSize(newTemplate.getSize());
this.imageDao.update(templateVO.getId(), templateVO);
}

View File

@ -536,6 +536,7 @@ public class KVMStorageProcessor implements StorageProcessor {
newTemplate.setSize(info.virtualSize);
newTemplate.setPhysicalSize(info.size);
newTemplate.setFormat(ImageFormat.QCOW2);
newTemplate.setName(templateName);
return new CopyCmdAnswer(newTemplate);
} catch (Exception e) {
s_logger.debug("Failed to create template from volume: " + e.toString());

View File

@ -972,6 +972,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
newTemplate.setPhysicalSize(result.second());
newTemplate.setSize(result.third());
newTemplate.setFormat(ImageFormat.OVA);
newTemplate.setName(uniqeName);
return new CopyCmdAnswer(newTemplate);
} catch (Throwable e) {
if (e instanceof RemoteException) {

View File

@ -1388,6 +1388,7 @@ public class XenServerStorageProcessor implements StorageProcessor {
newTemplate.setFormat(ImageFormat.VHD);
newTemplate.setSize(virtualSize);
newTemplate.setPhysicalSize(physicalSize);
newTemplate.setName(tmpltUUID);
CopyCmdAnswer answer = new CopyCmdAnswer(newTemplate);
return answer;
} catch (Exception e) {

View File

@ -375,7 +375,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
FormatInfo info = processor.process(destPath, null, templateUuid);
TemplateLocation loc = new TemplateLocation(_storage, destPath);
loc.create(1, true, templateName);
loc.create(1, true, templateUuid);
loc.addFormat(info);
loc.save();
TemplateProp prop = loc.getTemplateInfo();
@ -384,6 +384,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
newTemplate.setFormat(ImageFormat.VHD);
newTemplate.setSize(prop.getSize());
newTemplate.setPhysicalSize(prop.getPhysicalSize());
newTemplate.setName(templateUuid);
return new CopyCmdAnswer(newTemplate);
} catch (ConfigurationException e) {
s_logger.debug("Failed to create template from snapshot: " + e.toString());
@ -424,6 +425,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
File metaFile = new File(metaFileName);
FileWriter writer = new FileWriter(metaFile);
BufferedWriter bufferWriter = new BufferedWriter(writer);
// KVM didn't change template unique name, just used the template name passed from orchestration layer, so no need
// to send template name back.
bufferWriter.write("uniquename=" + destData.getName());
bufferWriter.write("\n");
bufferWriter.write("filename=" + fileName);
@ -454,7 +457,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
FormatInfo info = processor.process(destPath, null, templateName);
TemplateLocation loc = new TemplateLocation(_storage, destPath);
loc.create(1, true, srcFile.getName());
loc.create(1, true, destData.getName());
loc.addFormat(info);
loc.save();
@ -464,7 +467,6 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
newTemplate.setFormat(srcFormat);
newTemplate.setSize(prop.getSize());
newTemplate.setPhysicalSize(prop.getPhysicalSize());
return new CopyCmdAnswer(newTemplate);
} catch (ConfigurationException e) {
s_logger.debug("Failed to create template:" + e.toString());