mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-5795: Template.properties file wasn't created when a template
was created from a volume. Added a post creation change to create the file with the necessary information.
This commit is contained in:
parent
2efe61ddbc
commit
2ace4fe241
|
|
@ -347,6 +347,7 @@ namespace HypervResource
|
|||
public string path;
|
||||
public string checksum;
|
||||
public string size;
|
||||
public string id;
|
||||
|
||||
public static TemplateObjectTO ParseJson(dynamic json)
|
||||
{
|
||||
|
|
@ -362,7 +363,8 @@ namespace HypervResource
|
|||
uuid = (string)templateObjectTOJson.uuid,
|
||||
path = (string)templateObjectTOJson.path,
|
||||
checksum = (string)templateObjectTOJson.checksum,
|
||||
size = (string)templateObjectTOJson.size
|
||||
size = (string)templateObjectTOJson.size,
|
||||
id = (string)templateObjectTOJson.id
|
||||
};
|
||||
result.s3DataStoreTO = S3TO.ParseJson(templateObjectTOJson.imageDataStore);
|
||||
result.nfsDataStoreTO = NFSTO.ParseJson(templateObjectTOJson.imageDataStore);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Principal;
|
||||
using System.Web.Http;
|
||||
|
|
@ -1549,6 +1550,12 @@ namespace HypervResource
|
|||
// doesn't do anything if the directory is already present.
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(destFile));
|
||||
File.Copy(srcFile, destFile);
|
||||
|
||||
FileInfo destFileInfo = new FileInfo(destFile);
|
||||
// Write the template.properties file
|
||||
PostCreateTemplate(Path.GetDirectoryName(destFile), destTemplateObjectTO.id, destTemplateObjectTO.name,
|
||||
destFileInfo.Length.ToString(), srcVolumeObjectTO.size.ToString(), destTemplateObjectTO.format);
|
||||
|
||||
TemplateObjectTO destTemplateObject = new TemplateObjectTO();
|
||||
destTemplateObject.size = srcVolumeObjectTO.size.ToString();
|
||||
destTemplateObject.format = srcVolumeObjectTO.format;
|
||||
|
|
@ -1585,6 +1592,25 @@ namespace HypervResource
|
|||
}
|
||||
}
|
||||
|
||||
private static void PostCreateTemplate(string path, string templateId, string templateUuid, string physicalSize, string virtualSize, string format)
|
||||
{
|
||||
string templatePropFile = Path.Combine(path, "template.properties");
|
||||
using (StreamWriter sw = new StreamWriter(File.Open(templatePropFile, FileMode.Create), Encoding.GetEncoding("iso-8859-1")))
|
||||
{
|
||||
sw.NewLine = "\n";
|
||||
sw.WriteLine("id=" + templateId);
|
||||
sw.WriteLine("filename=" + templateUuid + "." + format);
|
||||
sw.WriteLine(format + ".filename=" + templateUuid + "." + format);
|
||||
sw.WriteLine("uniquename=" + templateUuid);
|
||||
sw.WriteLine(format + "=true");
|
||||
sw.WriteLine("virtualsize=" + virtualSize);
|
||||
sw.WriteLine(format + ".virtualsize=" + virtualSize);
|
||||
sw.WriteLine("size=" + physicalSize);
|
||||
sw.WriteLine("vhd.size=" + physicalSize);
|
||||
sw.WriteLine("public=false");
|
||||
}
|
||||
}
|
||||
|
||||
private static bool VerifyChecksum(string destFile, string checksum)
|
||||
{
|
||||
string localChecksum = BitConverter.ToString(CalcFileChecksum(destFile)).Replace("-", "").ToLower();
|
||||
|
|
|
|||
Loading…
Reference in New Issue