wsp-10327 Add Dynamic Memory to VPS - Server Part.
This commit is contained in:
parent
1c48c3d230
commit
8fa9792b83
12 changed files with 171 additions and 92 deletions
|
@ -0,0 +1,58 @@
|
|||
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 MemoryHelper
|
||||
{
|
||||
public static DynamicMemory GetDynamicMemory(PowerShellManager powerShell, string vmName)
|
||||
{
|
||||
DynamicMemory info = null;
|
||||
|
||||
Command cmd = new Command("Get-VMMemory");
|
||||
cmd.Parameters.Add("VMName", vmName);
|
||||
Collection<PSObject> result = powerShell.Execute(cmd);
|
||||
|
||||
if (result != null && result.Count > 0)
|
||||
{
|
||||
info = new DynamicMemory();
|
||||
info.Enabled = result[0].GetBool("DynamicMemoryEnabled");
|
||||
info.Minimum = Convert.ToInt32(result[0].GetLong("Minimum") / Constants.Size1M);
|
||||
info.Maximum = Convert.ToInt32(result[0].GetLong("Maximum") / Constants.Size1M);
|
||||
info.Buffer = Convert.ToInt32(result[0].GetInt("Buffer") / Constants.Size1M);
|
||||
info.Priority = Convert.ToInt32(result[0].GetInt("Priority") / Constants.Size1M);
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public static void Update(PowerShellManager powerShell, VirtualMachine vm, int ramMb, DynamicMemory dynamicMemory)
|
||||
{
|
||||
Command cmd = new Command("Set-VMMemory");
|
||||
|
||||
cmd.Parameters.Add("VMName", vm.Name);
|
||||
cmd.Parameters.Add("StartupBytes", ramMb * Constants.Size1M);
|
||||
|
||||
if (dynamicMemory != null && dynamicMemory.Enabled)
|
||||
{
|
||||
cmd.Parameters.Add("DynamicMemoryEnabled", true);
|
||||
cmd.Parameters.Add("MinimumBytes", dynamicMemory.Minimum * Constants.Size1M);
|
||||
cmd.Parameters.Add("MaximumBytes", dynamicMemory.Maximum * Constants.Size1M);
|
||||
cmd.Parameters.Add("Buffer", dynamicMemory.Buffer);
|
||||
cmd.Parameters.Add("Priority", dynamicMemory.Priority);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.Parameters.Add("DynamicMemoryEnabled", false);
|
||||
}
|
||||
|
||||
powerShell.Execute(cmd, true);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue