Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8263410A88 for ; Fri, 11 Oct 2013 10:04:46 +0000 (UTC) Received: (qmail 5186 invoked by uid 500); 11 Oct 2013 10:04:44 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 5167 invoked by uid 500); 11 Oct 2013 10:04:42 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 5134 invoked by uid 99); 11 Oct 2013 10:04:39 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Oct 2013 10:04:39 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 729A49152CE; Fri, 11 Oct 2013 10:04:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: devdeep@apache.org To: commits@cloudstack.apache.org Message-Id: <6d4ad351d26c445e9d44820f478492f7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/hyperv to f1c2c50 Date: Fri, 11 Oct 2013 10:04:38 +0000 (UTC) Updated Branches: refs/heads/hyperv 3a5c7f1e4 -> f1c2c502e Implementation for attach iso command. Attaches an iso to a given vm. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f1c2c502 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f1c2c502 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f1c2c502 Branch: refs/heads/hyperv Commit: f1c2c502eccfea040538b67c2633685c0395b6f8 Parents: 3a5c7f1 Author: Devdeep Singh Authored: Fri Oct 11 15:12:18 2013 +0530 Committer: Devdeep Singh Committed: Fri Oct 11 15:12:18 2013 +0530 ---------------------------------------------------------------------- .../HypervResource/HypervResourceController.cs | 70 +++++++++++++++++- .../ServerResource/HypervResource/WmiCalls.cs | 78 ++++++++++++++++++++ 2 files changed, 147 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f1c2c502/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 cce40e1..7a0c2db 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs @@ -151,6 +151,74 @@ namespace HypervResource } } + // POST api/HypervResource/AttachCommand + [HttpPost] + [ActionName(CloudStackTypes.AttachCommand)] + public JContainer AttachCommand([FromBody]dynamic cmd) + { + using (log4net.NDC.Push(Guid.NewGuid().ToString())) + { + logger.Info(CloudStackTypes.AttachCommand + cmd.ToString()); + + string details = null; + bool result = false; + + try + { + string vmName = (string)cmd.vmName; + string isoPath = "\\\\10.102.192.150\\SMB-Share\\202-2-305ed1f7-1be8-345e-86c3-a976f7f57f10.iso"; + WmiCalls.AttachIso(vmName, isoPath); + + result = true; + } + catch (Exception sysEx) + { + details = CloudStackTypes.AttachCommand + " failed due to " + sysEx.Message; + logger.Error(details, sysEx); + } + + object ansContent = new + { + result = result, + details = details + }; + + return ReturnCloudStackTypedJArray(ansContent, CloudStackTypes.AttachAnswer); + } + } + + // POST api/HypervResource/DetachCommand + [HttpPost] + [ActionName(CloudStackTypes.DettachCommand)] + public JContainer DetachCommand([FromBody]dynamic cmd) + { + using (log4net.NDC.Push(Guid.NewGuid().ToString())) + { + logger.Info(CloudStackTypes.DettachCommand + cmd.ToString()); + + string details = null; + bool result = false; + + try + { + string vmName = (string)cmd.vmName; + result = true; + } + catch (Exception sysEx) + { + details = CloudStackTypes.DettachCommand + " failed due to " + sysEx.Message; + logger.Error(details, sysEx); + } + + object ansContent = new + { + result = result, + details = details + }; + + return ReturnCloudStackTypedJArray(ansContent, CloudStackTypes.DettachAnswer); + } + } // POST api/HypervResource/DestroyCommand [HttpPost] @@ -1078,7 +1146,7 @@ namespace HypervResource { result = result, details = details, - newData = newData + newData = cmd.destTO }; return ReturnCloudStackTypedJArray(ansContent, CloudStackTypes.CopyCmdAnswer); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f1c2c502/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCalls.cs ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCalls.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCalls.cs index ad43d1f..9b00c82 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCalls.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCalls.cs @@ -400,6 +400,48 @@ namespace HypervResource return newDrivePaths[0]; } + /// + /// Attach iso to the vm + /// + /// + /// + private static void AttachIsoToVm(ComputerSystem vm, string isoPath) + { + // Disk drives are attached to a 'Parent' IDE controller. We IDE Controller's settings for the 'Path', which our new Disk drive will use to reference it. + VirtualSystemSettingData vmSettings = GetVmSettings(vm); + var ctrller = GetDvdDriveSettings(vmSettings); + + // A description of the drive is created by modifying a clone of the default ResourceAllocationSettingData for that drive type + string defaultDiskQuery = String.Format("ResourceSubType LIKE \"{0}\" AND InstanceID LIKE \"%Default\"", IDE_ISO_DISK); + var newDiskSettings = CloneResourceAllocationSetting(defaultDiskQuery); + + // Set IDE controller and address on the controller for the new drive + newDiskSettings.LateBoundObject["Parent"] = ctrller.Path.ToString(); + newDiskSettings.LateBoundObject["Connection"] = new string[] { isoPath }; + newDiskSettings.CommitObject(); + + // Add the new vhd object as a virtual hard disk to the vm. + string[] newDiskResource = new string[] { newDiskSettings.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20) }; + ManagementPath[] newDiskPaths = AddVirtualResource(newDiskResource, vm); + // assert + if (newDiskPaths.Length != 1) + { + var errMsg = string.Format( + "Failed to add disk image to VM {0} (GUID {1}): number of resource created {2}", + vm.ElementName, + vm.Name, + newDiskPaths.Length); + var ex = new WmiException(errMsg); + logger.Error(errMsg, ex); + throw ex; + } + logger.InfoFormat("Created disk {2} for VM {0} (GUID {1}), image {3} ", + vm.ElementName, + vm.Name, + newDiskPaths[0].Path, + isoPath); + } + private static void InsertDiskImage(ComputerSystem vm, string vhdfile, string diskResourceSubType, ManagementPath drivePath) { // A description of the disk is created by modifying a clone of the default ResourceAllocationSettingData for that disk type @@ -451,6 +493,22 @@ namespace HypervResource return new ResourceAllocationSettingData((ManagementBaseObject)defaultDiskDriveSettings.LateBoundObject.Clone()); } + public static void AttachIso(string displayName, string iso) + { + logger.DebugFormat("Got request to attach iso {0} to vm {1}", iso, displayName); + + ComputerSystem vm = GetComputerSystem(displayName); + if (vm == null) + { + logger.DebugFormat("VM {0} not found", displayName); + return; + } + else + { + AttachIsoToVm(vm, iso); + } + } + public static void DestroyVm(dynamic jsonObj) { string vmToDestroy = jsonObj.vmName; @@ -1073,6 +1131,26 @@ namespace HypervResource throw ex; } + public static ResourceAllocationSettingData GetDvdDriveSettings(VirtualSystemSettingData vmSettings) + { + var wmiObjCollection = GetResourceAllocationSettings(vmSettings); + + foreach (ResourceAllocationSettingData wmiObj in wmiObjCollection) + { + if (wmiObj.ResourceType == 16) + { + return wmiObj; + } + } + + var errMsg = string.Format( + "Cannot find the Dvd drive in VirtualSystemSettingData {0}", + vmSettings.Path.Path); + var ex = new WmiException(errMsg); + logger.Error(errMsg, ex); + throw ex; + } + public static ResourceAllocationSettingData GetIDEControllerSettings(VirtualSystemSettingData vmSettings, string cntrllerAddr) { var wmiObjCollection = GetResourceAllocationSettings(vmSettings);