This commit is contained in:
Virtuworks 2015-03-19 20:09:45 -04:00
commit 4564bff8cd
44 changed files with 4282 additions and 144 deletions

View file

@ -1,4 +1,4 @@
USE [${install.database}] USE [${install.database}]
GO GO
-- update database version -- update database version
DECLARE @build_version nvarchar(10), @build_date datetime DECLARE @build_version nvarchar(10), @build_date datetime
@ -8860,6 +8860,12 @@ AND ((@GroupName IS NULL) OR (@GroupName IS NOT NULL AND RG.GroupName = @GroupNa
RETURN RETURN
GO GO
-- Hyper-V 2012 R2
IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [ProviderName] = 'HyperV2012R2')
BEGIN
INSERT [dbo].[Providers] ([ProviderID], [GroupID], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES (350, 30, N'HyperV2012R2', N'Microsoft Hyper-V 2012 R2', N'WebsitePanel.Providers.Virtualization.HyperV2012R2, WebsitePanel.Providers.Virtualization.HyperV2012R2', N'HyperV', 1)
END
GO
--ES OWA Editing --ES OWA Editing
IF NOT EXISTS (SELECT * FROM SYS.TABLES WHERE name = 'EnterpriseFoldersOwaPermissions') IF NOT EXISTS (SELECT * FROM SYS.TABLES WHERE name = 'EnterpriseFoldersOwaPermissions')

View file

@ -1074,10 +1074,14 @@ namespace WebsitePanel.EnterpriseServer
} }
} }
private static void CheckNumericQuota(PackageContext cntx, List<string> errors, string quotaName, int currentVal, int val, string messageKey) private static void CheckNumericQuota(PackageContext cntx, List<string> errors, string quotaName, long currentVal, long val, string messageKey)
{ {
CheckQuotaValue(cntx, errors, quotaName, currentVal, val, messageKey); CheckQuotaValue(cntx, errors, quotaName, currentVal, val, messageKey);
} }
private static void CheckNumericQuota(PackageContext cntx, List<string> errors, string quotaName, int currentVal, int val, string messageKey)
{
CheckQuotaValue(cntx, errors, quotaName, Convert.ToInt64(currentVal), Convert.ToInt64(val), messageKey);
}
private static void CheckNumericQuota(PackageContext cntx, List<string> errors, string quotaName, int val, string messageKey) private static void CheckNumericQuota(PackageContext cntx, List<string> errors, string quotaName, int val, string messageKey)
{ {
@ -1094,7 +1098,7 @@ namespace WebsitePanel.EnterpriseServer
CheckQuotaValue(cntx, errors, quotaName, 0, -1, messageKey); CheckQuotaValue(cntx, errors, quotaName, 0, -1, messageKey);
} }
private static void CheckQuotaValue(PackageContext cntx, List<string> errors, string quotaName, int currentVal, int val, string messageKey) private static void CheckQuotaValue(PackageContext cntx, List<string> errors, string quotaName, long currentVal, long val, string messageKey)
{ {
if (!cntx.Quotas.ContainsKey(quotaName)) if (!cntx.Quotas.ContainsKey(quotaName))
return; return;
@ -1111,7 +1115,7 @@ namespace WebsitePanel.EnterpriseServer
errors.Add(messageKey); errors.Add(messageKey);
else if (quota.QuotaTypeId == 2) else if (quota.QuotaTypeId == 2)
{ {
int maxValue = quota.QuotaAllocatedValue - quota.QuotaUsedValue + currentVal; long maxValue = quota.QuotaAllocatedValue - quota.QuotaUsedValue + currentVal;
if(val > maxValue) if(val > maxValue)
errors.Add(messageKey + ":" + maxValue); errors.Add(messageKey + ":" + maxValue);
} }
@ -1795,7 +1799,8 @@ namespace WebsitePanel.EnterpriseServer
else if (state == VirtualMachineRequestedState.Reboot) else if (state == VirtualMachineRequestedState.Reboot)
{ {
// shutdown first // shutdown first
ResultObject shutdownResult = ChangeVirtualMachineState(itemId, VirtualMachineRequestedState.ShutDown); ResultObject shutdownResult = ChangeVirtualMachineState(itemId,
VirtualMachineRequestedState.ShutDown);
if (!shutdownResult.IsSuccess) if (!shutdownResult.IsSuccess)
{ {
TaskManager.CompleteResultTask(res); TaskManager.CompleteResultTask(res);
@ -1817,6 +1822,14 @@ namespace WebsitePanel.EnterpriseServer
JobResult result = vps.ChangeVirtualMachineState(machine.VirtualMachineId, state); JobResult result = vps.ChangeVirtualMachineState(machine.VirtualMachineId, state);
if (result.Job.JobState == ConcreteJobState.Completed)
{
LogReturnValueResult(res, result);
TaskManager.CompleteTask();
return res;
}
else
{
// check return // check return
if (result.ReturnValue != ReturnCode.JobStarted) if (result.ReturnValue != ReturnCode.JobStarted)
{ {
@ -1834,6 +1847,7 @@ namespace WebsitePanel.EnterpriseServer
} }
} }
} }
}
catch(Exception ex) catch(Exception ex)
{ {
res.IsSuccess = false; res.IsSuccess = false;

View file

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebsitePanel.Providers.Virtualization
{
public enum AutomaticStartAction
{
Undefined = 100,
Nothing = 0,
StartIfRunning = 1,
Start = 2,
}
}

View file

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebsitePanel.Providers.Virtualization
{
public enum AutomaticStopAction
{
Undefined = 100,
TurnOff = 0,
Save = 1,
ShutDown = 2,
}
}

View file

@ -0,0 +1,41 @@
// Copyright (c) 2014, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.Providers.Virtualization
{
public class BiosInfo
{
public bool NumLockEnabled { get; set; }
public string[] StartupOrder { get; set; }
public bool BootFromCD { get; set; }
}
}

View file

@ -42,6 +42,9 @@ namespace WebsitePanel.Providers.Virtualization
Completed = 7, Completed = 7,
Terminated = 8, Terminated = 8,
Killed = 9, Killed = 9,
Exception = 10 Exception = 10,
NotStarted = 11,
Failed = 12,
} }
} }

View file

@ -0,0 +1,40 @@
// Copyright (c) 2014, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.Providers.Virtualization
{
public enum ControllerType
{
IDE = 0,
SCSI = 1
}
}

View file

@ -0,0 +1,44 @@
// Copyright (c) 2014, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.Providers.Virtualization
{
public class DvdDriveInfo
{
public ControllerType ControllerType { get; set; }
public int ControllerNumber { get; set; }
public int ControllerLocation { get; set; }
public string Name { get; set; }
public string Id { get; set; }
public string Path { get; set; }
}
}

View file

@ -0,0 +1,44 @@
// Copyright (c) 2014, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.Providers.Virtualization
{
public class MemoryInfo
{
public bool DynamicMemoryEnabled { get; set; }
public Int64 Startup { get; set; }
public Int64 Minimum { get; set; }
public Int64 Maximum { get; set; }
public int Buffer { get; set; }
public int Priority { get; set; }
}
}

View file

@ -35,9 +35,10 @@ namespace WebsitePanel.Providers.Virtualization
public enum OperationalStatus public enum OperationalStatus
{ {
None = 0, None = 0,
OK = 2, Ok = 2,
Error = 6, Error = 6,
NoContact = 12, NoContact = 12,
LostCommunication = 13 LostCommunication = 13,
Paused = 15
} }
} }

View file

@ -0,0 +1,40 @@
// Copyright (c) 2014, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.Providers.Virtualization
{
public enum VirtualHardDiskFormat
{
VHD = 0,
VHDX = 1
}
}

View file

@ -40,5 +40,15 @@ namespace WebsitePanel.Providers.Virtualization
public long MaxInternalSize { get; set; } public long MaxInternalSize { get; set; }
public string ParentPath { get; set; } public string ParentPath { get; set; }
public VirtualHardDiskType DiskType { get; set; } public VirtualHardDiskType DiskType { get; set; }
public bool SupportPersistentReservations { get; set; }
public ulong MaximumIOPS { get; set; }
public ulong MinimumIOPS { get; set; }
public ControllerType VHDControllerType { get; set; }
public int ControllerNumber { get; set; }
public int ControllerLocation { get; set; }
public string Name { get; set; }
public string Path { get; set; }
public VirtualHardDiskFormat DiskFormat { get; set; }
public bool Attached { get; set; }
} }
} }

View file

@ -69,8 +69,8 @@ namespace WebsitePanel.Providers.Virtualization
public int CpuUsage { get; set; } public int CpuUsage { get; set; }
[Persistent] [Persistent]
public int RamSize { get; set; } public long RamSize { get; set; }
public int RamUsage { get; set; } public long RamUsage { get; set; }
[Persistent] [Persistent]
public int HddSize { get; set; } public int HddSize { get; set; }
public LogicalDisk[] HddLogicalDisks { get; set; } public LogicalDisk[] HddLogicalDisks { get; set; }
@ -123,5 +123,24 @@ namespace WebsitePanel.Providers.Virtualization
// for GetVirtualMachineEx used in import method // for GetVirtualMachineEx used in import method
public VirtualMachineNetworkAdapter[] Adapters { get; set; } public VirtualMachineNetworkAdapter[] Adapters { get; set; }
[Persistent]
public VirtualHardDiskInfo[] Disks { get; set; }
[Persistent]
public string Status { get; set; }
[Persistent]
public string ReplicationState { get; set; }
[Persistent]
public int Generation { get; set; }
[Persistent]
public int ProcessorCount { get; set; }
[Persistent]
public string ParentSnapshotId { get; set; }
} }
} }

View file

@ -36,5 +36,6 @@ namespace WebsitePanel.Providers.Virtualization
{ {
public string Name { get; set; } public string Name { get; set; }
public string MacAddress { get; set; } public string MacAddress { get; set; }
public string SwitchName { get; set; }
} }
} }

View file

@ -37,6 +37,7 @@ namespace WebsitePanel.Providers.Virtualization
public string Id { get; set; } public string Id { get; set; }
public string CheckPointId { get; set; } public string CheckPointId { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string VMName { get; set; }
public string ParentId { get; set; } public string ParentId { get; set; }
public DateTime Created { get; set; } public DateTime Created { get; set; }
public bool IsCurrent { get; set; } public bool IsCurrent { get; set; }

View file

@ -34,8 +34,9 @@ namespace WebsitePanel.Providers.Virtualization
{ {
public enum VirtualMachineState public enum VirtualMachineState
{ {
/*
Unknown = 0, Unknown = 0,
Started = 2, // start Running = 2, // start
Off = 3, // turn off Off = 3, // turn off
Reset = 10, // reset Reset = 10, // reset
Paused = 32768, // pause Paused = 32768, // pause
@ -47,5 +48,36 @@ namespace WebsitePanel.Providers.Virtualization
Stopping = 32774, Stopping = 32774,
Deleted = 32775, Deleted = 32775,
Pausing = 32776 Pausing = 32776
*/
Snapshotting = 32771,
Migrating = 32772,
Deleted = 32775,
Unknown = 0,
Other = 1,
Running = 2,
Off = 3,
Stopping = 32774, // new 4
Saved = 32769, // new 6
Paused = 32768, // new 9
Starting = 32770, // new 10
Reset = 10, // new 11
Saving = 32773, // new 32773
Pausing = 32776, // new 32776
Resuming = 32777,
FastSaved = 32779,
FastSaving = 32780,
RunningCritical = 32781,
OffCritical = 32782,
StoppingCritical = 32783,
SavedCritical = 32784,
PausedCritical = 32785,
StartingCritical = 32786,
ResetCritical = 32787,
SavingCritical = 32788,
PausingCritical = 32789,
ResumingCritical = 32790,
FastSavedCritical = 32791,
FastSavingCritical = 32792
} }
} }

View file

@ -37,5 +37,6 @@ namespace WebsitePanel.Providers.Virtualization
{ {
[Persistent] [Persistent]
public string SwitchId { get; set; } public string SwitchId { get; set; }
public string SwitchType { get; set; }
} }
} }

View file

@ -288,6 +288,9 @@
<Compile Include="Statistics\StatsServer.cs" /> <Compile Include="Statistics\StatsServer.cs" />
<Compile Include="Statistics\StatsSite.cs" /> <Compile Include="Statistics\StatsSite.cs" />
<Compile Include="Statistics\StatsUser.cs" /> <Compile Include="Statistics\StatsUser.cs" />
<Compile Include="Virtualization\AutomaticStopAction.cs" />
<Compile Include="Virtualization\AutomaticStartAction.cs" />
<Compile Include="Virtualization\BiosInfo.cs" />
<Compile Include="Virtualization\ChangeJobStateReturnCode.cs" /> <Compile Include="Virtualization\ChangeJobStateReturnCode.cs" />
<Compile Include="Virtualization\ConcreteJob.cs"> <Compile Include="Virtualization\ConcreteJob.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
@ -298,6 +301,7 @@
<Compile Include="Virtualization\ConcreteJobState.cs"> <Compile Include="Virtualization\ConcreteJobState.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Virtualization\ControllerType.cs" />
<Compile Include="Virtualization\IVirtualizationServer.cs"> <Compile Include="Virtualization\IVirtualizationServer.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
@ -308,6 +312,8 @@
<Compile Include="Virtualization\KvpExchangeDataItem.cs" /> <Compile Include="Virtualization\KvpExchangeDataItem.cs" />
<Compile Include="Virtualization\LibraryItem.cs" /> <Compile Include="Virtualization\LibraryItem.cs" />
<Compile Include="Virtualization\LogicalDisk.cs" /> <Compile Include="Virtualization\LogicalDisk.cs" />
<Compile Include="Virtualization\DvdDriveInfo.cs" />
<Compile Include="Virtualization\MemoryInfo.cs" />
<Compile Include="Virtualization\MonitoredObjectAlert.cs" /> <Compile Include="Virtualization\MonitoredObjectAlert.cs" />
<Compile Include="Virtualization\MonitoredObjectEvent.cs" /> <Compile Include="Virtualization\MonitoredObjectEvent.cs" />
<Compile Include="Virtualization\MountedDiskInfo.cs" /> <Compile Include="Virtualization\MountedDiskInfo.cs" />
@ -322,6 +328,7 @@
<Compile Include="Virtualization\ThumbnailSize.cs"> <Compile Include="Virtualization\ThumbnailSize.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Virtualization\VirtualHardDiskFormat.cs" />
<Compile Include="Virtualization\VirtualHardDiskInfo.cs" /> <Compile Include="Virtualization\VirtualHardDiskInfo.cs" />
<Compile Include="Virtualization\VirtualHardDiskType.cs" /> <Compile Include="Virtualization\VirtualHardDiskType.cs" />
<Compile Include="Virtualization\VirtualMachine.cs"> <Compile Include="Virtualization\VirtualMachine.cs">

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WebsitePanel.Providers.Virtualization
{
public static class Constants
{
public const Int64 Size1G = 0x40000000;
public const Int64 Size1M = 0x100000;
}
}

View file

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Management.Automation;
using System.Text;
using System.Threading.Tasks;
namespace WebsitePanel.Providers.Virtualization
{
static class PSObjectExtension
{
#region Properties
public static object GetProperty(this PSObject obj, string name)
{
return obj.Members[name].Value;
}
public static T GetProperty<T>(this PSObject obj, string name)
{
return (T)obj.Members[name].Value;
}
public static T GetEnum<T>(this PSObject obj, string name) where T : struct
{
return (T)Enum.Parse(typeof(T), GetProperty(obj, name).ToString());
}
public static int GetInt(this PSObject obj, string name)
{
return Convert.ToInt32(obj.Members[name].Value);
}
public static long GetLong(this PSObject obj, string name)
{
return Convert.ToInt64(obj.Members[name].Value);
}
public static string GetString(this PSObject obj, string name)
{
return obj.Members[name].Value == null ? "" : obj.Members[name].Value.ToString();
}
#endregion
#region Methods
public static ManagementObject Invoke(this PSObject obj, string name, object argument)
{
return obj.Invoke(name, new[] {argument});
}
public static ManagementObject Invoke(this PSObject obj, string name, params object[] arguments)
{
var results = (ManagementObjectCollection)obj.Methods[name].Invoke(arguments);
foreach (var result in results)
{
return (ManagementObject) result;
}
return null;
}
#endregion
}
}

View file

@ -0,0 +1,109 @@
using System;
using System.Collections;
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 BiosHelper
{
public static BiosInfo Get(PowerShellManager powerShell, string name, int generation)
{
BiosInfo info = new BiosInfo();
// for Win2012R2+ and Win8.1+
if (generation == 2)
{
Command cmd = new Command("Get-VMFirmware");
cmd.Parameters.Add("VMName", name);
Collection<PSObject> result = powerShell.Execute(cmd, false);
if (result != null && result.Count > 0)
{
info.NumLockEnabled = true;
List<string> startupOrders = new List<string>();
info.BootFromCD = false;
foreach (dynamic item in (IEnumerable)result[0].GetProperty("BootOrder"))
{
string bootType = item.BootType.ToString();
// bootFromCD
if (!startupOrders.Any() && bootType == "Drive")
{
var device = item.Device;
info.BootFromCD = device.GetType().Name == "DvdDrive";
}
// startupOrders
startupOrders.Add(bootType);
}
info.StartupOrder = startupOrders.ToArray();
}
}
// for others win and linux
else
{
Command cmd = new Command("Get-VMBios");
cmd.Parameters.Add("VMName", name);
Collection<PSObject> result = powerShell.Execute(cmd, false);
if (result != null && result.Count > 0)
{
info.NumLockEnabled = Convert.ToBoolean(result[0].GetProperty("NumLockEnabled"));
List<string> startupOrders = new List<string>();
foreach (var item in (IEnumerable)result[0].GetProperty("StartupOrder"))
startupOrders.Add(item.ToString());
info.StartupOrder = startupOrders.ToArray();
info.BootFromCD = false;
if (info.StartupOrder != null && info.StartupOrder.Length > 0)
info.BootFromCD = info.StartupOrder[0] == "CD";
}
}
return info;
}
public static void Update(PowerShellManager powerShell, VirtualMachine vm, bool bootFromCD, bool numLockEnabled)
{
// for Win2012R2+ and Win8.1+
if (vm.Generation == 2)
{
Command cmd = new Command("Set-VMFirmware");
cmd.Parameters.Add("VMName", vm.Name);
if (bootFromCD)
cmd.Parameters.Add("FirstBootDevice", DvdDriveHelper.GetPS(powerShell, vm.Name));
else
cmd.Parameters.Add("FirstBootDevice", HardDriveHelper.GetPS(powerShell, vm.Name).FirstOrDefault());
powerShell.Execute(cmd, false);
}
// for others win and linux
else
{
Command cmd = new Command("Set-VMBios");
cmd.Parameters.Add("VMName", vm.Name);
var bootOrder = bootFromCD
? new[] { "CD", "IDE", "LegacyNetworkAdapter", "Floppy" }
: new[] { "IDE", "CD", "LegacyNetworkAdapter", "Floppy" };
cmd.Parameters.Add("StartupOrder", bootOrder);
powerShell.Execute(cmd, false);
}
}
}
}

View file

@ -0,0 +1,93 @@
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 DvdDriveHelper
{
public static DvdDriveInfo Get(PowerShellManager powerShell, string vmName)
{
DvdDriveInfo info = null;
PSObject result = GetPS(powerShell, vmName);
if (result != null)
{
info = new DvdDriveInfo();
info.Id = result.GetString("Id");
info.Name = result.GetString("Name");
info.ControllerType = result.GetEnum<ControllerType>("ControllerType");
info.ControllerNumber = result.GetInt("ControllerNumber");
info.ControllerLocation = result.GetInt("ControllerLocation");
info.Path = result.GetString("Path");
}
return info;
}
public static PSObject GetPS(PowerShellManager powerShell, string vmName)
{
Command cmd = new Command("Get-VMDvdDrive");
cmd.Parameters.Add("VMName", vmName);
Collection<PSObject> result = powerShell.Execute(cmd, false);
if (result != null && result.Count > 0)
{
return result[0];
}
return null;
}
public static void Set(PowerShellManager powerShell, string vmName, string path)
{
var dvd = Get(powerShell, vmName);
Command cmd = new Command("Set-VMDvdDrive");
cmd.Parameters.Add("VMName", vmName);
cmd.Parameters.Add("Path", path);
cmd.Parameters.Add("ControllerNumber", dvd.ControllerNumber);
cmd.Parameters.Add("ControllerLocation", dvd.ControllerLocation);
powerShell.Execute(cmd, false);
}
public static void Update(PowerShellManager powerShell, VirtualMachine vm, bool dvdDriveShouldBeInstalled)
{
if (!vm.DvdDriveInstalled && dvdDriveShouldBeInstalled)
Add(powerShell, vm.Name);
else if (vm.DvdDriveInstalled && !dvdDriveShouldBeInstalled)
Remove(powerShell, vm.Name);
}
public static void Add(PowerShellManager powerShell, string vmName)
{
Command cmd = new Command("Add-VMDvdDrive");
cmd.Parameters.Add("VMName", vmName);
powerShell.Execute(cmd, false);
}
public static void Remove(PowerShellManager powerShell, string vmName)
{
var dvd = Get(powerShell, vmName);
Command cmd = new Command("Remove-VMDvdDrive");
cmd.Parameters.Add("VMName", vmName);
cmd.Parameters.Add("ControllerNumber", dvd.ControllerNumber);
cmd.Parameters.Add("ControllerLocation", dvd.ControllerLocation);
powerShell.Execute(cmd, false);
}
}
}

View file

@ -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"));
}
}
}
}
}

View file

@ -0,0 +1,74 @@
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 JobHelper
{
public static JobResult CreateSuccessResult(ReturnCode returnCode = ReturnCode.OK)
{
return new JobResult
{
Job = new ConcreteJob {JobState = ConcreteJobState.Completed},
ReturnValue = returnCode
};
}
public static JobResult CreateResultFromPSResults(Collection<PSObject> objJob)
{
if (objJob == null || objJob.Count == 0)
return null;
JobResult result = new JobResult();
result.Job = CreateFromPSObject(objJob);
result.ReturnValue = ReturnCode.JobStarted;
switch (result.Job.JobState)
{
case ConcreteJobState.Failed:
result.ReturnValue = ReturnCode.Failed;
break;
}
return result;
}
public static ConcreteJob CreateFromPSObject(Collection<PSObject> objJob)
{
if (objJob == null || objJob.Count == 0)
return null;
ConcreteJob job = new ConcreteJob();
job.Id = objJob[0].GetProperty<int>("Id").ToString();
job.JobState = objJob[0].GetEnum<ConcreteJobState>("JobStateInfo");
job.Caption = objJob[0].GetProperty<string>("Name");
job.Description = objJob[0].GetProperty<string>("Command");
job.StartTime = objJob[0].GetProperty<DateTime>("PSBeginTime");
job.ElapsedTime = objJob[0].GetProperty<DateTime?>("PSEndTime") ?? DateTime.Now;
// PercentComplete
job.PercentComplete = 0;
var progress = (PSDataCollection<ProgressRecord>)objJob[0].GetProperty("Progress");
if (progress != null && progress.Count > 0)
job.PercentComplete = progress[0].PercentComplete;
// Errors
var errors = (PSDataCollection<ErrorRecord>)objJob[0].GetProperty("Error");
if (errors != null && errors.Count > 0)
{
job.ErrorDescription = errors[0].ErrorDetails.Message + ". " + errors[0].ErrorDetails.RecommendedAction;
job.ErrorCode = errors[0].Exception != null ? -1 : 0;
}
return job;
}
}
}

View file

