/// <remarks/>
 public void SetVmReplicationAsync(int itemId, VmReplication replication) {
     this.SetVmReplicationAsync(itemId, replication, null);
 }
 /// <remarks/>
 public void SetVmReplicationAsync(int itemId, VmReplication replication, object userState) {
     if ((this.SetVmReplicationOperationCompleted == null)) {
         this.SetVmReplicationOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSetVmReplicationOperationCompleted);
     }
     this.InvokeAsync("SetVmReplication", new object[] {
                 itemId,
                 replication}, this.SetVmReplicationOperationCompleted, userState);
 }
 public ResultObject SetVmReplication(int itemId, VmReplication replication) {
     object[] results = this.Invoke("SetVmReplication", new object[] {
                 itemId,
                 replication});
     return ((ResultObject)(results[0]));
 }
 /// <remarks/>
 public System.IAsyncResult BeginSetVmReplication(int itemId, VmReplication replication, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("SetVmReplication", new object[] {
                 itemId,
                 replication}, callback, asyncState);
 }
Example #5
0
        public void EnableVmReplication(string vmId, string replicaServer, VmReplication replication)
        {
            if (ReplicaMode != ReplicaMode.ReplicationEnabled)
                throw new Exception("Server does not allow replication by settings");

            var vm = GetVirtualMachineEx(vmId);

            Command cmd = new Command("Enable-VMReplication");
            cmd.Parameters.Add("VmName", vm.Name);
            cmd.Parameters.Add("ReplicaServerName", replicaServer);
            cmd.Parameters.Add("ReplicaServerPort", 443);
            cmd.Parameters.Add("AuthenticationType", "Cert");
            cmd.Parameters.Add("CertificateThumbprint", replication.Thumbprint);
            cmd.Parameters.Add("ReplicationFrequencySec", (int)replication.ReplicaFrequency);

            var excludes = vm.Disks
                .Select(d => d.Path)
                .Where(p => replication.VhdToReplicate.All(vp => !p.Equals(vp, StringComparison.OrdinalIgnoreCase)))
                .ToArray();
            if (excludes.Any())
                cmd.Parameters.Add("ExcludedVhdPath", excludes);

            // recovery points
            cmd.Parameters.Add("RecoveryHistory", replication.AdditionalRecoveryPoints);
            if (replication.AdditionalRecoveryPoints > 0)
            {
                if (replication.AdditionalRecoveryPoints > 24)
                    throw new Exception("AdditionalRecoveryPoints can not be greater than 24");

                if (replication.VSSSnapshotFrequencyHour > 0)
                {
                    if (replication.VSSSnapshotFrequencyHour > 12)
                        throw new Exception("VSSSnapshotFrequencyHour can not be greater than 12");

                    cmd.Parameters.Add("VSSSnapshotFrequencyHour", replication.VSSSnapshotFrequencyHour);
                }
            }

            PowerShell.Execute(cmd, true, true);
        }
