wsp-10323 Convert the VSP provider into one utilizing PowerShell. Step 5 Storage
This commit is contained in:
parent
b15d7966da
commit
13ae446aa1
11 changed files with 274 additions and 271 deletions
|
@ -87,7 +87,7 @@ namespace WebsitePanel.Providers.Virtualization
|
|||
if (bootFromCD)
|
||||
cmd.Parameters.Add("FirstBootDevice", DvdDriveHelper.GetPS(powerShell, vm.Name));
|
||||
else
|
||||
cmd.Parameters.Add("FirstBootDevice", VirtualMachineHelper.GetVirtualHardDisksPS(powerShell, vm.Name).FirstOrDefault());
|
||||
cmd.Parameters.Add("FirstBootDevice", HardDriveHelper.GetPS(powerShell, vm.Name).FirstOrDefault());
|
||||
|
||||
powerShell.Execute(cmd, false);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Runspaces;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WebsitePanel.Providers.Virtualization
|
||||
{
|
||||
public static class HardDriveHelper
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
//public static VirtualHardDiskInfo GetByPath(PowerShellManager powerShell, string vhdPath)
|
||||
//{
|
||||
// VirtualHardDiskInfo info = null;
|
||||
// var vmNames = new List<string>();
|
||||
|
||||
// Command cmd = new Command("Get-VM");
|
||||
|
||||
// Collection<PSObject> result = powerShell.Execute(cmd, false);
|
||||
|
||||
// if (result == null || result.Count == 0)
|
||||
// return null;
|
||||
|
||||
// vmNames = result.Select(r => r.GetString("Name")).ToList();
|
||||
// var drives = vmNames.SelectMany(n => Get(powerShell, n));
|
||||
|
||||
// return drives.FirstOrDefault(d=>d.Path == vhdPath);
|
||||
//}
|
||||
|
||||
public static Collection<PSObject> GetPS(PowerShellManager powerShell, string vmname)
|
||||
{
|
||||
Command cmd = new Command("Get-VMHardDiskDrive");
|
||||
cmd.Parameters.Add("VMName", vmname);
|
||||
|
||||
return powerShell.Execute(cmd, false);
|
||||
}
|
||||
|
||||
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, false);
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -12,16 +12,8 @@ namespace WebsitePanel.Providers.Virtualization
|
|||
{
|
||||
public static class VirtualMachineHelper
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const Int64 Size1G = 0x40000000;
|
||||
private const Int64 Size1M = 0x100000;
|
||||
|
||||
#endregion
|
||||
|
||||
public static OperationalStatus GetVMHeartBeatStatus(PowerShellManager powerShell, string name)
|
||||
{
|
||||
|
||||
OperationalStatus status = OperationalStatus.None;
|
||||
|
||||
Command cmd = new Command("Get-VMIntegrationService");
|
||||
|
@ -40,7 +32,6 @@ namespace WebsitePanel.Providers.Virtualization
|
|||
return status;
|
||||
}
|
||||
|
||||
|
||||
public static int GetVMProcessors(PowerShellManager powerShell, string name)
|
||||
{
|
||||
|
||||
|
@ -71,73 +62,15 @@ namespace WebsitePanel.Providers.Virtualization
|
|||
if (result != null && result.Count > 0)
|
||||
{
|
||||
info.DynamicMemoryEnabled = Convert.ToBoolean(result[0].GetProperty("DynamicMemoryEnabled"));
|
||||
info.Startup = Convert.ToInt64(result[0].GetProperty("Startup")) / Size1M;
|
||||
info.Minimum = Convert.ToInt64(result[0].GetProperty("Minimum")) / Size1M;
|
||||
info.Maximum = Convert.ToInt64(result[0].GetProperty("Maximum")) / Size1M;
|
||||
info.Startup = Convert.ToInt64(result[0].GetProperty("Startup")) / Constants.Size1M;
|
||||
info.Minimum = Convert.ToInt64(result[0].GetProperty("Minimum")) / Constants.Size1M;
|
||||
info.Maximum = Convert.ToInt64(result[0].GetProperty("Maximum")) / Constants.Size1M;
|
||||
info.Buffer = Convert.ToInt32(result[0].GetProperty("Buffer"));
|
||||
info.Priority = Convert.ToInt32(result[0].GetProperty("Priority"));
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
public static VirtualHardDiskInfo[] GetVirtualHardDisks(PowerShellManager powerShell, string name)
|
||||
{
|
||||
List<VirtualHardDiskInfo> disks = new List<VirtualHardDiskInfo>();
|
||||
|
||||
Collection<PSObject> result = GetVirtualHardDisksPS(powerShell, name);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public static Collection<PSObject> GetVirtualHardDisksPS(PowerShellManager powerShell, string name)
|
||||
{
|
||||
Command cmd = new Command("Get-VMHardDiskDrive");
|
||||
cmd.Parameters.Add("VMName", name);
|
||||
|
||||
return powerShell.Execute(cmd, false);
|
||||
}
|
||||
|
||||
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, false);
|
||||
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")) / Size1G;
|
||||
disk.FileSize = Convert.ToInt64(result[0].GetProperty("FileSize")) / Size1G;
|
||||
disk.Attached = Convert.ToBoolean(result[0].GetProperty("Attached"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void UpdateProcessors(PowerShellManager powerShell, VirtualMachine vm, int cpuCores, int cpuLimitSettings, int cpuReserveSettings, int cpuWeightSettings)
|
||||
{
|
||||
Command cmd = new Command("Set-VMProcessor");
|
||||
|
@ -150,12 +83,13 @@ namespace WebsitePanel.Providers.Virtualization
|
|||
|
||||
powerShell.Execute(cmd, false);
|
||||
}
|
||||
|
||||
public static void UpdateMemory(PowerShellManager powerShell, VirtualMachine vm, long ramMB)
|
||||
{
|
||||
Command cmd = new Command("Set-VMMemory");
|
||||
|
||||
cmd.Parameters.Add("VMName", vm.Name);
|
||||
cmd.Parameters.Add("StartupBytes", ramMB * Size1M);
|
||||
cmd.Parameters.Add("StartupBytes", ramMB * Constants.Size1M);
|
||||
|
||||
powerShell.Execute(cmd, false);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue