Skip to content

Commit 1a033ed

Browse files
committed
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.
1 parent c75f8bc commit 1a033ed

2 files changed

Lines changed: 67 additions & 12 deletions

File tree

plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,34 @@ public string FullFileName
301301
{
302302
get
303303
{
304-
if (String.IsNullOrEmpty(this.path))
304+
string fileName = null;
305+
if (this.primaryDataStore != null)
305306
{
306-
string fileName = null;
307-
if (this.primaryDataStore.isLocal)
307+
PrimaryDataStoreTO store = this.primaryDataStore;
308+
if (store.isLocal)
308309
{
309-
fileName = Path.Combine(this.primaryDataStore.Path, this.name);
310+
fileName = Path.Combine(store.Path, this.name);
310311
}
311312
else
312313
{
313-
fileName = @"\\" + this.primaryDataStore.uri.Host + this.primaryDataStore.uri.LocalPath + @"\" + this.name;
314+
fileName = @"\\" + store.uri.Host + store.uri.LocalPath + @"\" + this.name;
314315
}
315-
return fileName +'.' + this.format.ToLowerInvariant();
316+
fileName = fileName + '.' + this.format.ToLowerInvariant();
317+
}
318+
else if (this.nfsDataStoreTO != null)
319+
{
320+
NFSTO store = this.nfsDataStoreTO;
321+
fileName = store.UncPath + @"\" + this.path + @"\" + this.name;
322+
if (!this.format.Equals("RAW"))
323+
{
324+
fileName = fileName + '.' + this.format.ToLowerInvariant();
325+
}
326+
}
327+
else
328+
{
329+
fileName = this.path;
316330
}
317-
return this.path;
331+
return Utils.NormalizePath(fileName);
318332
}
319333
}
320334

plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,13 +1262,22 @@ public JContainer CopyCommand(dynamic cmd)
12621262
VolumeObjectTO destVolumeObjectTO = VolumeObjectTO.ParseJson(cmd.destTO);
12631263

12641264
string destFile = null;
1265-
if (destTemplateObjectTO != null && destTemplateObjectTO.primaryDataStore != null)
1265+
if (destTemplateObjectTO != null)
12661266
{
1267-
destFile = destTemplateObjectTO.FullFileName;
1268-
if (!destTemplateObjectTO.primaryDataStore.isLocal)
1267+
if (destTemplateObjectTO.primaryDataStore != null)
12691268
{
1270-
PrimaryDataStoreTO primary = destTemplateObjectTO.primaryDataStore;
1271-
Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password);
1269+
destFile = destTemplateObjectTO.FullFileName;
1270+
if (!destTemplateObjectTO.primaryDataStore.isLocal)
1271+
{
1272+
PrimaryDataStoreTO primary = destTemplateObjectTO.primaryDataStore;
1273+
Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password);
1274+
}
1275+
}
1276+
else if (destTemplateObjectTO.nfsDataStoreTO != null)
1277+
{
1278+
destFile = destTemplateObjectTO.FullFileName;
1279+
NFSTO store = destTemplateObjectTO.nfsDataStoreTO;
1280+
Utils.ConnectToRemote(store.UncPath, store.Domain, store.User, store.Password);
12721281
}
12731282
}
12741283

@@ -1428,6 +1437,38 @@ public JContainer CopyCommand(dynamic cmd)
14281437
result = true;
14291438
}
14301439
}
1440+
else if (srcVolumeObjectTO != null && destTemplateObjectTO != null)
1441+
{
1442+
var guessedDestFile = destTemplateObjectTO.FullFileName;
1443+
if (File.Exists(guessedDestFile))
1444+
{
1445+
logger.Info("Deleting existing file " + guessedDestFile);
1446+
File.Delete(guessedDestFile);
1447+
}
1448+
1449+
destTemplateObjectTO.format = srcVolumeObjectTO.format;
1450+
destFile = destTemplateObjectTO.FullFileName;
1451+
if (File.Exists(destFile))
1452+
{
1453+
logger.Info("Deleting existing file " + destFile);
1454+
File.Delete(destFile);
1455+
}
1456+
1457+
string srcFile = srcVolumeObjectTO.FullFileName;
1458+
if (!File.Exists(srcFile))
1459+
{
1460+
details = "Local template file missing from " + srcFile;
1461+
}
1462+
else
1463+
{
1464+
// Create the directory before copying the files. CreateDirectory
1465+
// doesn't do anything if the directory is already present.
1466+
Directory.CreateDirectory(Path.GetDirectoryName(destFile));
1467+
File.Copy(srcFile, destFile);
1468+
newData = cmd.destTO;
1469+
result = true;
1470+
}
1471+
}
14311472
else
14321473
{
14331474
details = "Data store combination not supported";

0 commit comments

Comments
 (0)