cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devd...@apache.org
Subject [43/54] git commit: updated refs/heads/hyperv to a27899a
Date Mon, 28 Oct 2013 06:05:09 GMT
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 <devdeep@gmail.com>
Authored: Fri Oct 11 15:12:18 2013 +0530
Committer: Devdeep Singh <devdeep@gmail.com>
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];
         }
 
+        /// <summary>
+        /// Attach iso to the vm
+        /// </summary>
+        /// <param name="vm"></param>
+        /// <param name="isoPath"></param>
+        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);


Mime
View raw message