wsp-10329 Adding hyper-v replica to HyperV Provider. Server Part 4.

This commit is contained in:
Alexander Trofimov 2015-04-16 13:58:12 -04:00
parent 5af4c5a932
commit cceebc9f24
4 changed files with 108 additions and 4 deletions

View file

@ -99,9 +99,11 @@ namespace WebsitePanel.Providers.Virtualization
// Configuration
int GetProcessorCoresNumber();
// Replication
List<CertificateInfo> GetCertificates(string remoteServer);
void SetReplicaServer(string remoteServer, string thumbprint, string storagePath);
void UnsetReplicaServer(string remoteServer);
bool IsReplicaServer(string remoteServer);
void EnableVmReplication(string vmId, string replicaServer, VmReplication replication);
void SetVmReplication(string vmId, string replicaServer, VmReplication replication);
void TestReplicationServer(string vmId, string replicaServer, string localThumbprint);

View file

@ -1962,13 +1962,13 @@ namespace WebsitePanel.Providers.Virtualization
public List<CertificateInfo> GetCertificates(string remoteServer)
{
// we cant get certificates from remote server
if (string.IsNullOrEmpty(remoteServer))
if (!string.IsNullOrEmpty(remoteServer))
return null;
Command cmd = new Command("Get-ChildItem");
cmd.Parameters.Add("Path", @"cert:\LocalMachine\My");
Collection<PSObject> result = PowerShell.Execute(cmd, true);
Collection<PSObject> result = PowerShell.Execute(cmd, false);
return result
.Select(
@ -1985,9 +1985,7 @@ namespace WebsitePanel.Providers.Virtualization
{
// we cant enable firewall rules on remote server
if (!string.IsNullOrEmpty(remoteServer))
{
ReplicaHelper.SetFirewallRule(PowerShell, true);
}
ReplicaHelper.SetReplicaServer(PowerShell, true, remoteServer, thumbprint, storagePath);
}
@ -1997,6 +1995,20 @@ namespace WebsitePanel.Providers.Virtualization
ReplicaHelper.SetReplicaServer(PowerShell, false, remoteServer, null, null);
}
public bool IsReplicaServer(string remoteServer)
{
Command cmd = new Command("Get-VMReplicationServer");
if (!string.IsNullOrEmpty(remoteServer))
{
cmd.Parameters.Add("ComputerName", remoteServer);
}
Collection<PSObject> result = PowerShell.Execute(cmd, true);
return result != null && result.Count > 0;
}
public void EnableVmReplication(string vmId, string replicaServer, VmReplication replication)
{
if (ReplicaMode != ReplicaMode.ReplicationEnabled)

View file

@ -133,6 +133,8 @@ namespace WebsitePanel.Providers.Virtualization2012 {
private System.Threading.SendOrPostCallback UnsetReplicaServerOperationCompleted;
private System.Threading.SendOrPostCallback IsReplicaServerOperationCompleted;
private System.Threading.SendOrPostCallback EnableVmReplicationOperationCompleted;
private System.Threading.SendOrPostCallback SetVmReplicationOperationCompleted;
@ -306,6 +308,9 @@ namespace WebsitePanel.Providers.Virtualization2012 {
/// <remarks/>
public event UnsetReplicaServerCompletedEventHandler UnsetReplicaServerCompleted;
/// <remarks/>
public event IsReplicaServerCompletedEventHandler IsReplicaServerCompleted;
/// <remarks/>
public event EnableVmReplicationCompletedEventHandler EnableVmReplicationCompleted;
@ -2479,6 +2484,48 @@ namespace WebsitePanel.Providers.Virtualization2012 {
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/IsReplicaServer", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool IsReplicaServer(string remoteServer) {
object[] results = this.Invoke("IsReplicaServer", new object[] {
remoteServer});
return ((bool)(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginIsReplicaServer(string remoteServer, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("IsReplicaServer", new object[] {
remoteServer}, callback, asyncState);
}
/// <remarks/>
public bool EndIsReplicaServer(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((bool)(results[0]));
}
/// <remarks/>
public void IsReplicaServerAsync(string remoteServer) {
this.IsReplicaServerAsync(remoteServer, null);
}
/// <remarks/>
public void IsReplicaServerAsync(string remoteServer, object userState) {
if ((this.IsReplicaServerOperationCompleted == null)) {
this.IsReplicaServerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnIsReplicaServerOperationCompleted);
}
this.InvokeAsync("IsReplicaServer", new object[] {
remoteServer}, this.IsReplicaServerOperationCompleted, userState);
}
private void OnIsReplicaServerOperationCompleted(object arg) {
if ((this.IsReplicaServerCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.IsReplicaServerCompleted(this, new IsReplicaServerCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/EnableVmReplication", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
@ -4062,6 +4109,32 @@ namespace WebsitePanel.Providers.Virtualization2012 {
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void UnsetReplicaServerCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void IsReplicaServerCompletedEventHandler(object sender, IsReplicaServerCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class IsReplicaServerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal IsReplicaServerCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public bool Result {
get {
this.RaiseExceptionIfNecessary();
return ((bool)(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void EnableVmReplicationCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);

View file

@ -924,6 +924,23 @@ namespace WebsitePanel.Server
}
}
[WebMethod, SoapHeader("settings")]
public bool IsReplicaServer(string remoteServer)
{
try
{
Log.WriteStart("'{0}' IsReplicaServer", ProviderSettings.ProviderName);
var result = VirtualizationProvider.IsReplicaServer(remoteServer);
Log.WriteEnd("'{0}' IsReplicaServer", ProviderSettings.ProviderName);
return result;
}
catch (Exception ex)
{
Log.WriteError(String.Format("'{0}' IsReplicaServer", ProviderSettings.ProviderName), ex);
throw;
}
}
[WebMethod, SoapHeader("settings")]
public void EnableVmReplication(string vmId, string replicaServer, VmReplication replication)
{