Skip to content

Commit 78b39bb

Browse files
committed
CLOUDSTACK-5455: Fix detach iso on hyperv. Made sure normalized path is
used while attaching and detaching iso. Also made normalization of path across the agent code.
1 parent e498bf0 commit 78b39bb

4 files changed

Lines changed: 19 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public string FullFileName
160160
else
161161
{
162162
fileName = @"\\" + this.primaryDataStore.uri.Host + this.primaryDataStore.uri.LocalPath + @"\" + this.name;
163-
fileName = fileName.Replace(@"/", @"\");
163+
fileName = Utils.NormalizePath(fileName);
164164
}
165165

166166
if (this.format != null)

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public JContainer AttachCommand([FromBody]dynamic cmd)
223223
Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password);
224224

225225
// The share is mapped, now attach the iso
226-
string isoPath = Path.Combine(share.UncPath.Replace('/', Path.DirectorySeparatorChar), dataStore.path);
226+
string isoPath = Utils.NormalizePath(Path.Combine(share.UncPath, dataStore.path));
227227
wmiCallsV2.AttachIso(vmName, isoPath);
228228
result = true;
229229
}
@@ -267,8 +267,7 @@ public JContainer DetachCommand([FromBody]dynamic cmd)
267267
{
268268
NFSTO share = dataStore.nfsDataStoreTO;
269269
// The share is mapped, now attach the iso
270-
string isoPath = Path.Combine(share.UncPath.Replace('/', Path.DirectorySeparatorChar),
271-
dataStore.path.Replace('/', Path.DirectorySeparatorChar));
270+
string isoPath = Utils.NormalizePath(Path.Combine(share.UncPath, dataStore.path));
272271
wmiCallsV2.DetachDisk(vmName, isoPath);
273272
result = true;
274273
}
@@ -957,7 +956,7 @@ public JContainer StartCommand([FromBody]dynamic cmd)
957956
share.uri = new Uri(uriStr);
958957
string defaultDataPath = wmiCallsV2.GetDefaultDataRoot();
959958

960-
string secondaryPath = Path.Combine(share.UncPath, "systemvm").Replace(@"/", @"\");
959+
string secondaryPath = Utils.NormalizePath(Path.Combine(share.UncPath, "systemvm"));
961960
string[] choices = choices = Directory.GetFiles(secondaryPath, "systemvm*.iso");
962961
if (choices.Length != 1)
963962
{
@@ -966,7 +965,7 @@ public JContainer StartCommand([FromBody]dynamic cmd)
966965
}
967966
else
968967
{
969-
systemVmIsoPath = Path.Combine(defaultDataPath, Path.GetFileName(choices[0]));
968+
systemVmIsoPath = Utils.NormalizePath(Path.Combine(defaultDataPath, Path.GetFileName(choices[0])));
970969
if (!File.Exists(systemVmIsoPath))
971970
{
972971
Utils.DownloadCifsFileToLocalFile(choices[0], share, systemVmIsoPath);
@@ -1057,7 +1056,7 @@ public JContainer CreateObjectCommand([FromBody]dynamic cmd)
10571056
else
10581057
{
10591058
volumePath = @"\\" + primary.uri.Host + primary.uri.LocalPath + @"\" + volumeName;
1060-
volumePath = volumePath.Replace('/', '\\');
1059+
volumePath = Utils.NormalizePath(volumePath);
10611060
Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password);
10621061
}
10631062

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ public static JToken CreateCloudStackMapObject(object objValue)
5656
return objContent;
5757
}
5858

59+
public static string NormalizePath(string path)
60+
{
61+
if (!String.IsNullOrEmpty(path))
62+
{
63+
path = path.Replace('/', Path.DirectorySeparatorChar);
64+
}
65+
66+
return path;
67+
}
68+
5969
/// <summary>
6070
/// Copy file on network share to local volume.
6171
/// </summary>
@@ -80,7 +90,7 @@ public static void DownloadCifsFileToLocalFile(string filePathRelativeToShare, N
8090
if (filePathRelativeToShare.EndsWith(".iso") || filePathRelativeToShare.EndsWith(".vhd") || filePathRelativeToShare.EndsWith(".vhdx"))
8191
{
8292
dest = Path.Combine(cifsShareDetails.UncPath, filePathRelativeToShare);
83-
dest = dest.Replace('/', Path.DirectorySeparatorChar);
93+
dest = Utils.NormalizePath(dest);
8494
}
8595
// if the filePathRelativeToShare string don't have filename and only a dir point then find the vhd files in that folder and use
8696
// In the clean setup, first copy command wont be having the filename it contains onlyu dir path.
@@ -117,7 +127,7 @@ public static void ConnectToRemote(string remoteUNC, string domain, string usern
117127
{
118128
NETRESOURCE nr = new NETRESOURCE();
119129
nr.dwType = RESOURCETYPE_DISK;
120-
nr.lpRemoteName = remoteUNC.Replace('/', Path.DirectorySeparatorChar);
130+
nr.lpRemoteName = Utils.NormalizePath(remoteUNC);
121131
if (domain != null)
122132
{
123133
username = domain + @"\" + username;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public ComputerSystem DeployVirtualMachine(dynamic jsonObj, string systemVmIso)
335335
NFSTO share = templateInfo.nfsDataStoreTO;
336336
Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password);
337337
// The share is mapped, now attach the iso
338-
isoPath = Path.Combine(share.UncPath.Replace('/', Path.DirectorySeparatorChar), templateInfo.path);
338+
isoPath = Utils.NormalizePath(Path.Combine(share.UncPath, templateInfo.path));
339339
}
340340

341341
string driveType = diskDrive.type;

0 commit comments

Comments
 (0)