diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization/VirtualizationServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization/VirtualizationServerController.cs index fb69ef50..254ff3e9 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization/VirtualizationServerController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization/VirtualizationServerController.cs @@ -40,6 +40,8 @@ using System.Text; using System.Collections; using System.Net.Mail; using System.Diagnostics; +using System.Linq; +using System.Net; namespace WebsitePanel.EnterpriseServer { @@ -252,6 +254,8 @@ namespace WebsitePanel.EnterpriseServer return res; } + int generation = 1; + // CPU cores int cpuCores = cntx.Quotas[Quotas.VPS_CPU_NUMBER].QuotaAllocatedValue; if (cpuCores == -1) // unlimited is not possible @@ -305,7 +309,7 @@ namespace WebsitePanel.EnterpriseServer // create server and return result return CreateVirtualMachine(packageId, hostname, osTemplate, password, summaryLetterEmail, - cpuCores, ramMB, hddGB, snapshots, + generation, cpuCores, ramMB, hddGB, snapshots, dvdInstalled, bootFromCD, numLock, startShutdownAllowed, pauseResumeAllowed, rebootAllowed, resetAllowed, reinstallAllowed, externalNetworkEnabled, externalAddressesNumber, randomExternalAddresses, externalAddresses, @@ -314,7 +318,7 @@ namespace WebsitePanel.EnterpriseServer public static IntResult CreateVirtualMachine(int packageId, string hostname, string osTemplateFile, string password, string summaryLetterEmail, - int cpuCores, int ramMB, int hddGB, int snapshots, + int generation, int cpuCores, int ramMB, int hddGB, int snapshots, bool dvdInstalled, bool bootFromCD, bool numLock, bool startShutdownAllowed, bool pauseResumeAllowed, bool rebootAllowed, bool resetAllowed, bool reinstallAllowed, bool externalNetworkEnabled, int externalAddressesNumber, bool randomExternalAddresses, int[] externalAddresses, @@ -454,6 +458,7 @@ namespace WebsitePanel.EnterpriseServer vm.CurrentTaskId = Guid.NewGuid().ToString("N"); // generate creation task id vm.ProvisioningStatus = VirtualMachineProvisioningStatus.InProgress; + vm.Generation = generation; vm.CpuCores = cpuCores; vm.RamSize = ramMB; vm.HddSize = hddGB; @@ -516,8 +521,9 @@ namespace WebsitePanel.EnterpriseServer } vm.RootFolderPath = EvaluateItemVariables(rootFolderPattern, vm); - vm.OperatingSystemTemplatePath = Path.Combine(templatesPath, osTemplateFile + ".vhd"); - vm.VirtualHardDrivePath = Path.Combine(vm.RootFolderPath, hostname + ".vhd"); + var correctVhdPath = GetCorrectTemplateFilePath(templatesPath, osTemplateFile); + vm.OperatingSystemTemplatePath = correctVhdPath; + vm.VirtualHardDrivePath = Path.Combine(vm.RootFolderPath, hostname + Path.GetExtension(correctVhdPath)); // save meta-item try @@ -577,6 +583,14 @@ namespace WebsitePanel.EnterpriseServer return res; } + private static string GetCorrectTemplateFilePath(string templatesPath, string osTemplateFile) + { + if (osTemplateFile.Trim().EndsWith(".vhdx")) + return Path.Combine(templatesPath, osTemplateFile); + + return Path.Combine(templatesPath, osTemplateFile + ".vhd"); + } + internal static void CreateVirtualMachineInternal(string taskId, VirtualMachine vm, LibraryItem osTemplate, int externalAddressesNumber, bool randomExternalAddresses, int[] externalAddresses, int privateAddressesNumber, bool randomPrivateAddresses, string[] privateAddresses, @@ -1195,7 +1209,8 @@ namespace WebsitePanel.EnterpriseServer // set OS template string templatesPath = settings["OsTemplatesPath"]; - item.OperatingSystemTemplatePath = Path.Combine(templatesPath, osTemplateFile + ".vhd"); + var correctVhdPath = GetCorrectTemplateFilePath(templatesPath, osTemplateFile); + item.OperatingSystemTemplatePath = correctVhdPath; try { LibraryItem[] osTemplates = GetOperatingSystemTemplatesByServiceId(serviceId); diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esVirtualizationServer.asmx.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esVirtualizationServer.asmx.cs index 5ad2523e..8bdf9045 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esVirtualizationServer.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esVirtualizationServer.asmx.cs @@ -193,7 +193,7 @@ namespace WebsitePanel.EnterpriseServer { return VirtualizationServerController.CreateVirtualMachine(packageId, hostname, osTemplateFile, password, summaryLetterEmail, - cpuCores, ramMB, hddGB, snapshots, dvdInstalled, bootFromCD, numLock, + generation, cpuCores, ramMB, hddGB, snapshots, dvdInstalled, bootFromCD, numLock, startShutdownAllowed, pauseResumeAllowed, rebootAllowed, resetAllowed, reinstallAllowed, externalNetworkEnabled, externalAddressesNumber, randomExternalAddresses, externalAddresses, privateNetworkEnabled, privateAddressesNumber, randomPrivateAddresses, privateAddresses); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs index b86d832a..cb30af2e 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs @@ -315,7 +315,7 @@ namespace WebsitePanel.Providers.Virtualization cmdNew.Parameters.Add("Name", vm.Name); cmdNew.Parameters.Add("Generation", vm.Generation > 1 ? vm.Generation : 1); cmdNew.Parameters.Add("VHDPath", vm.VirtualHardDrivePath); - PowerShell.Execute(cmdNew, true); + PowerShell.Execute(cmdNew, true, true); // Set VM Command cmdSet = new Command("Set-VM"); @@ -512,14 +512,10 @@ namespace WebsitePanel.Providers.Virtualization DeleteSwitch(networkAdapter.SwitchName); } - object[] errors; - Command cmdSet = new Command("Remove-VM"); cmdSet.Parameters.Add("Name", vm.Name); cmdSet.Parameters.Add("Force"); - PowerShell.Execute(cmdSet, false, out errors); - - PowerShellManager.ExceptionIfErrors(errors); + PowerShell.Execute(cmdSet, false, true); return JobHelper.CreateSuccessResult(ReturnCode.JobStarted); } @@ -788,9 +784,7 @@ namespace WebsitePanel.Providers.Virtualization if (!string.IsNullOrEmpty(computerName)) cmd.Parameters.Add("ComputerName", computerName); if (!string.IsNullOrEmpty(type)) cmd.Parameters.Add("SwitchType", type); - object[] errors; - Collection result = PowerShell.Execute(cmd, false, out errors); - PowerShellManager.ExceptionIfErrors(errors); + Collection result = PowerShell.Execute(cmd, false, true); foreach (PSObject current in result) { diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/PowerShellManager.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/PowerShellManager.cs index 74298da0..1f63b104 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/PowerShellManager.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/PowerShellManager.cs @@ -66,12 +66,13 @@ namespace WebsitePanel.Providers.Virtualization public Collection Execute(Command cmd, bool addComputerNameParameter) { object[] errors; - return Execute(cmd, addComputerNameParameter, out errors); + return Execute(cmd, addComputerNameParameter, false); } - public Collection Execute(Command cmd, bool addComputerNameParameter, out object[] errors) + public Collection Execute(Command cmd, bool addComputerNameParameter, bool withExceptions) { HostedSolutionLog.LogStart("Execute"); + List errorList = new List(); HostedSolutionLog.DebugCommand(cmd); @@ -110,14 +111,17 @@ namespace WebsitePanel.Providers.Virtualization } } pipeLine = null; - errors = errorList.ToArray(); + + if (withExceptions) + ExceptionIfErrors(errorList); + HostedSolutionLog.LogEnd("Execute"); return results; } - public static void ExceptionIfErrors(object[] errors) + private static void ExceptionIfErrors(List errors) { - if (errors != null && errors.Length > 0) + if (errors != null && errors.Count > 0) throw new Exception("Invoke error: " + string.Join("; ", errors.Select(e => e.ToString()))); } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/App_LocalResources/HyperV2012R2_Create.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/App_LocalResources/HyperV2012R2_Create.ascx.resx new file mode 100644 index 00000000..5b5b2e6f --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/App_LocalResources/HyperV2012R2_Create.ascx.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + First + + + Second + + + Generation: + + + Generation + + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/HyperV2012R2_Create.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/HyperV2012R2_Create.ascx new file mode 100644 index 00000000..04e7bb37 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/HyperV2012R2_Create.ascx @@ -0,0 +1,20 @@ +<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="HyperV2012R2_Create.ascx.cs" Inherits="WebsitePanel.Portal.ProviderControls.HyperV2012R2_Create" %> +<%@ Register TagPrefix="wsp" TagName="CollapsiblePanel" Src="../../UserControls/CollapsiblePanel.ascx" %> + + + + + + + + + +
+ + + 1 + 2 + +
+
diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/HyperV2012R2_Create.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/HyperV2012R2_Create.ascx.cs new file mode 100644 index 00000000..18553f3d --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/HyperV2012R2_Create.ascx.cs @@ -0,0 +1,51 @@ +// 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. + +using System; +using WebsitePanel.Providers.Virtualization; + +namespace WebsitePanel.Portal.ProviderControls +{ + public partial class HyperV2012R2_Create : WebsitePanelControlBase, IVirtualMachineCreateControl + { + protected void Page_Load(object sender, EventArgs e) + { + } + + public void BindItem(VirtualMachine item) + { + var generation = item.Generation > 1 ? item.Generation : 1; + ddlGeneration.SelectedValue = generation.ToString(); + } + + public void SaveItem(VirtualMachine item) + { + item.Generation = Convert.ToInt32(ddlGeneration.SelectedValue); + } + } +} diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/HyperV2012R2_Create.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/HyperV2012R2_Create.ascx.designer.cs new file mode 100644 index 00000000..ffb228ce --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPS/ProviderControls/HyperV2012R2_Create.ascx.designer.cs @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WebsitePanel.Portal.ProviderControls { + + + public partial class HyperV2012R2_Create { + + /// + /// secGeneration control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::WebsitePanel.Portal.CollapsiblePanel secGeneration; + + /// + /// GenerationPanel control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Panel GenerationPanel; + + /// + /// locGeneration control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Localize locGeneration; + + /// + /// ddlGeneration control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.DropDownList ddlGeneration; + } +} diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebsitePanel.Portal.Modules.csproj b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebsitePanel.Portal.Modules.csproj index 18e0b6e0..ca62cd3b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebsitePanel.Portal.Modules.csproj +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebsitePanel.Portal.Modules.csproj @@ -258,6 +258,13 @@ EnterpriseStorageOwaUsersList.ascx + + HyperV2012R2_Create.ascx + ASPXCodeBehind + + + HyperV2012R2_Create.ascx + SmarterMail100_EditAccount.ascx ASPXCodeBehind @@ -4510,6 +4517,7 @@ + @@ -4559,6 +4567,9 @@ + + Designer +