CLOUDSTACK-5308, CLOUDSTACK-5542: Copy command didn't handle the scenario

when a volume is copied to secondary storage for template creation.
Updated the command to handle it.
This commit is contained in:
Devdeep Singh 2013-12-26 22:30:27 +05:30
parent c75f8bcc06
commit 1a033eddae
2 changed files with 67 additions and 12 deletions

View File

@ -301,20 +301,34 @@ namespace HypervResource
{
get
{
if (String.IsNullOrEmpty(this.path))
string fileName = null;
if (this.primaryDataStore != null)
{
string fileName = null;
if (this.primaryDataStore.isLocal)
PrimaryDataStoreTO store = this.primaryDataStore;
if (store.isLocal)
{
fileName = Path.Combine(this.primaryDataStore.Path, this.name);
fileName = Path.Combine(store.Path, this.name);
}
else
{
fileName = @"\\" + this.primaryDataStore.uri.Host + this.primaryDataStore.uri.LocalPath + @"\" + this.name;
fileName = @"\\" + store.uri.Host + store.uri.LocalPath + @"\" + this.name;
}
return fileName +'.' + this.format.ToLowerInvariant();
fileName = fileName + '.' + this.format.ToLowerInvariant();
}
return this.path;
else if (this.nfsDataStoreTO != null)
{
NFSTO store = this.nfsDataStoreTO;
fileName = store.UncPath + @"\" + this.path + @"\" + this.name;
if (!this.format.Equals("RAW"))
{
fileName = fileName + '.' + this.format.ToLowerInvariant();
}
}
else
{
fileName = this.path;
}
return Utils.NormalizePath(fileName);
}
}

View File

@ -1262,13 +1262,22 @@ namespace HypervResource
VolumeObjectTO destVolumeObjectTO = VolumeObjectTO.ParseJson(cmd.destTO);
string destFile = null;
if (destTemplateObjectTO != null && destTemplateObjectTO.primaryDataStore != null)
if (destTemplateObjectTO != null)
{
destFile = destTemplateObjectTO.FullFileName;
if (!destTemplateObjectTO.primaryDataStore.isLocal)
if (destTemplateObjectTO.primaryDataStore != null)
{
PrimaryDataStoreTO primary = destTemplateObjectTO.primaryDataStore;
Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password);
destFile = destTemplateObjectTO.FullFileName;
if (!destTemplateObjectTO.primaryDataStore.isLocal)
{
PrimaryDataStoreTO primary = destTemplateObjectTO.primaryDataStore;
Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password);
}
}
else if (destTemplateObjectTO.nfsDataStoreTO != null)
{
destFile = destTemplateObjectTO.FullFileName;
NFSTO store = destTemplateObjectTO.nfsDataStoreTO;
Utils.ConnectToRemote(store.UncPath, store.Domain, store.User, store.Password);
}
}
@ -1428,6 +1437,38 @@ namespace HypervResource
result = true;
}
}
else if (srcVolumeObjectTO != null && destTemplateObjectTO != null)
{
var guessedDestFile = destTemplateObjectTO.FullFileName;
if (File.Exists(guessedDestFile))
{
logger.Info("Deleting existing file " + guessedDestFile);
File.Delete(guessedDestFile);
}
destTemplateObjectTO.format = srcVolumeObjectTO.format;
destFile = destTemplateObjectTO.FullFileName;
if (File.Exists(destFile))
{
logger.Info("Deleting existing file " + destFile);
File.Delete(destFile);
}
string srcFile = srcVolumeObjectTO.FullFileName;
if (!File.Exists(srcFile))
{
details = "Local template file missing from " + srcFile;
}
else
{
// Create the directory before copying the files. CreateDirectory
// doesn't do anything if the directory is already present.
Directory.CreateDirectory(Path.GetDirectoryName(destFile));
File.Copy(srcFile, destFile);
newData = cmd.destTO;
result = true;
}
}
else
{
details = "Data store combination not supported";