예제 #1
0
        public static VirtualHardDiskInfo[] Get(PowerShellManager powerShell, string vmname)
        {
            List<VirtualHardDiskInfo> disks = new List<VirtualHardDiskInfo>();

            Collection<PSObject> result = GetPS(powerShell, vmname);

            if (result != null && result.Count > 0)
            {
                foreach (PSObject d in result)
                {
                    VirtualHardDiskInfo disk = new VirtualHardDiskInfo();

                    disk.SupportPersistentReservations = Convert.ToBoolean(d.GetProperty("SupportPersistentReservations"));
                    disk.MaximumIOPS = Convert.ToUInt64(d.GetProperty("MaximumIOPS"));
                    disk.MinimumIOPS = Convert.ToUInt64(d.GetProperty("MinimumIOPS"));
                    disk.VHDControllerType = d.GetEnum<ControllerType>("ControllerType");
                    disk.ControllerNumber = Convert.ToInt32(d.GetProperty("ControllerNumber"));
                    disk.ControllerLocation = Convert.ToInt32(d.GetProperty("ControllerLocation"));
                    disk.Path = d.GetProperty("Path").ToString();
                    disk.Name = d.GetProperty("Name").ToString();

                    GetVirtualHardDiskDetail(powerShell, disk.Path, ref disk);

                    disks.Add(disk);
                }
            }
            return disks.ToArray();
        }
예제 #2
0
        public static VirtualHardDiskInfo[] Get(PowerShellManager powerShell, string vmname)
        {
            List <VirtualHardDiskInfo> disks = new List <VirtualHardDiskInfo>();

            Collection <PSObject> result = GetPS(powerShell, vmname);

            if (result != null && result.Count > 0)
            {
                foreach (PSObject d in result)
                {
                    VirtualHardDiskInfo disk = new VirtualHardDiskInfo();

                    disk.SupportPersistentReservations = Convert.ToBoolean(d.GetProperty("SupportPersistentReservations"));
                    disk.MaximumIOPS        = Convert.ToUInt64(d.GetProperty("MaximumIOPS"));
                    disk.MinimumIOPS        = Convert.ToUInt64(d.GetProperty("MinimumIOPS"));
                    disk.VHDControllerType  = d.GetEnum <ControllerType>("ControllerType");
                    disk.ControllerNumber   = Convert.ToInt32(d.GetProperty("ControllerNumber"));
                    disk.ControllerLocation = Convert.ToInt32(d.GetProperty("ControllerLocation"));
                    disk.Path = d.GetProperty("Path").ToString();
                    disk.Name = d.GetProperty("Name").ToString();

                    GetVirtualHardDiskDetail(powerShell, disk.Path, ref disk);

                    disks.Add(disk);
                }
            }
            return(disks.ToArray());
        }
예제 #3
0
 public static void GetVirtualHardDiskDetail(PowerShellManager powerShell, string path, ref VirtualHardDiskInfo disk)
 {
     if (!string.IsNullOrEmpty(path))
     {
         Command cmd = new Command("Get-VHD");
         cmd.Parameters.Add("Path", path);
         Collection<PSObject> result = powerShell.Execute(cmd, true);
         if (result != null && result.Count > 0)
         {
             disk.DiskFormat = result[0].GetEnum<VirtualHardDiskFormat>("VhdFormat");
             disk.DiskType = result[0].GetEnum<VirtualHardDiskType>("VhdType");
             disk.ParentPath = result[0].GetProperty<string>("ParentPath");
             disk.MaxInternalSize = Convert.ToInt64(result[0].GetProperty("Size"));
             disk.FileSize = Convert.ToInt64(result[0].GetProperty("FileSize"));
             disk.Attached = disk.InUse = Convert.ToBoolean(result[0].GetProperty("Attached"));
         }
     }
 }
예제 #4
0
 public VirtualHardDiskInfo GetVirtualHardDiskInfo(string vhdPath)
 {
     try
     {
         VirtualHardDiskInfo hardDiskInfo = new VirtualHardDiskInfo();
         HardDriveHelper.GetVirtualHardDiskDetail(PowerShell, vhdPath, ref hardDiskInfo);
         return hardDiskInfo;
     }
     catch (Exception ex)
     {
         HostedSolutionLog.LogError("GetVirtualHardDiskInfo", ex);
         throw;
     }
 }
예제 #5
0
        public VirtualHardDiskInfo GetVirtualHardDiskInfo(string vhdPath)
        {
            ManagementObject objImgSvc = GetImageManagementService();

            // get method params
            ManagementBaseObject inParams = objImgSvc.GetMethodParameters("GetVirtualHardDiskInfo");
            inParams["Path"] = FileUtils.EvaluateSystemVariables(vhdPath);

            // execute method
            ManagementBaseObject outParams = (ManagementBaseObject)objImgSvc.InvokeMethod("GetVirtualHardDiskInfo", inParams, null);
            ReturnCode result = (ReturnCode)Convert.ToInt32(outParams["ReturnValue"]);
            if (result == ReturnCode.OK)
            {
                // create XML
                string xml = (string)outParams["Info"];
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);

                // read properties
                VirtualHardDiskInfo vhd = new VirtualHardDiskInfo();
                vhd.DiskType = (VirtualHardDiskType)Enum.Parse(typeof(VirtualHardDiskType), GetPropertyValue("Type", doc), true);
                vhd.FileSize = Int64.Parse(GetPropertyValue("FileSize", doc));
                vhd.InSavedState = Boolean.Parse(GetPropertyValue("InSavedState", doc));
                vhd.InUse = Boolean.Parse(GetPropertyValue("InUse", doc));
                vhd.MaxInternalSize = Int64.Parse(GetPropertyValue("MaxInternalSize", doc));
                vhd.ParentPath = GetPropertyValue("ParentPath", doc);
                return vhd;
            }
            return null;
        }
예제 #6
0
 public static void GetVirtualHardDiskDetail(PowerShellManager powerShell, string path, ref VirtualHardDiskInfo disk)
 {
     if (!string.IsNullOrEmpty(path))
     {
         Command cmd = new Command("Get-VHD");
         cmd.Parameters.Add("Path", path);
         Collection <PSObject> result = powerShell.Execute(cmd, true);
         if (result != null && result.Count > 0)
         {
             disk.DiskFormat      = result[0].GetEnum <VirtualHardDiskFormat>("VhdFormat");
             disk.DiskType        = result[0].GetEnum <VirtualHardDiskType>("VhdType");
             disk.ParentPath      = result[0].GetProperty <string>("ParentPath");
             disk.MaxInternalSize = Convert.ToInt64(result[0].GetProperty("Size"));
             disk.FileSize        = Convert.ToInt64(result[0].GetProperty("FileSize"));
             disk.Attached        = disk.InUse = Convert.ToBoolean(result[0].GetProperty("Attached"));
         }
     }
 }