Add a SCSI controller by default. This is needed so that data volumes can be added/removed

on a running vm.
This commit is contained in:
Devdeep Singh 2013-10-31 17:14:31 +05:30
parent 9cdf193d9a
commit 96b670a511
2 changed files with 37 additions and 1 deletions

View File

@ -986,7 +986,7 @@ namespace HypervResource
}
}
// POST api/HypervResource/StartupCommand
// POST api/HypervResource/CopyCommand
[HttpPost]
[ActionName(CloudStackTypes.CopyCommand)]
public JContainer CopyCommand(dynamic cmd)

View File

@ -188,6 +188,7 @@ namespace HypervResource
}
public const string IDE_HARDDISK_CONTROLLER = "Microsoft:Hyper-V:Emulated IDE Controller";
public const string SCSI_CONTROLLER = "Microsoft:Hyper-V:Synthetic SCSI Controller";
public const string IDE_HARDDISK_DRIVE = "Microsoft:Hyper-V:Synthetic Disk Drive";
public const string IDE_ISO_DRIVE = "Microsoft:Hyper-V:Synthetic DVD Drive";
@ -258,6 +259,9 @@ namespace HypervResource
logger.DebugFormat("Going ahead with create VM {0}, {1} vcpus, {2}MB RAM", vmName, vcpus, memSize);
var newVm = CreateVM(vmName, memSize, vcpus);
// Add a SCSI controller for attaching/detaching data volumes.
AddScsiControllerToVm(newVm);
foreach (var diskDrive in diskDrives)
{
string vhdFile = null;
@ -657,6 +661,38 @@ namespace HypervResource
return newDrivePaths[0];
}
private ManagementPath AddScsiControllerToVm(ComputerSystem vm)
{
// A description of the controller is created by modifying a clone of the default ResourceAllocationSettingData for scsi controller
string scsiQuery = String.Format("ResourceSubType LIKE \"{0}\" AND InstanceID LIKE \"%Default\"", SCSI_CONTROLLER);
var scsiSettings = CloneResourceAllocationSetting(scsiQuery);
scsiSettings.LateBoundObject["ElementName"] = "SCSI Controller";
scsiSettings.CommitObject();
// Insert SCSI controller into vm
string[] newResources = new string[] { scsiSettings.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20) };
ManagementPath[] newResourcePaths = AddVirtualResource(newResources, vm);
// assert
if (newResourcePaths.Length != 1)
{
var errMsg = string.Format(
"Failed to add scsi controller to VM {0} (GUID {1}): number of resource created {2}",
vm.ElementName,
vm.Name,
newResourcePaths.Length);
var ex = new WmiException(errMsg);
logger.Error(errMsg, ex);
throw ex;
}
logger.DebugFormat("New controller type {0} WMI path is {1}s",
scsiSettings.ResourceSubType,
newResourcePaths[0].Path);
return newResourcePaths[0];
}
private void InsertDiskImage(ComputerSystem vm, string diskImagePath, string diskResourceSubType, ManagementPath drivePath)
{