@ -0,0 +1,109 @@
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 NetworkAdapterHelper
{
#region Constants
private const string EXTERNAL_NETWORK_ADAPTER_NAME = "External Network Adapter";
private const string PRIVATE_NETWORK_ADAPTER_NAME = "Private Network Adapter";
private const string MANAGEMENT_NETWORK_ADAPTER_NAME = "Management Network Adapter";
#endregion
public static VirtualMachineNetworkAdapter[] Get(PowerShellManager powerShell, string vmName)
{
List<VirtualMachineNetworkAdapter> adapters = new List<VirtualMachineNetworkAdapter>();
Command cmd = new Command("Get-VMNetworkAdapter");
if (!string.IsNullOrEmpty(vmName)) cmd.Parameters.Add("VMName", vmName);
Collection<PSObject> result = powerShell.Execute(cmd, false);
if (result != null && result.Count > 0)
{
foreach (PSObject psAdapter in result)
{
VirtualMachineNetworkAdapter adapter = new VirtualMachineNetworkAdapter();
adapter.Name = psAdapter.GetString("Name");
adapter.MacAddress = psAdapter.GetString("MacAddress");
adapter.SwitchName = psAdapter.GetString("SwitchName");
adapters.Add(adapter);
}
}
return adapters.ToArray();
}
public static VirtualMachineNetworkAdapter Get(PowerShellManager powerShell, string vmName, string macAddress)
{
var adapters = Get(powerShell, vmName);
return adapters.FirstOrDefault(a => a.MacAddress == macAddress);
}
public static void Update(PowerShellManager powerShell, VirtualMachine vm)
{
// External NIC
if (!vm.ExternalNetworkEnabled && !String.IsNullOrEmpty(vm.ExternalNicMacAddress))
{
Delete(powerShell, vm.Name, vm.ExternalNicMacAddress);
vm.ExternalNicMacAddress = null; // reset MAC
}
else if (vm.ExternalNetworkEnabled && !String.IsNullOrEmpty(vm.ExternalNicMacAddress)
&& Get(powerShell,vm.Name,vm.ExternalNicMacAddress) == null)
{
Add(powerShell, vm.Name, vm.ExternalSwitchId, vm.ExternalNicMacAddress, EXTERNAL_NETWORK_ADAPTER_NAME, vm.LegacyNetworkAdapter);
}
// Private NIC
if (!vm.PrivateNetworkEnabled && !String.IsNullOrEmpty(vm.PrivateNicMacAddress))
{
Delete(powerShell, vm.Name, vm.PrivateNicMacAddress);
vm.PrivateNicMacAddress = null; // reset MAC
}
else if (vm.PrivateNetworkEnabled && !String.IsNullOrEmpty(vm.PrivateNicMacAddress)
&& Get(powerShell, vm.Name, vm.PrivateNicMacAddress) == null)
{
Add(powerShell, vm.Name, vm.PrivateSwitchId, vm.PrivateNicMacAddress, PRIVATE_NETWORK_ADAPTER_NAME, vm.LegacyNetworkAdapter);
}
}
public static void Add(PowerShellManager powerShell, string vmName, string switchId, string macAddress, string adapterName, bool legacyAdapter)
{
Command cmd = new Command("Add-VMNetworkAdapter");
cmd.Parameters.Add("VMName", vmName);
cmd.Parameters.Add("Name", adapterName);
cmd.Parameters.Add("SwitchName", switchId);
if (String.IsNullOrEmpty(macAddress))
cmd.Parameters.Add("DynamicMacAddress");
else
cmd.Parameters.Add("StaticMacAddress", macAddress);
powerShell.Execute(cmd, false);
}
public static void Delete(PowerShellManager powerShell, string vmName, string macAddress)
{
var networkAdapter = Get(powerShell, vmName, macAddress);
if (networkAdapter == null)
return;
Command cmd = new Command("Remove-VMNetworkAdapter");
cmd.Parameters.Add("VMName", vmName);
cmd.Parameters.Add("Name", networkAdapter.Name);
powerShell.Execute(cmd, false);
}
}
}

View file

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Text;
using System.Threading.Tasks;
namespace WebsitePanel.Providers.Virtualization
{
public static class SnapshotHelper
{
public static VirtualMachineSnapshot GetFromPS(PSObject psObject, string runningSnapshotId = null)
{
var snapshot = new VirtualMachineSnapshot
{
Id = psObject.GetString("Id"),
Name = psObject.GetString("Name"),
VMName = psObject.GetString("VMName"),
ParentId = psObject.GetString("ParentSnapshotId"),
Created = psObject.GetProperty<DateTime>("CreationTime")
};
if (string.IsNullOrEmpty(snapshot.ParentId))
snapshot.ParentId = null; // for capability
if (!String.IsNullOrEmpty(runningSnapshotId))
snapshot.IsCurrent = snapshot.Id == runningSnapshotId;
return snapshot;
}
public static VirtualMachineSnapshot GetFromWmi(ManagementBaseObject objSnapshot)
{
if (objSnapshot == null || objSnapshot.Properties.Count == 0)
return null;
VirtualMachineSnapshot snapshot = new VirtualMachineSnapshot();
snapshot.Id = (string)objSnapshot["InstanceID"];
snapshot.Name = (string)objSnapshot["ElementName"];
string parentId = (string)objSnapshot["Parent"];
if (!String.IsNullOrEmpty(parentId))
{
int idx = parentId.IndexOf("Microsoft:");
snapshot.ParentId = parentId.Substring(idx, parentId.Length - idx - 1);
snapshot.ParentId = snapshot.ParentId.ToLower().Replace("microsoft:", "");
}
if (!String.IsNullOrEmpty(snapshot.Id))
{
snapshot.Id = snapshot.Id.ToLower().Replace("microsoft:", "");
}
snapshot.Created = Wmi.ToDateTime((string)objSnapshot["CreationTime"]);
if (string.IsNullOrEmpty(snapshot.ParentId))
snapshot.ParentId = null; // for capability
return snapshot;
}
public static void Delete(PowerShellManager powerShell, VirtualMachineSnapshot snapshot, bool includeChilds)
{
Command cmd = new Command("Remove-VMSnapshot");
cmd.Parameters.Add("VMName", snapshot.VMName);
cmd.Parameters.Add("Name", snapshot.Name);
if (includeChilds) cmd.Parameters.Add("IncludeAllChildSnapshots", true);
powerShell.Execute(cmd, false);
}
}
}

View file

@ -0,0 +1,97 @@
using System;
using System.Collections;
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 VirtualMachineHelper
{
public static OperationalStatus GetVMHeartBeatStatus(PowerShellManager powerShell, string name)
{
OperationalStatus status = OperationalStatus.None;
Command cmd = new Command("Get-VMIntegrationService");
cmd.Parameters.Add("VMName", name);
cmd.Parameters.Add("Name", "HeartBeat");
Collection<PSObject> result = powerShell.Execute(cmd, false);
if (result != null && result.Count > 0)
{
var statusString = result[0].GetProperty("PrimaryOperationalStatus");
if (statusString != null)
status = (OperationalStatus)Enum.Parse(typeof(OperationalStatus), statusString.ToString());
}
return status;
}
public static int GetVMProcessors(PowerShellManager powerShell, string name)
{
int procs = 0;
Command cmd = new Command("Get-VMProcessor");
cmd.Parameters.Add("VMName", name);
Collection<PSObject> result = powerShell.Execute(cmd, false);
if (result != null && result.Count > 0)
{
procs = Convert.ToInt32(result[0].GetProperty("Count"));
}
return procs;
}
public static MemoryInfo GetVMMemory(PowerShellManager powerShell, string name)
{
MemoryInfo info = new MemoryInfo();
Command cmd = new Command("Get-VMMemory");
cmd.Parameters.Add("VMName", name);
Collection<PSObject> result = powerShell.Execute(cmd, false);
if (result != null && result.Count > 0)
{
info.DynamicMemoryEnabled = Convert.ToBoolean(result[0].GetProperty("DynamicMemoryEnabled"));
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 void UpdateProcessors(PowerShellManager powerShell, VirtualMachine vm, int cpuCores, int cpuLimitSettings, int cpuReserveSettings, int cpuWeightSettings)
{
Command cmd = new Command("Set-VMProcessor");
cmd.Parameters.Add("VMName", vm.Name);
cmd.Parameters.Add("Count", cpuCores);
cmd.Parameters.Add("Maximum", Convert.ToInt64(cpuLimitSettings * 1000));
cmd.Parameters.Add("Reserve", Convert.ToInt64(cpuReserveSettings * 1000));
cmd.Parameters.Add("RelativeWeight", cpuWeightSettings);
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 * Constants.Size1M);
powerShell.Execute(cmd, false);
}
}
}

