Merge
This commit is contained in:
commit
3270eedf22
3 changed files with 50 additions and 9 deletions
|
@ -20,5 +20,8 @@ namespace WebsitePanel.Providers.Virtualization
|
||||||
|
|
||||||
public const Int64 Size1G = 0x40000000;
|
public const Int64 Size1G = 0x40000000;
|
||||||
public const Int64 Size1M = 0x100000;
|
public const Int64 Size1M = 0x100000;
|
||||||
|
|
||||||
|
public const string KVP_RAM_SUMMARY_KEY = "VM-RAM-Summary";
|
||||||
|
public const string KVP_HDD_SUMMARY_KEY = "VM-HDD-Summary";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,8 @@ namespace WebsitePanel.Providers.Virtualization
|
||||||
|
|
||||||
cmd.Parameters.Add("VMName", vm.Name);
|
cmd.Parameters.Add("VMName", vm.Name);
|
||||||
cmd.Parameters.Add("Count", cpuCores);
|
cmd.Parameters.Add("Count", cpuCores);
|
||||||
cmd.Parameters.Add("Maximum", Convert.ToInt64(cpuLimitSettings * 1000));
|
cmd.Parameters.Add("Maximum", cpuLimitSettings);
|
||||||
cmd.Parameters.Add("Reserve", Convert.ToInt64(cpuReserveSettings * 1000));
|
cmd.Parameters.Add("Reserve", cpuReserveSettings);
|
||||||
cmd.Parameters.Add("RelativeWeight", cpuWeightSettings);
|
cmd.Parameters.Add("RelativeWeight", cpuWeightSettings);
|
||||||
|
|
||||||
powerShell.Execute(cmd, true);
|
powerShell.Execute(cmd, true);
|
||||||
|
|
|
@ -152,7 +152,10 @@ namespace WebsitePanel.Providers.Virtualization
|
||||||
vm.Name = result[0].GetProperty("Name").ToString();
|
vm.Name = result[0].GetProperty("Name").ToString();
|
||||||
vm.State = result[0].GetEnum<VirtualMachineState>("State");
|
vm.State = result[0].GetEnum<VirtualMachineState>("State");
|
||||||
vm.CpuUsage = ConvertNullableToInt32(result[0].GetProperty("CpuUsage"));
|
vm.CpuUsage = ConvertNullableToInt32(result[0].GetProperty("CpuUsage"));
|
||||||
vm.RamUsage = Convert.ToInt32(ConvertNullableToInt64(result[0].GetProperty("MemoryAssigned")) / Constants.Size1M);
|
// This does not truly give the RAM usage, only the memory assigned to the VPS
|
||||||
|
// Lets handle detection of total memory and usage else where
|
||||||
|
//vm.RamUsage = Convert.ToInt32(ConvertNullableToInt64(result[0].GetProperty("MemoryAssigned")) / Constants.Size1M);
|
||||||
|
vm.RamSize = Convert.ToInt32(ConvertNullableToInt64(result[0].GetProperty("MemoryStartup")) / Constants.Size1M);
|
||||||
vm.Uptime = Convert.ToInt64(result[0].GetProperty<TimeSpan>("UpTime").TotalMilliseconds);
|
vm.Uptime = Convert.ToInt64(result[0].GetProperty<TimeSpan>("UpTime").TotalMilliseconds);
|
||||||
vm.Status = result[0].GetProperty("Status").ToString();
|
vm.Status = result[0].GetProperty("Status").ToString();
|
||||||
vm.ReplicationState = result[0].GetProperty("ReplicationState").ToString();
|
vm.ReplicationState = result[0].GetProperty("ReplicationState").ToString();
|
||||||
|
@ -192,6 +195,38 @@ namespace WebsitePanel.Providers.Virtualization
|
||||||
// network adapters
|
// network adapters
|
||||||
vm.Adapters = NetworkAdapterHelper.Get(PowerShell, vm.Name);
|
vm.Adapters = NetworkAdapterHelper.Get(PowerShell, vm.Name);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Use the WebsitePanel VMConfig Windows service to get the RAM usage as well as the HDD usage / sizes
|
||||||
|
List<KvpExchangeDataItem> vmKvps = GetKVPItems(vmId);
|
||||||
|
foreach (KvpExchangeDataItem vmKvp in vmKvps)
|
||||||
|
{
|
||||||
|
// RAM
|
||||||
|
if (vmKvp.Name == Constants.KVP_RAM_SUMMARY_KEY)
|
||||||
|
{
|
||||||
|
string[] ram = vmKvp.Data.Split(':');
|
||||||
|
int freeRam = Int32.Parse(ram[0]);
|
||||||
|
int availRam = Int32.Parse(ram[1]);
|
||||||
|
|
||||||
|
vm.RamUsage = availRam - freeRam;
|
||||||
|
}
|
||||||
|
|
||||||
|
// HDD
|
||||||
|
if (vmKvp.Name == Constants.KVP_HDD_SUMMARY_KEY)
|
||||||
|
{
|
||||||
|
string[] disksArray = vmKvp.Data.Split(';');
|
||||||
|
vm.HddLogicalDisks = new LogicalDisk[disksArray.Length];
|
||||||
|
for (int i = 0; i < disksArray.Length; i++)
|
||||||
|
{
|
||||||
|
string[] disk = disksArray[i].Split(':');
|
||||||
|
vm.HddLogicalDisks[i] = new LogicalDisk();
|
||||||
|
vm.HddLogicalDisks[i].DriveLetter = disk[0];
|
||||||
|
vm.HddLogicalDisks[i].FreeSpace = Int32.Parse(disk[1]);
|
||||||
|
vm.HddLogicalDisks[i].Size = Int32.Parse(disk[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -504,19 +539,21 @@ namespace WebsitePanel.Providers.Virtualization
|
||||||
if (vm.State != VirtualMachineState.Saved && vm.State != VirtualMachineState.Off)
|
if (vm.State != VirtualMachineState.Saved && vm.State != VirtualMachineState.Off)
|
||||||
throw new Exception("The virtual computer system must be in the powered off or saved state prior to calling Destroy method.");
|
throw new Exception("The virtual computer system must be in the powered off or saved state prior to calling Destroy method.");
|
||||||
|
|
||||||
// Delete network adapters and network switchesw
|
// Delete network adapters and network switches
|
||||||
foreach (var networkAdapter in vm.Adapters)
|
foreach (var networkAdapter in vm.Adapters)
|
||||||
{
|
{
|
||||||
NetworkAdapterHelper.Delete(PowerShell, vm.Name, networkAdapter);
|
NetworkAdapterHelper.Delete(PowerShell, vm.Name, networkAdapter);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(networkAdapter.SwitchName))
|
// If more than 1 VM are assigned to the same switch, deleting the virtual machine also deletes the switch which takes other VM instances off line
|
||||||
DeleteSwitch(networkAdapter.SwitchName);
|
// There may be a reason for this that I am not aware of?
|
||||||
|
//if (!string.IsNullOrEmpty(networkAdapter.SwitchName))
|
||||||
|
//DeleteSwitch(networkAdapter.SwitchName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command cmdSet = new Command("Remove-VM");
|
Command cmdSet = new Command("Remove-VM");
|
||||||
cmdSet.Parameters.Add("Name", vm.Name);
|
cmdSet.Parameters.Add("Name", vm.Name);
|
||||||
cmdSet.Parameters.Add("Force");
|
cmdSet.Parameters.Add("Force");
|
||||||
PowerShell.Execute(cmdSet, false, true);
|
PowerShell.Execute(cmdSet, true, true);
|
||||||
|
|
||||||
return JobHelper.CreateSuccessResult(ReturnCode.JobStarted);
|
return JobHelper.CreateSuccessResult(ReturnCode.JobStarted);
|
||||||
}
|
}
|
||||||
|
@ -782,10 +819,11 @@ namespace WebsitePanel.Providers.Virtualization
|
||||||
|
|
||||||
Command cmd = new Command("Get-VMSwitch");
|
Command cmd = new Command("Get-VMSwitch");
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(computerName)) cmd.Parameters.Add("ComputerName", computerName);
|
// Not needed as the PowerShellManager adds the computer name
|
||||||
|
//if (!string.IsNullOrEmpty(computerName)) cmd.Parameters.Add("ComputerName", computerName);
|
||||||
if (!string.IsNullOrEmpty(type)) cmd.Parameters.Add("SwitchType", type);
|
if (!string.IsNullOrEmpty(type)) cmd.Parameters.Add("SwitchType", type);
|
||||||
|
|
||||||
Collection<PSObject> result = PowerShell.Execute(cmd, false, true);
|
Collection<PSObject> result = PowerShell.Execute(cmd, true, true);
|
||||||
|
|
||||||
foreach (PSObject current in result)
|
foreach (PSObject current in result)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue