Updated Branches: refs/heads/hyperv 9cdf193d9 -> 96b670a51
Add a SCSI controller by default. This is needed so that data volumes can be added/removed on a running vm. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/96b670a5 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/96b670a5 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/96b670a5 Branch: refs/heads/hyperv Commit: 96b670a511003604ec3e963750bd1849610b1168 Parents: 9cdf193 Author: Devdeep Singh <devd...@gmail.com> Authored: Thu Oct 31 17:14:31 2013 +0530 Committer: Devdeep Singh <devd...@gmail.com> Committed: Thu Oct 31 17:17:27 2013 +0530 ---------------------------------------------------------------------- .../HypervResource/HypervResourceController.cs | 2 +- .../ServerResource/HypervResource/WmiCallsV2.cs | 36 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96b670a5/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs index 55c37f3..eb8834f 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs @@ -986,7 +986,7 @@ namespace HypervResource } } - // POST api/HypervResource/StartupCommand + // POST api/HypervResource/CopyCommand [HttpPost] [ActionName(CloudStackTypes.CopyCommand)] public JContainer CopyCommand(dynamic cmd) http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96b670a5/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs index 71c75d3..18b96cc 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs @@ -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) {