Example #6
0
        public VmReplication GetReplication(string vmId)
        {
            if (ReplicaMode != ReplicaMode.ReplicationEnabled)
                throw new Exception("Server does not allow replication by settings");

            VmReplication replica = null;
            var vm = GetVirtualMachineEx(vmId);

            Command cmd = new Command("Get-VMReplication");
            cmd.Parameters.Add("VmName", vm.Name);

            Collection<PSObject> result = PowerShell.Execute(cmd, true);

            if (result != null && result.Count > 0)
            {
                replica = new VmReplication();
                replica.ReplicaFrequency = result[0].GetEnum<ReplicaFrequency>("FrequencySec", ReplicaFrequency.Seconds30);
                replica.Thumbprint = result[0].GetString("CertificateThumbprint");
                replica.AdditionalRecoveryPoints = result[0].GetInt("RecoveryHistory");
                replica.VSSSnapshotFrequencyHour = result[0].GetInt("VSSSnapshotFrequencyHour");

                List<string> excludes = new List<string>();
                foreach (dynamic item in (IEnumerable) result[0].GetProperty("ExcludedDisks"))
                    excludes.Add(item.Path.ToString());
                replica.VhdToReplicate = vm.Disks
                    .Select(d => d.Path)
                    .Where(p => excludes.All(ep => !p.Equals(ep, StringComparison.OrdinalIgnoreCase)))
                    .ToArray();
            }

            return replica;
        }
        public static ResultObject SetVmReplication(int itemId, VmReplication replication)
        {
            TaskManager.StartTask("VPS2012", "SetVmReplication");

            ResultObject result = new ResultObject();


            try
            {
                VirtualMachine vm = GetVirtualMachineByItemId(itemId);

                // Check Quotas
                ReplicationHelper.CheckReplicationQuota(vm.PackageId, ref result);
                if (result.ErrorCodes.Count > 0)
                    return result;

                VirtualizationServer2012 vs = GetVirtualizationProxy(vm.ServiceId);

                // Get replica server
                var replicaServerInfo = ReplicationHelper.GetReplicaInfoForService(vm.ServiceId, ref result);
                if (result.ErrorCodes.Count > 0) return result;

                // We should use enable replication or set replication?
                var vmReplica = vs.GetReplication(vm.VirtualMachineId);
                if (vmReplica == null) // need enable
                {
                    vs.EnableVmReplication(vm.VirtualMachineId, replicaServerInfo.ComputerName, replication);
                    vs.StartInitialReplication(vm.VirtualMachineId);
                }
                else // need set
                {
                    vs.SetVmReplication(vm.VirtualMachineId, replicaServerInfo.ComputerName, replication);
                }
                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
            TaskManager.WriteWarning("Organization with itemId '{0}' not found", itemId.ToString());
            return result; 
        }
Example #8
0
        public void SetVmReplication(string vmId, string replicaServer, VmReplication replication)
        {
            if (ReplicaMode != ReplicaMode.ReplicationEnabled)
                throw new Exception("Server does not allow replication by settings");

            var vm = GetVirtualMachineEx(vmId);

            Command cmd = new Command("Set-VMReplication");
            cmd.Parameters.Add("VmName", vm.Name);
            cmd.Parameters.Add("ReplicaServerName", replicaServer);
            cmd.Parameters.Add("ReplicaServerPort", 443);
            cmd.Parameters.Add("AuthenticationType", "Cert");
            cmd.Parameters.Add("CertificateThumbprint", replication.Thumbprint);
            cmd.Parameters.Add("ReplicationFrequencySec", (int)replication.ReplicaFrequency);

            // recovery points
            cmd.Parameters.Add("RecoveryHistory", replication.AdditionalRecoveryPoints);
            if (replication.AdditionalRecoveryPoints > 0)
            {
                if (replication.AdditionalRecoveryPoints > 24)
                    throw new Exception("AdditionalRecoveryPoints can not be greater than 24");

                if (replication.VSSSnapshotFrequencyHour > 0)
                {
                    if (replication.VSSSnapshotFrequencyHour > 12)
                        throw new Exception("VSSSnapshotFrequencyHour can not be greater than 12");

                    cmd.Parameters.Add("VSSSnapshotFrequencyHour", replication.VSSSnapshotFrequencyHour);
                }
                else
                {
                    cmd.Parameters.Add("DisableVSSSnapshotReplication");
                }
            }

            PowerShell.Execute(cmd, true, true);
        }
 /// <remarks/>
 public void SetVmReplicationAsync(string vmId, string replicaServer, VmReplication replication) {
     this.SetVmReplicationAsync(vmId, replicaServer, replication, null);
 }
 public ResultObject SetVmReplication(int itemId, VmReplication replication)
 {
     return VirtualizationServerController2012.SetVmReplication(itemId, replication);
 }
 /// <remarks/>
 public System.IAsyncResult BeginSetVmReplication(string vmId, string replicaServer, VmReplication replication, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("SetVmReplication", new object[] {
                 vmId,
                 replicaServer,
                 replication}, callback, asyncState);
 }
 public void SetVmReplication(string vmId, string replicaServer, VmReplication replication) {
     this.Invoke("SetVmReplication", new object[] {
                 vmId,
                 replicaServer,
                 replication});
 }
 /// <remarks/>
 public void EnableVmReplicationAsync(string vmId, string replicaServer, VmReplication replication, object userState) {
     if ((this.EnableVmReplicationOperationCompleted == null)) {
         this.EnableVmReplicationOperationCompleted = new System.Threading.SendOrPostCallback(this.OnEnableVmReplicationOperationCompleted);
     }
     this.InvokeAsync("EnableVmReplication", new object[] {
                 vmId,
                 replicaServer,
                 replication}, this.EnableVmReplicationOperationCompleted, userState);
 }
 public void SetVmReplication(string vmId, string replicaServer, VmReplication replication)
 {
     try
     {
         Log.WriteStart("'{0}' SetVmReplication", ProviderSettings.ProviderName);
         VirtualizationProvider.SetVmReplication(vmId, replicaServer, replication);
         Log.WriteEnd("'{0}' SetVmReplication", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' SetVmReplication", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
        private void SetReplication()
        {
            var vmReplica = new VmReplication();

            vmReplica.VhdToReplicate = chlVHDs.Items.Cast<ListItem>()
                .Where(li => li.Selected)
                .Select(li => li.Value)
                .ToArray();

            vmReplica.Thumbprint = ddlCeritficateDiv.Visible ? ddlCeritficate.SelectedValue : txtCeritficate.Text;
            vmReplica.ReplicaFrequency = (ReplicaFrequency) Convert.ToInt32(ddlFrequency.SelectedValue);
            vmReplica.AdditionalRecoveryPoints = radRecoveryPoints.SelectedValue == "OnlyLast" ? 0 : Convert.ToInt32(txtRecoveryPointsAdditional.Text);
            vmReplica.VSSSnapshotFrequencyHour = chbVSS.Checked ? Convert.ToInt32(txtRecoveryPointsVSS.Text) : 0;

            try
            {
                ResultObject res = ES.Services.VPS2012.SetVmReplication(PanelRequest.ItemID, vmReplica);

                if (res.IsSuccess)
                {
                    Bind();
                    ShowSuccessMessage("VPS_SET_REPLICATION_ERROR");
                }
                else
                    messageBox.ShowMessage(res, "VPS_SET_REPLICATION_ERROR", "VPS");
            }
            catch (Exception ex)
            {
                ShowErrorMessage("VPS_SET_REPLICATION_ERROR", ex);
            }
        }