CLOUDSTACK-8431: [Hyper-V] Fixed VM deployment failing when the stale vhd already exists Now generating guid when the template copy from secondary to primary storage requested instead of using it same as secondary

this closes #214
This commit is contained in:
Anshul Gangwar 2015-04-24 15:23:18 +05:30 committed by Rajesh Battala
parent d9064ecfea
commit aa265fe88f
2 changed files with 194 additions and 210 deletions

View File

@ -290,11 +290,11 @@ namespace HypervResource
PrimaryDataStoreTO store = this.primaryDataStore; PrimaryDataStoreTO store = this.primaryDataStore;
if (store.isLocal) if (store.isLocal)
{ {
fileName = Path.Combine(store.Path, this.uuid); fileName = Path.Combine(store.Path, this.path);
} }
else else
{ {
fileName = @"\\" + store.uri.Host + store.uri.LocalPath + @"\" + this.uuid; fileName = @"\\" + store.uri.Host + store.uri.LocalPath + @"\" + this.path;
} }
fileName = fileName + '.' + this.format.ToLowerInvariant(); fileName = fileName + '.' + this.format.ToLowerInvariant();
} }

View File

@ -1538,6 +1538,10 @@ namespace HypervResource
string destFile = null; string destFile = null;
if (destTemplateObjectTO != null) if (destTemplateObjectTO != null)
{ {
if (destTemplateObjectTO.path == null)
{
destTemplateObjectTO.path = System.Guid.NewGuid().ToString();
}
if (destTemplateObjectTO.primaryDataStore != null) if (destTemplateObjectTO.primaryDataStore != null)
{ {
destFile = destTemplateObjectTO.FullFileName; destFile = destTemplateObjectTO.FullFileName;
@ -1548,24 +1552,6 @@ namespace HypervResource
} }
} }
// Template already downloaded?
if (destFile != null && File.Exists(destFile) &&
!String.IsNullOrEmpty(destTemplateObjectTO.checksum))
{
// TODO: checksum fails us, because it is of the compressed image.
// ASK: should we store the compressed or uncompressed version or is the checksum not calculated correctly?
logger.Debug(CloudStackTypes.CopyCommand + " calling VerifyChecksum to see if we already have the file at " + destFile);
result = VerifyChecksum(destFile, destTemplateObjectTO.checksum);
if (!result)
{
result = true;
logger.Debug(CloudStackTypes.CopyCommand + " existing file has different checksum " + destFile);
}
}
// Do we have to create a new one?
if (!result)
{
// Create local copy of a template? // Create local copy of a template?
if (srcTemplateObjectTO != null && destTemplateObjectTO != null) if (srcTemplateObjectTO != null && destTemplateObjectTO != null)
{ {
@ -1633,7 +1619,6 @@ namespace HypervResource
FileInfo destFileInfo = new FileInfo(destFile); FileInfo destFileInfo = new FileInfo(destFile);
destTemplateObjectTO.size = destFileInfo.Length.ToString(); destTemplateObjectTO.size = destFileInfo.Length.ToString();
destTemplateObjectTO.path = destTemplateObjectTO.uuid;
JObject ansObj = Utils.CreateCloudStackObject(CloudStackTypes.TemplateObjectTO, destTemplateObjectTO); JObject ansObj = Utils.CreateCloudStackObject(CloudStackTypes.TemplateObjectTO, destTemplateObjectTO);
newData = ansObj; newData = ansObj;
result = true; result = true;
@ -1784,7 +1769,6 @@ namespace HypervResource
details = "Data store combination not supported"; details = "Data store combination not supported";
} }
} }
}
catch (Exception ex) catch (Exception ex)
{ {
// Test by providing wrong key // Test by providing wrong key