You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by de...@apache.org on 2014/01/09 06:20:46 UTC

git commit: updated refs/heads/4.3 to 2ace4fe

Updated Branches:
  refs/heads/4.3 2efe61ddb -> 2ace4fe24


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.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2ace4fe2
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2ace4fe2
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2ace4fe2

Branch: refs/heads/4.3
Commit: 2ace4fe24159d549baef61e931e0c4747f0ffa31
Parents: 2efe61d
Author: Devdeep Singh <de...@gmail.com>
Authored: Wed Jan 8 21:36:52 2014 +0530
Committer: Devdeep Singh <de...@gmail.com>
Committed: Thu Jan 9 10:50:59 2014 +0530

----------------------------------------------------------------------
 .../HypervResource/CloudStackTypes.cs           |  4 ++-
 .../HypervResource/HypervResourceController.cs  | 26 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ace4fe2/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
index 226610b..a3258ce 100644
--- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
+++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
@@ -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);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ace4fe2/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
index c678c01..5ed3904 100644
--- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
+++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
@@ -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();