Skip to content

Commit 3604f87

Browse files
committed
CLOUDSTACK-5217: Attach volume fails with NPE. Made changes to make sure
the hypervisor product version is reported on startup. Also made changes to fix attach and detach volume on scsi controller.
1 parent 025335a commit 3604f87

4 files changed

Lines changed: 158 additions & 39 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ public static NFSTO ParseJson(dynamic json)
406406
public class DiskTO
407407
{
408408
public string type;
409+
public string diskSequence = null;
409410
public TemplateObjectTO templateObjectTO = null;
411+
public VolumeObjectTO volumeObjectTO = null;
410412

411413
public static DiskTO ParseJson(dynamic json)
412414
{
@@ -416,7 +418,9 @@ public static DiskTO ParseJson(dynamic json)
416418
result = new DiskTO()
417419
{
418420
templateObjectTO = TemplateObjectTO.ParseJson(json.data),
421+
volumeObjectTO = VolumeObjectTO.ParseJson(json.data),
419422
type = (string)json.type,
423+
diskSequence = json.diskSeq
420424
};
421425
}
422426

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

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,29 @@ public JContainer AttachCommand([FromBody]dynamic cmd)
215215
{
216216
string vmName = (string)cmd.vmName;
217217
DiskTO disk = DiskTO.ParseJson(cmd.disk);
218-
TemplateObjectTO dataStore = disk.templateObjectTO;
219218

220-
if (dataStore.nfsDataStoreTO != null)
219+
if (disk.type.Equals("ISO"))
221220
{
221+
TemplateObjectTO dataStore = disk.templateObjectTO;
222222
NFSTO share = dataStore.nfsDataStoreTO;
223223
Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password);
224-
225-
// The share is mapped, now attach the iso
226-
string isoPath = Utils.NormalizePath(Path.Combine(share.UncPath, dataStore.path));
227-
wmiCallsV2.AttachIso(vmName, isoPath);
224+
string diskPath = Utils.NormalizePath(Path.Combine(share.UncPath, dataStore.path));
225+
wmiCallsV2.AttachIso(vmName, diskPath);
226+
result = true;
227+
}
228+
else if (disk.type.Equals("DATADISK"))
229+
{
230+
VolumeObjectTO volume = disk.volumeObjectTO;
231+
PrimaryDataStoreTO primary = volume.primaryDataStore;
232+
Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password);
233+
string diskPath = Utils.NormalizePath(volume.FullFileName);
234+
wmiCallsV2.AttachDisk(vmName, diskPath, disk.diskSequence);
228235
result = true;
229236
}
237+
else
238+
{
239+
details = "Invalid disk type to be attached to vm " + vmName;
240+
}
230241
}
231242
catch (Exception sysEx)
232243
{
@@ -238,6 +249,7 @@ public JContainer AttachCommand([FromBody]dynamic cmd)
238249
{
239250
result = result,
240251
details = details,
252+
disk = cmd.disk,
241253
contextMap = contextMap
242254
};
243255

@@ -261,16 +273,27 @@ public JContainer DetachCommand([FromBody]dynamic cmd)
261273
{
262274
string vmName = (string)cmd.vmName;
263275
DiskTO disk = DiskTO.ParseJson(cmd.disk);
264-
TemplateObjectTO dataStore = disk.templateObjectTO;
265276

266-
if (dataStore.nfsDataStoreTO != null)
277+
if (disk.type.Equals("ISO"))
267278
{
279+
TemplateObjectTO dataStore = disk.templateObjectTO;
268280
NFSTO share = dataStore.nfsDataStoreTO;
269-
// The share is mapped, now attach the iso
270-
string isoPath = Utils.NormalizePath(Path.Combine(share.UncPath, dataStore.path));
271-
wmiCallsV2.DetachDisk(vmName, isoPath);
281+
string diskPath = Utils.NormalizePath(Path.Combine(share.UncPath, dataStore.path));
282+
wmiCallsV2.DetachDisk(vmName, diskPath);
272283
result = true;
273284
}
285+
else if (disk.type.Equals("DATADISK"))
286+
{
287+
VolumeObjectTO volume = disk.volumeObjectTO;
288+
PrimaryDataStoreTO primary = volume.primaryDataStore;
289+
string diskPath = Utils.NormalizePath(volume.FullFileName);
290+
wmiCallsV2.DetachDisk(vmName, diskPath);
291+
result = true;
292+
}
293+
else
294+
{
295+
details = "Invalid disk type to be dettached from vm " + vmName;
296+
}
274297
}
275298
catch (Exception sysEx)
276299
{
@@ -1649,6 +1672,14 @@ public JContainer StartupCommand([FromBody]dynamic cmdArray)
16491672
strtRouteCmd.hypervisorVersion = System.Environment.OSVersion.Version.ToString();
16501673
strtRouteCmd.caps = "hvm";
16511674

1675+
dynamic details = strtRouteCmd.hostDetails;
1676+
if (details != null)
1677+
{
1678+
string productVersion = System.Environment.OSVersion.Version.Major.ToString() + "." +
1679+
System.Environment.OSVersion.Version.Minor.ToString();
1680+
details.Add("product_version", productVersion);
1681+
}
1682+
16521683
// Detect CPUs, speed, memory
16531684
uint cores;
16541685
uint mhz;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ namespace HypervResource
2727
{
2828
public interface IWmiCallsV2
2929
{
30-
System.Management.ManagementPath AddDiskDriveToVm(ComputerSystem vm, string vhdfile, string cntrllerAddr, string driveResourceType);
30+
System.Management.ManagementPath AddDiskDriveToIdeController(ComputerSystem vm, string vhdfile, string cntrllerAddr, string driveResourceType);
3131
ComputerSystem AddUserData(ComputerSystem vm, string userData);
3232
void AttachIso(string displayName, string iso);
33+
void AttachDisk(string vmName, string diskPath, string addressOnController);
3334
void CreateDynamicVirtualHardDisk(ulong MaxInternalSize, string Path);
3435
SyntheticEthernetPortSettingData CreateNICforVm(ComputerSystem vm, string mac);
3536
ComputerSystem CreateVM(string name, long memory_mb, int vcpus);

0 commit comments

Comments
 (0)