View file

@ -0,0 +1,159 @@
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;
using WebsitePanel.Providers.HostedSolution;
namespace WebsitePanel.Providers.Virtualization
{
public class PowerShellManager : IDisposable
{
protected static InitialSessionState session = null;
protected Runspace RunSpace { get; set; }
public PowerShellManager()
{
OpenRunspace();
}
protected void OpenRunspace()
{
HostedSolutionLog.LogStart("OpenRunspace");
if (session == null)
{
session = InitialSessionState.CreateDefault();
session.ImportPSModule(new[] {"Hyper-V"});
}
Runspace runSpace = RunspaceFactory.CreateRunspace(session);
runSpace.Open();
runSpace.SessionStateProxy.SetVariable("ConfirmPreference", "none");
RunSpace = runSpace;
HostedSolutionLog.LogEnd("OpenRunspace");
}
public void Dispose()
{
try
{
if (RunSpace != null && RunSpace.RunspaceStateInfo.State == RunspaceState.Opened)
{
RunSpace.Close();
RunSpace = null;
}
}
catch (Exception ex)
{
HostedSolutionLog.LogError("Runspace error", ex);
}
}
public Collection<PSObject> Execute(Command cmd)
{
return Execute(cmd, true);
}
public Collection<PSObject> Execute(Command cmd, bool useDomainController)
{
object[] errors;
return Execute(cmd, useDomainController, out errors);
}
public Collection<PSObject> Execute(Command cmd, out object[] errors)
{
return Execute(cmd, true, out errors);
}
public Collection<PSObject> Execute(Command cmd, bool useDomainController, out object[] errors)
{
HostedSolutionLog.LogStart("Execute");
List<object> errorList = new List<object>();
HostedSolutionLog.DebugCommand(cmd);
Collection<PSObject> results = null;
// Create a pipeline
Pipeline pipeLine = RunSpace.CreatePipeline();
using (pipeLine)
{
// Add the command
pipeLine.Commands.Add(cmd);
// Execute the pipeline and save the objects returned.
results = pipeLine.Invoke();
// Log out any errors in the pipeline execution
// NOTE: These errors are NOT thrown as exceptions!
// Be sure to check this to ensure that no errors
// happened while executing the command.
if (pipeLine.Error != null && pipeLine.Error.Count > 0)
{
foreach (object item in pipeLine.Error.ReadToEnd())
{
errorList.Add(item);
string errorMessage = string.Format("Invoke error: {0}", item);
HostedSolutionLog.LogWarning(errorMessage);
}
}
}
pipeLine = null;
errors = errorList.ToArray();
HostedSolutionLog.LogEnd("Execute");
return results;
}
/// <summary>
/// Returns the identity of the object from the shell execution result
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
public static string GetResultObjectIdentity(Collection<PSObject> result)
{
HostedSolutionLog.LogStart("GetResultObjectIdentity");
if (result == null)
throw new ArgumentNullException("result", "Execution result is not specified");
if (result.Count < 1)
throw new ArgumentException("Execution result is empty", "result");
if (result.Count > 1)
throw new ArgumentException("Execution result contains more than one object", "result");
PSMemberInfo info = result[0].Members["Identity"];
if (info == null)
throw new ArgumentException("Execution result does not contain Identity property", "result");
string ret = info.Value.ToString();
HostedSolutionLog.LogEnd("GetResultObjectIdentity");
return ret;
}
public static string GetResultObjectDN(Collection<PSObject> result)
{
HostedSolutionLog.LogStart("GetResultObjectDN");
if (result == null)
throw new ArgumentNullException("result", "Execution result is not specified");
if (result.Count < 1)
throw new ArgumentException("Execution result does not contain any object");
if (result.Count > 1)
throw new ArgumentException("Execution result contains more than one object");
PSMemberInfo info = result[0].Members["DistinguishedName"];
if (info == null)
throw new ArgumentException("Execution result does not contain DistinguishedName property", "result");
string ret = info.Value.ToString();
HostedSolutionLog.LogEnd("GetResultObjectDN");
return ret;
}
}
}

View file

@ -0,0 +1,21 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WebsitePanel.Providers.Virtualization.HyperV2012R2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("WebsitePanel.Providers.Virtualization.HyperV2012R2")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("959c2614-2d69-4e4f-9e77-bd868e5afd4b")]

