diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/AutomaticStartAction.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/AutomaticStartAction.cs
new file mode 100644
index 00000000..881a8a27
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/AutomaticStartAction.cs
@@ -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,
+ }
+}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/AutomaticStopAction.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/AutomaticStopAction.cs
new file mode 100644
index 00000000..3386e0d8
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/AutomaticStopAction.cs
@@ -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,
+ }
+}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj b/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj
index 5a7ebe5b..d0bf17c3 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj
@@ -288,6 +288,8 @@
+
+
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Constants.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Constants.cs
new file mode 100644
index 00000000..7821a6fd
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Constants.cs
@@ -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;
+ }
+}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/BiosHelper.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/BiosHelper.cs
index ebfc9694..21dafb52 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/BiosHelper.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/BiosHelper.cs
@@ -87,7 +87,7 @@ namespace WebsitePanel.Providers.Virtualization
if (bootFromCD)
cmd.Parameters.Add("FirstBootDevice", DvdDriveHelper.GetPS(powerShell, vm.Name));
else
- cmd.Parameters.Add("FirstBootDevice", VirtualMachineHelper.GetVirtualHardDisksPS(powerShell, vm.Name).FirstOrDefault());
+ cmd.Parameters.Add("FirstBootDevice", HardDriveHelper.GetPS(powerShell, vm.Name).FirstOrDefault());
powerShell.Execute(cmd, false);
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/HardDriveHelper.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/HardDriveHelper.cs
new file mode 100644
index 00000000..c8a951d6
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/HardDriveHelper.cs
@@ -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 disks = new List();
+
+ Collection 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");
+ 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();
+
+ // Command cmd = new Command("Get-VM");
+
+ // Collection 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 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 result = powerShell.Execute(cmd, false);
+ if (result != null && result.Count > 0)
+ {
+ disk.DiskFormat = result[0].GetEnum("VhdFormat");
+ disk.DiskType = result[0].GetEnum("VhdType");
+ disk.ParentPath = result[0].GetProperty("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"));
+ }
+ }
+ }
+
+ }
+}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/VirtualMachineHelper.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/VirtualMachineHelper.cs
index 0d24c149..e7d05288 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/VirtualMachineHelper.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/VirtualMachineHelper.cs
@@ -12,16 +12,8 @@ namespace WebsitePanel.Providers.Virtualization
{
public static class VirtualMachineHelper
{
- #region Constants
-
- private const Int64 Size1G = 0x40000000;
- private const Int64 Size1M = 0x100000;
-
- #endregion
-
public static OperationalStatus GetVMHeartBeatStatus(PowerShellManager powerShell, string name)
{
-
OperationalStatus status = OperationalStatus.None;
Command cmd = new Command("Get-VMIntegrationService");
@@ -40,7 +32,6 @@ namespace WebsitePanel.Providers.Virtualization
return status;
}
-
public static int GetVMProcessors(PowerShellManager powerShell, string name)
{
@@ -71,73 +62,15 @@ namespace WebsitePanel.Providers.Virtualization
if (result != null && result.Count > 0)
{
info.DynamicMemoryEnabled = Convert.ToBoolean(result[0].GetProperty("DynamicMemoryEnabled"));
- info.Startup = Convert.ToInt64(result[0].GetProperty("Startup")) / Size1M;
- info.Minimum = Convert.ToInt64(result[0].GetProperty("Minimum")) / Size1M;
- info.Maximum = Convert.ToInt64(result[0].GetProperty("Maximum")) / Size1M;
+ info.Startup = Convert.ToInt64(result[0].GetProperty("Startup")) / Constants.Size1M;
+ info.Minimum = Convert.ToInt64(result[0].GetProperty("Minimum")) / Constants.Size1M;
+ info.Maximum = Convert.ToInt64(result[0].GetProperty("Maximum")) / Constants.Size1M;
info.Buffer = Convert.ToInt32(result[0].GetProperty("Buffer"));
info.Priority = Convert.ToInt32(result[0].GetProperty("Priority"));
}
return info;
}
-
- public static VirtualHardDiskInfo[] GetVirtualHardDisks(PowerShellManager powerShell, string name)
- {
- List disks = new List();
-
- Collection result = GetVirtualHardDisksPS(powerShell, name);
-
- if (result != null && result.Count > 0)
- {
- foreach (PSObject d in result)
- {
- VirtualHardDiskInfo disk = new VirtualHardDiskInfo();
-
- disk.SupportPersistentReservations = Convert.ToBoolean(d.GetProperty("SupportPersistentReservations"));
- disk.MaximumIOPS = Convert.ToUInt64(d.GetProperty("MaximumIOPS"));
- disk.MinimumIOPS = Convert.ToUInt64(d.GetProperty("MinimumIOPS"));
- disk.VHDControllerType = d.GetEnum("ControllerType");
- disk.ControllerNumber = Convert.ToInt32(d.GetProperty("ControllerNumber"));
- disk.ControllerLocation = Convert.ToInt32(d.GetProperty("ControllerLocation"));
- disk.Path = d.GetProperty("Path").ToString();
- disk.Name = d.GetProperty("Name").ToString();
-
- GetVirtualHardDiskDetail(powerShell, disk.Path, ref disk);
-
- disks.Add(disk);
- }
- }
- return disks.ToArray();
- }
-
- public static Collection GetVirtualHardDisksPS(PowerShellManager powerShell, string name)
- {
- Command cmd = new Command("Get-VMHardDiskDrive");
- cmd.Parameters.Add("VMName", name);
-
- return powerShell.Execute(cmd, false);
- }
-
- public static void GetVirtualHardDiskDetail(PowerShellManager powerShell, string path, ref VirtualHardDiskInfo disk)
- {
- if (!string.IsNullOrEmpty(path))
- {
- Command cmd = new Command("Get-VHD");
- cmd.Parameters.Add("Path", path);
- Collection result = powerShell.Execute(cmd, false);
- if (result != null && result.Count > 0)
- {
- disk.DiskFormat = result[0].GetEnum("VhdFormat");
- disk.DiskType = result[0].GetEnum("VhdType");
- disk.ParentPath = result[0].GetProperty("ParentPath");
- disk.MaxInternalSize = Convert.ToInt64(result[0].GetProperty("Size")) / Size1G;
- disk.FileSize = Convert.ToInt64(result[0].GetProperty("FileSize")) / Size1G;
- disk.Attached = Convert.ToBoolean(result[0].GetProperty("Attached"));
- }
- }
- }
-
-
public static void UpdateProcessors(PowerShellManager powerShell, VirtualMachine vm, int cpuCores, int cpuLimitSettings, int cpuReserveSettings, int cpuWeightSettings)
{
Command cmd = new Command("Set-VMProcessor");
@@ -150,12 +83,13 @@ namespace WebsitePanel.Providers.Virtualization
powerShell.Execute(cmd, false);
}
+
public static void UpdateMemory(PowerShellManager powerShell, VirtualMachine vm, long ramMB)
{
Command cmd = new Command("Set-VMMemory");
cmd.Parameters.Add("VMName", vm.Name);
- cmd.Parameters.Add("StartupBytes", ramMB * Size1M);
+ cmd.Parameters.Add("StartupBytes", ramMB * Constants.Size1M);
powerShell.Execute(cmd, false);
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs
index 095eba14..7b1801ea 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs
@@ -198,12 +198,12 @@ namespace WebsitePanel.Providers.Virtualization
vm.DvdDriveInstalled = dvdInfo != null;
// HDD
- vm.Disks = VirtualMachineHelper.GetVirtualHardDisks(PowerShell, vm.Name);
+ vm.Disks = HardDriveHelper.Get(PowerShell, vm.Name);
if (vm.Disks != null && vm.Disks.GetLength(0) > 0)
{
vm.VirtualHardDrivePath = vm.Disks[0].Path;
- vm.HddSize = Convert.ToInt32(vm.Disks[0].FileSize);
+ vm.HddSize = Convert.ToInt32(vm.Disks[0].FileSize / Size1G);
}
// network adapters
@@ -327,104 +327,46 @@ namespace WebsitePanel.Providers.Virtualization
vm.OperatingSystemTemplatePath = FileUtils.EvaluateSystemVariables(vm.OperatingSystemTemplatePath);
vm.VirtualHardDrivePath = FileUtils.EvaluateSystemVariables(vm.VirtualHardDrivePath);
- string vmID = null;
-
- // request management service
- ManagementObject objVmsvc = GetVirtualSystemManagementService();
-
- // display name
- ManagementObject objGlobalSettings = wmi.GetWmiClass("msvm_VirtualSystemGlobalSettingData").CreateInstance();
- objGlobalSettings["ElementName"] = vm.Name;
-
- // VM folders
- objGlobalSettings["ExternalDataRoot"] = vm.RootFolderPath;
- objGlobalSettings["SnapshotDataRoot"] = vm.RootFolderPath;
-
- wmi.Dump(objGlobalSettings);
-
- // startup/shutdown actions
- if (AutomaticStartActionSettings != 100)
+ try
{
- objGlobalSettings["AutomaticStartupAction"] = AutomaticStartActionSettings;
- objGlobalSettings["AutomaticStartupActionDelay"] = String.Format("000000000000{0:d2}.000000:000", AutomaticStartupDelaySettings);
+ // Add new VM
+ Command cmdNew = new Command("New-VM");
+ cmdNew.Parameters.Add("Name", vm.Name);
+ cmdNew.Parameters.Add("VHDPath", vm.VirtualHardDrivePath);
+ PowerShell.Execute(cmdNew, false);
+
+ // Set VM
+ Command cmdSet = new Command("Set-VM");
+ cmdSet.Parameters.Add("Name", vm.Name);
+ cmdSet.Parameters.Add("SmartPagingFilePath", vm.RootFolderPath);
+ cmdSet.Parameters.Add("SnapshotFileLocation", vm.RootFolderPath);
+ // startup/shutdown actions
+ var autoStartAction = (AutomaticStartAction) AutomaticStartActionSettings;
+ var autoStopAction = (AutomaticStopAction) AutomaticStartActionSettings;
+ if (autoStartAction != AutomaticStartAction.Undefined)
+ {
+ cmdSet.Parameters.Add("AutomaticStartAction", autoStartAction.ToString());
+ cmdSet.Parameters.Add("AutomaticStartDelay", AutomaticStartupDelaySettings);
+ }
+ if (autoStopAction != AutomaticStopAction.Undefined)
+ cmdSet.Parameters.Add("AutomaticStopAction", autoStopAction.ToString());
+ PowerShell.Execute(cmdSet, false);
+
+ // Get created machine Id
+ var createdMachine = GetVirtualMachines().FirstOrDefault(m => m.Name == vm.Name);
+ if (createdMachine == null)
+ throw new Exception("Can't find created machine");
+ vm.VirtualMachineId = createdMachine.VirtualMachineId;
+
+ // Update common settings
+ UpdateVirtualMachine(vm);
+ }
+ catch (Exception ex)
+ {
+ HostedSolutionLog.LogError("CreateVirtualMachine", ex);
+ throw;
}
- if (AutomaticStopActionSettings != 100)
- objGlobalSettings["AutomaticShutdownAction"] = AutomaticStopActionSettings;
-
- if (AutomaticRecoveryActionSettings != 100)
- objGlobalSettings["AutomaticRecoveryAction"] = AutomaticRecoveryActionSettings;
-
- // create machine
- ManagementBaseObject inParams = objVmsvc.GetMethodParameters("DefineVirtualSystem");
- inParams["SystemSettingData"] = objGlobalSettings.GetText(TextFormat.CimDtd20);
- inParams["ResourceSettingData"] = new string[] { };
-
- // invoke method
- ManagementBaseObject outParams = objVmsvc.InvokeMethod("DefineVirtualSystem", inParams, null);
- ManagementObject objVM = wmi.GetWmiObjectByPath((string)outParams["DefinedSystem"]);
-
- // job
- JobResult job = CreateJobResultFromWmiMethodResults(outParams); ;
-
- // read VM id
- vmID = (string)objVM["Name"];
-
- // update general settings
- //UpdateVirtualMachineGeneralSettings(vmID, objVM,
- // vm.CpuCores,
- // vm.RamSize,
- // vm.BootFromCD,
- // vm.NumLockEnabled);
-
- // hard disks
- // load IDE 0 controller
- ManagementObject objIDE0 = wmi.GetWmiObject(
- "Msvm_ResourceAllocationSettingData", "ResourceSubType = 'Microsoft Emulated IDE Controller'"
- + " and InstanceID Like 'Microsoft:{0}%' and Address = 0", vmID);
-
- // load default hard disk drive
- ManagementObject objDefaultHdd = wmi.GetWmiObject(
- "Msvm_ResourceAllocationSettingData", "ResourceSubType = 'Microsoft Synthetic Disk Drive'"
- + " and InstanceID like '%Default'");
- ManagementObject objHdd = (ManagementObject)objDefaultHdd.Clone();
- objHdd["Parent"] = objIDE0.Path;
- objHdd["Address"] = 0;
-
- // add HDD to VM resources
- ManagementObject objAddedHDD = AddVirtualMachineResources(objVM, objHdd);
-
- // attach VHD
- string fullVhdPath = vm.VirtualHardDrivePath;
- ManagementObject objDefaultVHD = wmi.GetWmiObject(
- "Msvm_ResourceAllocationSettingData", "ResourceSubType = 'Microsoft Virtual Hard Disk'"
- + " and InstanceID like '%Default'");
- ManagementObject objVhd = (ManagementObject)objDefaultVHD.Clone();
- objVhd["Parent"] = objAddedHDD.Path.Path;
- objVhd["Connection"] = new string[] { fullVhdPath };
-
- // add VHD to the system
- AddVirtualMachineResources(objVM, objVhd);
-
- // DVD drive
- if (vm.DvdDriveInstalled)
- {
- AddVirtualMachineDvdDrive(vmID, objVM);
- }
-
- // add external adapter
- if (vm.ExternalNetworkEnabled && !String.IsNullOrEmpty(vm.ExternalSwitchId))
- AddNetworkAdapter(objVM, vm.ExternalSwitchId, vm.Name, vm.ExternalNicMacAddress, EXTERNAL_NETWORK_ADAPTER_NAME, vm.LegacyNetworkAdapter);
-
- // add private adapter
- if (vm.PrivateNetworkEnabled && !String.IsNullOrEmpty(vm.PrivateSwitchId))
- AddNetworkAdapter(objVM, vm.PrivateSwitchId, vm.Name, vm.PrivateNicMacAddress, PRIVATE_NETWORK_ADAPTER_NAME, vm.LegacyNetworkAdapter);
-
- // add management adapter
- if (vm.ManagementNetworkEnabled && !String.IsNullOrEmpty(vm.ManagementSwitchId))
- AddNetworkAdapter(objVM, vm.ManagementSwitchId, vm.Name, vm.ManagementNicMacAddress, MANAGEMENT_NETWORK_ADAPTER_NAME, vm.LegacyNetworkAdapter);
-
- vm.VirtualMachineId = vmID;
return vm;
}
@@ -1483,33 +1425,17 @@ namespace WebsitePanel.Providers.Virtualization
#region Storage
public VirtualHardDiskInfo GetVirtualHardDiskInfo(string vhdPath)
{
- ManagementObject objImgSvc = GetImageManagementService();
-
- // get method params
- ManagementBaseObject inParams = objImgSvc.GetMethodParameters("GetVirtualHardDiskInfo");
- inParams["Path"] = FileUtils.EvaluateSystemVariables(vhdPath);
-
- // execute method
- ManagementBaseObject outParams = (ManagementBaseObject)objImgSvc.InvokeMethod("GetVirtualHardDiskInfo", inParams, null);
- ReturnCode result = (ReturnCode)Convert.ToInt32(outParams["ReturnValue"]);
- if (result == ReturnCode.OK)
+ try
{
- // create XML
- string xml = (string)outParams["Info"];
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(xml);
-
- // read properties
- VirtualHardDiskInfo vhd = new VirtualHardDiskInfo();
- vhd.DiskType = (VirtualHardDiskType)Enum.Parse(typeof(VirtualHardDiskType), GetPropertyValue("Type", doc), true);
- vhd.FileSize = Int64.Parse(GetPropertyValue("FileSize", doc));
- vhd.InSavedState = Boolean.Parse(GetPropertyValue("InSavedState", doc));
- vhd.InUse = Boolean.Parse(GetPropertyValue("InUse", doc));
- vhd.MaxInternalSize = Int64.Parse(GetPropertyValue("MaxInternalSize", doc));
- vhd.ParentPath = GetPropertyValue("ParentPath", doc);
- return vhd;
+ VirtualHardDiskInfo hardDiskInfo = new VirtualHardDiskInfo();
+ HardDriveHelper.GetVirtualHardDiskDetail(PowerShell, vhdPath, ref hardDiskInfo);
+ return hardDiskInfo;
+ }
+ catch (Exception ex)
+ {
+ HostedSolutionLog.LogError("GetVirtualHardDiskInfo", ex);
+ throw;
}
- return null;
}
private string GetPropertyValue(string propertyName, XmlDocument doc)
@@ -1741,9 +1667,6 @@ exit", Convert.ToInt32(objDisk["Index"])));
public JobResult ConvertVirtualHardDisk(string sourcePath, string destinationPath, VirtualHardDiskType diskType)
{
- sourcePath = FileUtils.EvaluateSystemVariables(sourcePath);
- destinationPath = FileUtils.EvaluateSystemVariables(destinationPath);
-
// check source file
if (!FileExists(sourcePath))
throw new Exception("Source VHD cannot be found: " + sourcePath);
@@ -1752,17 +1675,26 @@ exit", Convert.ToInt32(objDisk["Index"])));
string destFolder = Path.GetDirectoryName(destinationPath);
if (!DirectoryExists(destFolder))
CreateFolder(destFolder);
+
+ sourcePath = FileUtils.EvaluateSystemVariables(sourcePath);
+ destinationPath = FileUtils.EvaluateSystemVariables(destinationPath);
+
+ try
+ {
+ Command cmd = new Command("Convert-VHD");
- ManagementObject objImgSvc = GetImageManagementService();
+ cmd.Parameters.Add("Path", sourcePath);
+ cmd.Parameters.Add("DestinationPath", destinationPath);
+ cmd.Parameters.Add("VHDType", diskType.ToString());
- // get method params
- ManagementBaseObject inParams = objImgSvc.GetMethodParameters("ConvertVirtualHardDisk");
- inParams["SourcePath"] = sourcePath;
- inParams["DestinationPath"] = destinationPath;
- inParams["Type"] = (UInt16)diskType;
-
- ManagementBaseObject outParams = (ManagementBaseObject)objImgSvc.InvokeMethod("ConvertVirtualHardDisk", inParams, null);
- return CreateJobResultFromWmiMethodResults(outParams);
+ PowerShell.Execute(cmd, false);
+ return JobHelper.CreateSuccessResult(ReturnCode.JobStarted);
+ }
+ catch (Exception ex)
+ {
+ HostedSolutionLog.LogError("ConvertVirtualHardDisk", ex);
+ throw;
+ }
}
public void DeleteRemoteFile(string path)
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/WebsitePanel.Providers.Virtualization.HyperV2012R2.csproj b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/WebsitePanel.Providers.Virtualization.HyperV2012R2.csproj
index c18926b0..635edce5 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/WebsitePanel.Providers.Virtualization.HyperV2012R2.csproj
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/WebsitePanel.Providers.Virtualization.HyperV2012R2.csproj
@@ -17,7 +17,7 @@
true
full
false
- ..\WebsitePanel.Server\bin\
+ ..\WebsitePanel.Server\bin\HyperV2012R2\
DEBUG;TRACE
prompt
4
@@ -53,8 +53,10 @@
VersionInfo.cs
+
+
diff --git a/WebsitePanel/Sources/WebsitePanel.Server/Web.config b/WebsitePanel/Sources/WebsitePanel.Server/Web.config
index 0dcd0c7d..8074f342 100644
--- a/WebsitePanel/Sources/WebsitePanel.Server/Web.config
+++ b/WebsitePanel/Sources/WebsitePanel.Server/Web.config
@@ -1,4 +1,4 @@
-
+
@@ -7,34 +7,34 @@
-
-
-
-
-
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
@@ -42,85 +42,85 @@
-
+
-
+
-
+
-
+
-
+
-
-
-
+
+
+
-
+
-
-
-
-
+
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -129,40 +129,40 @@
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
+
\ No newline at end of file