View file

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EE40516B-93DF-4CAB-80C4-64DCE0B751CC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WebsitePanel.Providers.Virtualization.HyperV2012R2</RootNamespace>
<AssemblyName>WebsitePanel.Providers.Virtualization.HyperV2012R2</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\WebsitePanel.Server\bin\HyperV2012R2\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Storage.Vds">
<HintPath>..\..\Lib\References\Microsoft\Microsoft.Storage.Vds.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\References\Microsoft\Windows2012\System.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\VersionInfo.cs">
<Link>VersionInfo.cs</Link>
</Compile>
<Compile Include="Constants.cs" />
<Compile Include="Extensions\PSObjectExtension.cs" />
<Compile Include="Helpers\BiosHelper.cs" />
<Compile Include="Helpers\HardDriveHelper.cs" />
<Compile Include="Helpers\NetworkAdapterHelper.cs" />
<Compile Include="Helpers\DvdDriveHelper.cs" />
<Compile Include="Helpers\JobHelper.cs" />
<Compile Include="Helpers\SnapshotHelper.cs" />
<Compile Include="PowerShellManager.cs" />
<Compile Include="HyperV2012R2.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helpers\VirtualMachineHelper.cs" />
<Compile Include="Wmi.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WebsitePanel.Providers.Base\WebsitePanel.Providers.Base.csproj">
<Project>{684c932a-6c75-46ac-a327-f3689d89eb42}</Project>
<Name>WebsitePanel.Providers.Base</Name>
</ProjectReference>
<ProjectReference Include="..\WebsitePanel.Providers.HostedSolution\WebsitePanel.Providers.HostedSolution.csproj">
<Project>{a06de5e4-4331-47e1-8f46-7b846146b559}</Project>
<Name>WebsitePanel.Providers.HostedSolution</Name>
</ProjectReference>
<ProjectReference Include="..\WebsitePanel.Server.Utils\WebsitePanel.Server.Utils.csproj">
<Project>{e91e52f3-9555-4d00-b577-2b1dbdd87ca7}</Project>
<Name>WebsitePanel.Server.Utils</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -0,0 +1,295 @@
// Copyright (c) 2014, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.Diagnostics;
namespace WebsitePanel.Providers.Virtualization
{
internal class Wmi
{
string nameSpace = null;
string computerName = null;
ManagementScope scope = null;
public Wmi(string nameSpace) : this(nameSpace, null)
{
}
public Wmi(string computerName, string nameSpace)
{
this.nameSpace = nameSpace;
this.computerName = computerName;
}
internal ManagementObjectCollection ExecuteWmiQuery(string query, params object[] args)
{
if (args != null && args.Length > 0)
query = String.Format(query, args);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(GetScope(),
new ObjectQuery(query));
return searcher.Get();
}
internal ManagementObject GetWmiObject(string className, string filter, params object[] args)
{
ManagementObjectCollection col = GetWmiObjects(className, filter, args);
ManagementObjectCollection.ManagementObjectEnumerator enumerator = col.GetEnumerator();
return enumerator.MoveNext() ? (ManagementObject)enumerator.Current : null;
}
internal ManagementObject GetWmiObject(string className)
{
return GetWmiObject(className, null);
}
internal ManagementObjectCollection GetWmiObjects(string className, string filter, params object[] args)
{
string query = "select * from " + className;
if (!String.IsNullOrEmpty(filter))
query += " where " + filter;
return ExecuteWmiQuery(query, args);
}
internal ManagementObjectCollection GetWmiObjects(string className)
{
return GetWmiObjects(className, null);
}
internal ManagementObject GetWmiObjectByPath(string path)
{
return new ManagementObject(GetScope(), new ManagementPath(path), null);
}
internal ManagementClass GetWmiClass(string className)
{
return new ManagementClass(GetScope(), new ManagementPath(className), null);
}
internal ManagementObject GetRelatedWmiObject(ManagementObject obj, string className)
{
ManagementObjectCollection col = obj.GetRelated(className);
ManagementObjectCollection.ManagementObjectEnumerator enumerator = col.GetEnumerator();
enumerator.MoveNext();
return (ManagementObject)enumerator.Current;
}
internal void Dump(ManagementBaseObject obj)
{
#if DEBUG
foreach (PropertyData prop in obj.Properties)
{
string typeName = prop.Value == null ? "null" : prop.Value.GetType().ToString();
Debug.WriteLine(prop.Name + ": " + prop.Value + " (" + typeName + ")");
}
#endif
}
// Converts a given datetime in DMTF format to System.DateTime object.
internal static System.DateTime ToDateTime(string dmtfDate)
{
System.DateTime initializer = System.DateTime.MinValue;
int year = initializer.Year;
int month = initializer.Month;
int day = initializer.Day;
int hour = initializer.Hour;
int minute = initializer.Minute;
int second = initializer.Second;
long ticks = 0;
string dmtf = dmtfDate;
System.DateTime datetime = System.DateTime.MinValue;
string tempString = string.Empty;
if (String.IsNullOrEmpty(dmtf))
{
return DateTime.MinValue;
}
else if ((dmtf.Length != 25))
{
throw new System.ArgumentOutOfRangeException();
}
try
{
tempString = dmtf.Substring(0, 4);
if (("****" != tempString))
{
year = int.Parse(tempString);
}
tempString = dmtf.Substring(4, 2);
if (("**" != tempString))
{
month = int.Parse(tempString);
}
tempString = dmtf.Substring(6, 2);
if (("**" != tempString))
{
day = int.Parse(tempString);
}
tempString = dmtf.Substring(8, 2);
if (("**" != tempString))
{
hour = int.Parse(tempString);
}
tempString = dmtf.Substring(10, 2);
if (("**" != tempString))
{
minute = int.Parse(tempString);
}
tempString = dmtf.Substring(12, 2);
if (("**" != tempString))
{
second = int.Parse(tempString);
}
tempString = dmtf.Substring(15, 6);
if (("******" != tempString))
{
ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000))));
}
if (((((((((year < 0)
|| (month < 0))
|| (day < 0))
|| (hour < 0))
|| (minute < 0))
|| (minute < 0))
|| (second < 0))
|| (ticks < 0)))
{
throw new System.ArgumentOutOfRangeException();
}
}
catch (System.Exception e)
{
throw new System.ArgumentOutOfRangeException(null, e.Message);
}
if (year == 0
&& month == 0
&& day == 0
&& hour == 0
&& minute == 0
&& second == 0
&& ticks == 0)
return DateTime.MinValue;
datetime = new System.DateTime(year, month, day, hour, minute, second, 0);
datetime = datetime.AddTicks(ticks);
System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime);
int UTCOffset = 0;
int OffsetToBeAdjusted = 0;
long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute)));
tempString = dmtf.Substring(22, 3);
if ((tempString != "******"))
{
tempString = dmtf.Substring(21, 4);
try
{
UTCOffset = int.Parse(tempString);
}
catch (System.Exception e)
{
throw new System.ArgumentOutOfRangeException(null, e.Message);
}
OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset)));
datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted)));
}
return datetime;
}
// Converts a given System.DateTime object to DMTF datetime format.
internal string ToDmtfDateTime(System.DateTime date)
{
string utcString = string.Empty;
System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date);
long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute)));
if ((System.Math.Abs(OffsetMins) > 999))
{
date = date.ToUniversalTime();
utcString = "+000";
}
else
{
if ((tickOffset.Ticks >= 0))
{
utcString = string.Concat("+", ((System.Int64)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0'));
}
else
{
string strTemp = ((System.Int64)(OffsetMins)).ToString();
utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0'));
}
}
string dmtfDateTime = ((System.Int32)(date.Year)).ToString().PadLeft(4, '0');
dmtfDateTime = string.Concat(dmtfDateTime, ((System.Int32)(date.Month)).ToString().PadLeft(2, '0'));
dmtfDateTime = string.Concat(dmtfDateTime, ((System.Int32)(date.Day)).ToString().PadLeft(2, '0'));
dmtfDateTime = string.Concat(dmtfDateTime, ((System.Int32)(date.Hour)).ToString().PadLeft(2, '0'));
dmtfDateTime = string.Concat(dmtfDateTime, ((System.Int32)(date.Minute)).ToString().PadLeft(2, '0'));
dmtfDateTime = string.Concat(dmtfDateTime, ((System.Int32)(date.Second)).ToString().PadLeft(2, '0'));
dmtfDateTime = string.Concat(dmtfDateTime, ".");
System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0);
long microsec = ((long)((((date.Ticks - dtTemp.Ticks)
* 1000)
/ System.TimeSpan.TicksPerMillisecond)));
string strMicrosec = ((System.Int64)(microsec)).ToString();
if ((strMicrosec.Length > 6))
{
strMicrosec = strMicrosec.Substring(0, 6);
}
dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0'));
dmtfDateTime = string.Concat(dmtfDateTime, utcString);
return dmtfDateTime;
}
public ManagementScope GetScope()
{
if (scope != null)
return scope;
// create new scope
if (String.IsNullOrEmpty(computerName))
{
// local
scope = new ManagementScope(nameSpace);
}
else
{
// remote
ConnectionOptions options = new ConnectionOptions();
string path = String.Format(@"\\{0}\{1}", computerName, nameSpace);
scope = new ManagementScope(path, options);
}
// connect
scope.Connect();
return scope;
}
}
}

View file

@ -488,7 +488,7 @@ namespace WebsitePanel.Providers.Virtualization
return vm; return vm;
} }
private void UpdateVirtualMachineGeneralSettings(string vmId, ManagementObject objVM, int cpuCores, int ramMB, bool bootFromCD, bool numLockEnabled) private void UpdateVirtualMachineGeneralSettings(string vmId, ManagementObject objVM, int cpuCores, long ramMB, bool bootFromCD, bool numLockEnabled)
{ {
// request management service // request management service
ManagementObject objVmsvc = GetVirtualSystemManagementService(); ManagementObject objVmsvc = GetVirtualSystemManagementService();
@ -1989,10 +1989,10 @@ exit", Convert.ToInt32(objDisk["Index"])));
#region Stop #region Stop
else if (!started && else if (!started &&
(vps.State == VirtualMachineState.Started (vps.State == VirtualMachineState.Running
|| vps.State == VirtualMachineState.Paused)) || vps.State == VirtualMachineState.Paused))
{ {
if (vps.State == VirtualMachineState.Started) if (vps.State == VirtualMachineState.Running)
{ {
// try to shutdown the system // try to shutdown the system
ReturnCode code = ShutDownVirtualMachine(vm.VirtualMachineId, true, "Virtual Machine has been suspended from WebsitePanel"); ReturnCode code = ShutDownVirtualMachine(vm.VirtualMachineId, true, "Virtual Machine has been suspended from WebsitePanel");

View file

@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013 # Visual Studio 2013
VisualStudioVersion = 12.0.40121.0 VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Caching Application Block", "Caching Application Block", "{C8E6F2E4-A5B8-486A-A56E-92D864524682}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Caching Application Block", "Caching Application Block", "{C8E6F2E4-A5B8-486A-A56E-92D864524682}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
@ -154,7 +154,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebsitePanel.Providers.Host
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebsitePanel.Providers.Mail.IceWarp", "WebsitePanel.Providers.Mail.IceWarp\WebsitePanel.Providers.Mail.IceWarp.csproj", "{95EA2D6E-278C-4A74-97DB-946362C4DEEA}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebsitePanel.Providers.Mail.IceWarp", "WebsitePanel.Providers.Mail.IceWarp\WebsitePanel.Providers.Mail.IceWarp.csproj", "{95EA2D6E-278C-4A74-97DB-946362C4DEEA}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebsitePanel.Providers.HostedSolution.Crm2015", "WebsitePanel.Providers.HostedSolution.Crm2015\WebsitePanel.Providers.HostedSolution.Crm2015.csproj", "{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebsitePanel.Providers.Virtualization.HyperV2012R2", "WebsitePanel.Providers.Virtualization.HyperV-2012R2\WebsitePanel.Providers.Virtualization.HyperV2012R2.csproj", "{EE40516B-93DF-4CAB-80C4-64DCE0B751CC}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -776,16 +776,16 @@ Global
{95EA2D6E-278C-4A74-97DB-946362C4DEEA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {95EA2D6E-278C-4A74-97DB-946362C4DEEA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{95EA2D6E-278C-4A74-97DB-946362C4DEEA}.Release|Mixed Platforms.Build.0 = Release|Any CPU {95EA2D6E-278C-4A74-97DB-946362C4DEEA}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{95EA2D6E-278C-4A74-97DB-946362C4DEEA}.Release|x86.ActiveCfg = Release|Any CPU {95EA2D6E-278C-4A74-97DB-946362C4DEEA}.Release|x86.ActiveCfg = Release|Any CPU
{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EE40516B-93DF-4CAB-80C4-64DCE0B751CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}.Debug|Any CPU.Build.0 = Debug|Any CPU {EE40516B-93DF-4CAB-80C4-64DCE0B751CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {EE40516B-93DF-4CAB-80C4-64DCE0B751CC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {EE40516B-93DF-4CAB-80C4-64DCE0B751CC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}.Debug|x86.ActiveCfg = Debug|Any CPU {EE40516B-93DF-4CAB-80C4-64DCE0B751CC}.Debug|x86.ActiveCfg = Debug|Any CPU
{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}.Release|Any CPU.ActiveCfg = Release|Any CPU {EE40516B-93DF-4CAB-80C4-64DCE0B751CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}.Release|Any CPU.Build.0 = Release|Any CPU {EE40516B-93DF-4CAB-80C4-64DCE0B751CC}.Release|Any CPU.Build.0 = Release|Any CPU
{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {EE40516B-93DF-4CAB-80C4-64DCE0B751CC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}.Release|Mixed Platforms.Build.0 = Release|Any CPU {EE40516B-93DF-4CAB-80C4-64DCE0B751CC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{96EC3A56-5598-4B2D-A1F2-2E0DB6BA2AB6}.Release|x86.ActiveCfg = Release|Any CPU {EE40516B-93DF-4CAB-80C4-64DCE0B751CC}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View file

@ -1,4 +1,4 @@
<?xml version="1.0"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<!-- Custom configuration sections --> <!-- Custom configuration sections -->
<configSections> <configSections>
@ -162,7 +162,7 @@
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin/Crm2011;bin/Crm2013;bin/Exchange2013;bin/Sharepoint2013;bin/Lync2013;bin/Lync2013HP;bin/Dns2012;bin/IceWarp;bin/IIs80;bin/Crm2015"/> <probing privatePath="bin/Crm2011;bin/Crm2013;bin/Exchange2013;bin/Sharepoint2013;bin/Lync2013;bin/Lync2013HP;bin/Dns2012;bin/IceWarp;bin/IIs80;bin/HyperV2012R2" />
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
</configuration> </configuration>

View file

@ -54,9 +54,9 @@ legend {font-weight:700; color:#428bca; padding:0 4px;}
legend span.NormalBold {display:inline;} legend span.NormalBold {display:inline;}
.Tabs {width:100%;} .Tabs {width:100%;}
.Separator {display:none;} .Separator {display:none;}
.Tabs span {display:table; table-layout:fixed; width:100%; table-layout:fixed;} .Tabs span {display:table; table-layout:fixed; min-width:100%; table-layout:fixed;}
.Tabs span span {display:table-cell; width:15%; text-align:center; padding:0;} .Tabs span span {display:table-cell; width:15%; text-align:center; padding:0;}
.Tabs a {display:block; padding:10px 0; text-decoration:none; border-bottom:1px solid #ddd;} .Tabs a {display:block; padding:10px 5px; text-decoration:none; border-bottom:1px solid #ddd;}
.Tabs a:Hover {background:#eee; text-decoration:none;} .Tabs a:Hover {background:#eee; text-decoration:none;}
.Tabs a.ActiveTab {border:1px solid #ddd; border-bottom:none; color:#555; margin-bottom:-1px;} .Tabs a.ActiveTab {border:1px solid #ddd; border-bottom:none; color:#555; margin-bottom:-1px;}
.Tabs a.ActiveTab:hover {background:none;} .Tabs a.ActiveTab:hover {background:none;}

View file

@ -56,15 +56,15 @@ namespace WebsitePanel.Portal
set { ViewState["DisplayText"] = value; } set { ViewState["DisplayText"] = value; }
} }
public int Progress public long Progress
{ {
get { return (ViewState["Progress"] != null) ? (int)ViewState["Progress"] : 0; } get { return (ViewState["Progress"] != null) ? (long)ViewState["Progress"] : 0; }
set { ViewState["Progress"] = value; } set { ViewState["Progress"] = value; }
} }
public int Total public long Total
{ {
get { return (ViewState["Total"] != null) ? (int)ViewState["Total"] : 0; } get { return (ViewState["Total"] != null) ? (long)ViewState["Total"] : 0; }
set { ViewState["Total"] = value; } set { ViewState["Total"] = value; }
} }
@ -101,7 +101,7 @@ namespace WebsitePanel.Portal
string bkgSrc = Page.ResolveUrl(PortalUtils.GetThemedImage("gauge_bkg.gif")); string bkgSrc = Page.ResolveUrl(PortalUtils.GetThemedImage("gauge_bkg.gif"));
// calculate the width of the gauge // calculate the width of the gauge
int fTotal = Total; long fTotal = Total;
int percent = (fTotal > 0) ? Convert.ToInt32(Math.Round((double)Progress / (double)fTotal * 100)) : 0; int percent = (fTotal > 0) ? Convert.ToInt32(Math.Round((double)Progress / (double)fTotal * 100)) : 0;
double fFilledWidth = (fTotal > 0) ? ((double)Progress / (double)fTotal * Width) : 0; double fFilledWidth = (fTotal > 0) ? ((double)Progress / (double)fTotal * Width) : 0;

View file

@ -92,7 +92,7 @@ namespace WebsitePanel.Portal
private void UpdateControl() private void UpdateControl()
{ {
int total = gauge.Total; long total = gauge.Total;
if (QuotaTypeId == 1) if (QuotaTypeId == 1)
{ {
litValue.Text = (total == 0) ? GetLocalizedString("Text.Disabled") : GetLocalizedString("Text.Enabled"); litValue.Text = (total == 0) ? GetLocalizedString("Text.Disabled") : GetLocalizedString("Text.Enabled");

View file

@ -211,18 +211,24 @@ namespace WebsitePanel.Portal.UserControls
private void ShowActionList() private void ShowActionList()
{ {
var checkboxColumn = gvItems.Columns[0];
websiteActions.Visible = false; websiteActions.Visible = false;
mailActions.Visible = false; mailActions.Visible = false;
checkboxColumn.Visible = false;
switch (QuotaName) switch (QuotaName)
{ {
case "Web.Sites": case "Web.Sites":
websiteActions.Visible = true; websiteActions.Visible = true;
checkboxColumn.Visible = true;
break; break;
case "Mail.Accounts": case "Mail.Accounts":
ProviderInfo provider = ES.Services.Servers.GetPackageServiceProvider(PanelSecurity.PackageId, "Mail"); ProviderInfo provider = ES.Services.Servers.GetPackageServiceProvider(PanelSecurity.PackageId, "Mail");
if (provider.EditorControl == "SmarterMail100") if (provider.EditorControl == "SmarterMail100")
{
mailActions.Visible = true; mailActions.Visible = true;
checkboxColumn.Visible = true;
}
break; break;
} }
} }

View file

@ -213,6 +213,9 @@
<data name="Heartbeat.OK" xml:space="preserve"> <data name="Heartbeat.OK" xml:space="preserve">
<value>OK</value> <value>OK</value>
</data> </data>
<data name="Heartbeat.Paused" xml:space="preserve">
<value>Paused</value>
</data>
<data name="locChangeHostname.Text" xml:space="preserve"> <data name="locChangeHostname.Text" xml:space="preserve">
<value>Change VPS Host Name</value> <value>Change VPS Host Name</value>
</data> </data>
@ -273,6 +276,9 @@
<data name="State.Starting" xml:space="preserve"> <data name="State.Starting" xml:space="preserve">
<value>Starting</value> <value>Starting</value>
</data> </data>
<data name="State.Running" xml:space="preserve">
<value>Running</value>
</data>
<data name="State.Stopping" xml:space="preserve"> <data name="State.Stopping" xml:space="preserve">
<value>Stopping</value> <value>Stopping</value>
</data> </data>

View file

@ -98,9 +98,9 @@ namespace WebsitePanel.Portal.VPS
TimeSpan uptime = TimeSpan.FromMilliseconds(vm.Uptime); TimeSpan uptime = TimeSpan.FromMilliseconds(vm.Uptime);
uptime = uptime.Subtract(TimeSpan.FromMilliseconds(uptime.Milliseconds)); uptime = uptime.Subtract(TimeSpan.FromMilliseconds(uptime.Milliseconds));
litUptime.Text = uptime.ToString(); litUptime.Text = uptime.ToString();
litStatus.Text = GetLocalizedString("State." + vm.State.ToString()); litStatus.Text = GetLocalizedString("State." + vm.State);
litCreated.Text = vm.CreatedDate.ToString(); litCreated.Text = vm.CreatedDate.ToString();
litHeartbeat.Text = GetLocalizedString("Heartbeat." + vm.Heartbeat.ToString()); litHeartbeat.Text = GetLocalizedString("Heartbeat." + vm.Heartbeat);
// CPU // CPU
cpuGauge.Progress = vm.CpuUsage; cpuGauge.Progress = vm.CpuUsage;
@ -155,7 +155,7 @@ namespace WebsitePanel.Portal.VPS
|| vm.State == VirtualMachineState.Saved)) || vm.State == VirtualMachineState.Saved))
buttons.Add(CreateActionButton("Start", "start.png")); buttons.Add(CreateActionButton("Start", "start.png"));
if (vm.State == VirtualMachineState.Started) if (vm.State == VirtualMachineState.Running)
{ {
if(vmi.RebootAllowed) if(vmi.RebootAllowed)
buttons.Add(CreateActionButton("Reboot", "reboot.png")); buttons.Add(CreateActionButton("Reboot", "reboot.png"));
@ -165,12 +165,12 @@ namespace WebsitePanel.Portal.VPS
} }
if (vmi.StartTurnOffAllowed if (vmi.StartTurnOffAllowed
&& (vm.State == VirtualMachineState.Started && (vm.State == VirtualMachineState.Running
|| vm.State == VirtualMachineState.Paused)) || vm.State == VirtualMachineState.Paused))
buttons.Add(CreateActionButton("TurnOff", "turnoff.png")); buttons.Add(CreateActionButton("TurnOff", "turnoff.png"));
if (vmi.PauseResumeAllowed if (vmi.PauseResumeAllowed
&& vm.State == VirtualMachineState.Started) && vm.State == VirtualMachineState.Running)
buttons.Add(CreateActionButton("Pause", "pause.png")); buttons.Add(CreateActionButton("Pause", "pause.png"));
if (vmi.PauseResumeAllowed if (vmi.PauseResumeAllowed
@ -178,7 +178,7 @@ namespace WebsitePanel.Portal.VPS
buttons.Add(CreateActionButton("Resume", "start2.png")); buttons.Add(CreateActionButton("Resume", "start2.png"));
if (vmi.ResetAllowed if (vmi.ResetAllowed
&& (vm.State == VirtualMachineState.Started && (vm.State == VirtualMachineState.Running
|| vm.State == VirtualMachineState.Paused)) || vm.State == VirtualMachineState.Paused))
buttons.Add(CreateActionButton("Reset", "reset2.png")); buttons.Add(CreateActionButton("Reset", "reset2.png"));

View file

@ -120,6 +120,7 @@
<td> <td>
<asp:Panel ID="sharedIP" runat="server"> <asp:Panel ID="sharedIP" runat="server">
<asp:Localize ID="locSharedIPAddress" runat="server" meta:resourcekey="locSharedIPAddress" Text="IP address: Shared" /> <asp:Localize ID="locSharedIPAddress" runat="server" meta:resourcekey="locSharedIPAddress" Text="IP address: Shared" />
<asp:Label ID="lblSharedIP" runat="server"/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
<asp:LinkButton ID="cmdSwitchToDedicatedIP" meta:resourcekey="cmdSwitchToDedicatedIP" runat="server" Text="Switch to dedicated IP" OnClick="cmdSwitchToDedicatedIP_Click"></asp:LinkButton> <asp:LinkButton ID="cmdSwitchToDedicatedIP" meta:resourcekey="cmdSwitchToDedicatedIP" runat="server" Text="Switch to dedicated IP" OnClick="cmdSwitchToDedicatedIP_Click"></asp:LinkButton>
</asp:Panel> </asp:Panel>

View file

@ -69,7 +69,7 @@ namespace WebsitePanel.Portal
new Tab { Id = "webman", ResourceKey = "Tab.WebManagement", Quota = Quotas.WEB_REMOTEMANAGEMENT, ViewId = "tabWebManagement" }, new Tab { Id = "webman", ResourceKey = "Tab.WebManagement", Quota = Quotas.WEB_REMOTEMANAGEMENT, ViewId = "tabWebManagement" },
new Tab { Id = "SSL", ResourceKey = "Tab.SSL", Quota = Quotas.WEB_SSL, ViewId = "SSL" }, new Tab { Id = "SSL", ResourceKey = "Tab.SSL", Quota = Quotas.WEB_SSL, ViewId = "SSL" },
}; };
protected string SharedIdAddres { get; set; }
private int PackageId private int PackageId
{ {
get { return (int)ViewState["PackageId"]; } get { return (int)ViewState["PackageId"]; }
@ -198,6 +198,16 @@ namespace WebsitePanel.Portal
{ {
litIPAddress.Text = site.SiteIPAddress; litIPAddress.Text = site.SiteIPAddress;
} }
else
{
IPAddressInfo[] ipsGeneral = ES.Services.Servers.GetIPAddresses(IPAddressPool.General, PanelRequest.ServerId);
bool generalIPExists = ipsGeneral.Any() && !string.IsNullOrEmpty(ipsGeneral[0].ExternalIP);
if (generalIPExists)
{
lblSharedIP.Text = string.Format("({0})", ipsGeneral[0].ExternalIP);
}
lblSharedIP.Visible = generalIPExists;
}
dedicatedIP.Visible = site.IsDedicatedIP; dedicatedIP.Visible = site.IsDedicatedIP;
sharedIP.Visible = !site.IsDedicatedIP; sharedIP.Visible = !site.IsDedicatedIP;

View file

@ -1,31 +1,3 @@
// Copyright (c) 2015, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
@ -238,6 +210,15 @@ namespace WebsitePanel.Portal {
/// </remarks> /// </remarks>
protected global::System.Web.UI.WebControls.Localize locSharedIPAddress; protected global::System.Web.UI.WebControls.Localize locSharedIPAddress;
/// <summary>
/// lblSharedIP control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label lblSharedIP;
/// <summary> /// <summary>
/// cmdSwitchToDedicatedIP control. /// cmdSwitchToDedicatedIP control.
/// </summary> /// </summary>