コード例 #1
0
        public static CreatePolicyOperationResponse CreateHyperV2012R2Policy(
            this SiteRecoveryManagementClient client,
            string armResourceName)
        {
            HyperVReplica2012R2PolicyInput hvrProfileInput = new HyperVReplica2012R2PolicyInput()
            {
                ApplicationConsistentSnapshotFrequencyInHours = 0,
                AllowedAuthenticationType = 1,
                Compression = "Enable",
                InitialReplicationMethod      = "OverNetwork",
                OnlineReplicationStartTime    = null,
                RecoveryPoints                = 0,
                ReplicaDeletion               = "Required",
                ReplicationPort               = 8083,
                ReplicationFrequencyInSeconds = 300
            };

            CreatePolicyInputProperties policyCreationProp = new CreatePolicyInputProperties()
            {
                ProviderSpecificInput = hvrProfileInput
            };

            CreatePolicyInput policyCreationInput = new CreatePolicyInput()
            {
                Properties = policyCreationProp
            };

            return(client.Policies.Create(
                       armResourceName,
                       policyCreationInput,
                       GetRequestHeaders()) as CreatePolicyOperationResponse);
        }
コード例 #2
0
ファイル: PairingTests.cs プロジェクト: wub/azure-sdk-for-net
        public void CreateHyperV2012R2Profile()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var    client     = GetSiteRecoveryClient(CustomHttpHandler);
                string policyName = "Hydra-Profile-HyperV-2012-R2-" + new Random().Next();
                HyperVReplica2012R2PolicyInput hvrProfileInput = new HyperVReplica2012R2PolicyInput()
                {
                    ApplicationConsistentSnapshotFrequencyInHours = 0,
                    AllowedAuthenticationType = 1,
                    Compression = "Enable",
                    InitialReplicationMethod      = "OverNetwork",
                    OnlineReplicationStartTime    = null,
                    RecoveryPoints                = 0,
                    ReplicaDeletion               = "Required",
                    ReplicationPort               = 8083,
                    ReplicationFrequencyInSeconds = 300
                };

                CreatePolicyInputProperties createInputProp = new CreatePolicyInputProperties()
                {
                    ProviderSpecificInput = hvrProfileInput
                };

                CreatePolicyInput policyInput = new CreatePolicyInput()
                {
                    Properties = createInputProp
                };

                var response = client.Policies.Create(policyName, policyInput, RequestHeaders);
                Assert.NotNull(response);
                Assert.Equal(response.Status, OperationStatus.Succeeded);

                var policyResponse = response as CreatePolicyOperationResponse;
                Assert.NotNull(policyResponse);
                Assert.NotNull(policyResponse.Policy);
                Assert.Equal(policyResponse.Policy.Name, policyName);
            }
        }
コード例 #3
0
ファイル: PairingTests.cs プロジェクト: wub/azure-sdk-for-net
        public void PairClouds()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                string priCld         = string.Empty;
                string recCldGuid     = string.Empty;
                string recCld         = string.Empty;
                string policyName     = "Hydra" + (new Random()).Next();
                Fabric selectedFabric = null;
                Policy currentPolicy  = null;

                var fabrics = client.Fabrics.List(RequestHeaders);

                foreach (var fabric in fabrics.Fabrics)
                {
                    if (fabric.Properties.CustomDetails.InstanceType.Contains("VMM"))
                    {
                        selectedFabric = fabric;
                    }
                }

                var containers = client.ProtectionContainer.List(selectedFabric.Name, RequestHeaders);

                foreach (var container in containers.ProtectionContainers)
                {
                    if (client.ProtectionContainerMapping.List(selectedFabric.Name, container.Name, RequestHeaders).ProtectionContainerMappings.Count == 0)
                    {
                        if (string.IsNullOrEmpty(priCld))
                        {
                            priCld = container.Name;
                        }
                        else if (string.IsNullOrEmpty(recCld))
                        {
                            recCld     = container.Id;
                            recCldGuid = container.Name;
                        }
                    }
                }

                HyperVReplica2012R2PolicyInput hvrProfileInput = new HyperVReplica2012R2PolicyInput()
                {
                    ApplicationConsistentSnapshotFrequencyInHours = 0,
                    AllowedAuthenticationType = 1,
                    Compression = "Enable",
                    InitialReplicationMethod   = "OverNetwork",
                    OnlineReplicationStartTime = null,
                    RecoveryPoints             = 0,
                    ReplicaDeletion            = "Required"
                };

                CreatePolicyInputProperties policyCreationProp = new CreatePolicyInputProperties()
                {
                    ProviderSpecificInput = hvrProfileInput
                };

                CreatePolicyInput policyCreationInput = new CreatePolicyInput()
                {
                    Properties = policyCreationProp
                };

                var policyCreateResp = client.Policies.Create(policyName, policyCreationInput, RequestHeaders);

                currentPolicy = client.Policies.Get(policyName, RequestHeaders).Policy;

                CreateProtectionContainerMappingInputProperties pairingProps =
                    new CreateProtectionContainerMappingInputProperties()
                {
                    PolicyId = currentPolicy.Id,
                    ProviderSpecificInput       = new ReplicationProviderContainerMappingInput(),
                    TargetProtectionContainerId = recCld
                };

                CreateProtectionContainerMappingInput pairingInput = new CreateProtectionContainerMappingInput()
                {
                    Properties = pairingProps
                };

                var pairingResp = client.ProtectionContainerMapping.ConfigureProtection(selectedFabric.Name, priCld, "Mapping01", pairingInput, RequestHeaders);
            }
        }
コード例 #4
0
        public void EndToEndE2ESingleVM()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                bool pairClouds    = true;
                bool enableDR      = true;
                bool pfo           = true;
                bool commit        = true;
                bool tfo           = true;
                bool pfoReverse    = true;
                bool commitReverse = true;
                bool rr            = true;
                bool rrReverse     = true;
                bool disableDR     = true;
                bool unpair        = true;
                bool removePolicy  = true;

                var fabrics = client.Fabrics.List(RequestHeaders);

                Fabric selectedFabric = null;

                foreach (var fabric in fabrics.Fabrics)
                {
                    if (fabric.Properties.CustomDetails.InstanceType.Contains("VMM"))
                    {
                        selectedFabric = fabric;
                    }
                }

                string priCld      = string.Empty;
                string recCldGuid  = string.Empty;
                string recCld      = string.Empty;
                string policyName  = "Hydra-EndToEndE2ESingleVM-" + (new Random()).Next();
                string mappingName = "Mapping-EndToEndE2ESingleVM-" + (new Random()).Next();
                string replicationProtectedItemName = "PE" + (new Random()).Next();
                string enableDRVmName = string.Empty;
                Policy currentPolicy  = null;

                var policies = client.Policies.List(RequestHeaders);

                if (string.IsNullOrEmpty(recCldGuid))
                {
                    var containers = client.ProtectionContainer.List(selectedFabric.Name, RequestHeaders);

                    foreach (var container in containers.ProtectionContainers)
                    {
                        if (container.Properties.PairingStatus.Equals("NotPaired", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (string.IsNullOrEmpty(priCld))
                            {
                                priCld = container.Name;
                            }
                            else if (string.IsNullOrEmpty(recCld) && priCld != container.Name)
                            {
                                recCld     = container.Id;
                                recCldGuid = container.Name;
                            }
                        }
                    }
                }
                else
                {
                    recCld = client.ProtectionContainer.Get(selectedFabric.Name, recCldGuid, RequestHeaders).ProtectionContainer.Id;
                }

                if (pairClouds)
                {
                    HyperVReplica2012R2PolicyInput hvrProfileInput = new HyperVReplica2012R2PolicyInput()
                    {
                        ApplicationConsistentSnapshotFrequencyInHours = 0,
                        AllowedAuthenticationType = 1,
                        Compression = "Enable",
                        InitialReplicationMethod      = "OverNetwork",
                        OnlineReplicationStartTime    = null,
                        RecoveryPoints                = 0,
                        ReplicaDeletion               = "Required",
                        ReplicationPort               = 8083,
                        ReplicationFrequencyInSeconds = 300
                    };

                    CreatePolicyInputProperties policyCreationProp = new CreatePolicyInputProperties()
                    {
                        ProviderSpecificInput = hvrProfileInput
                    };

                    CreatePolicyInput policyCreationInput = new CreatePolicyInput()
                    {
                        Properties = policyCreationProp
                    };

                    var policyCreateResp = client.Policies.Create(policyName, policyCreationInput, RequestHeaders);

                    currentPolicy = client.Policies.Get(policyName, RequestHeaders).Policy;
                    CreateProtectionContainerMappingInputProperties pairingProps = new CreateProtectionContainerMappingInputProperties()
                    {
                        PolicyId = currentPolicy.Id,
                        TargetProtectionContainerId = recCld,
                        ProviderSpecificInput       = new ReplicationProviderContainerMappingInput()
                    };

                    CreateProtectionContainerMappingInput pairingInput = new CreateProtectionContainerMappingInput()
                    {
                        Properties = pairingProps
                    };

                    var pairingResponse = client.ProtectionContainerMapping.ConfigureProtection(
                        selectedFabric.Name,
                        priCld,
                        mappingName,
                        pairingInput,
                        RequestHeaders);

                    // Adding SP1 Profile too

                    HyperVReplica2012PolicyInput hvrsp1ProfileInput = new HyperVReplica2012PolicyInput()
                    {
                        ApplicationConsistentSnapshotFrequencyInHours = 0,
                        AllowedAuthenticationType = 1,
                        Compression = "Enable",
                        InitialReplicationMethod   = "OverNetwork",
                        OnlineReplicationStartTime = null,
                        RecoveryPoints             = 0,
                        ReplicaDeletion            = "Required",
                        ReplicationPort            = 8083
                    };

                    CreatePolicyInputProperties policySp1CreationProp = new CreatePolicyInputProperties()
                    {
                        ProviderSpecificInput = hvrsp1ProfileInput
                    };

                    CreatePolicyInput policySp1CreationInput = new CreatePolicyInput()
                    {
                        Properties = policySp1CreationProp
                    };

                    var policySp1CreateResp = client.Policies.Create(policyName + "SP1", policySp1CreationInput, RequestHeaders);

                    var currentSp1Policy = client.Policies.Get(policyName + "SP1", RequestHeaders).Policy;
                    CreateProtectionContainerMappingInputProperties pairingSp1Props = new CreateProtectionContainerMappingInputProperties()
                    {
                        PolicyId = currentSp1Policy.Id,
                        TargetProtectionContainerId = recCld,
                        ProviderSpecificInput       = new ReplicationProviderContainerMappingInput()
                    };

                    CreateProtectionContainerMappingInput pairingSp1Input = new CreateProtectionContainerMappingInput()
                    {
                        Properties = pairingSp1Props
                    };

                    var pairingSp1Response = client.ProtectionContainerMapping.ConfigureProtection(
                        selectedFabric.Name,
                        priCld,
                        mappingName + "sp1",
                        pairingSp1Input,
                        RequestHeaders);
                }
                else
                {
                    currentPolicy = client.Policies.Get(policyName, RequestHeaders).Policy;
                }

                if (enableDR)
                {
                    EnableProtectionInputProperties enableDRProp = new EnableProtectionInputProperties();
                    if (string.IsNullOrEmpty(enableDRVmName))
                    {
                        var protectableItems = client.ProtectableItem.List(selectedFabric.Name, priCld, "Unprotected", RequestHeaders);

                        enableDRProp = new EnableProtectionInputProperties()
                        {
                            PolicyId                = currentPolicy.Id,
                            ProtectableItemId       = protectableItems.ProtectableItems[0].Id,
                            ProviderSpecificDetails = new EnableProtectionProviderSpecificInput()
                        };
                    }
                    else
                    {
                        var item = client.ProtectableItem.Get(selectedFabric.Name, priCld, enableDRVmName, RequestHeaders);

                        enableDRProp = new EnableProtectionInputProperties()
                        {
                            PolicyId                = currentPolicy.Id,
                            ProtectableItemId       = item.ProtectableItem.Id,
                            ProviderSpecificDetails = new EnableProtectionProviderSpecificInput()
                        };
                    }

                    EnableProtectionInput enableInput = new EnableProtectionInput()
                    {
                        Properties = enableDRProp
                    };

                    var enableDRStartTime = DateTime.Now;

                    var enableDRresp = client.ReplicationProtectedItem.EnableProtection(
                        selectedFabric.Name,
                        priCld,
                        replicationProtectedItemName,
                        enableInput,
                        RequestHeaders);

                    MonitoringHelper.MonitorJobs(MonitoringHelper.SecondaryIrJobName, enableDRStartTime, client, RequestHeaders);
                }

                ///////////////////////////// PFO ////////////////////////////////
                PlannedFailoverInputProperties plannedFailoverProp = new PlannedFailoverInputProperties()
                {
                    ProviderSpecificDetails = new ProviderSpecificFailoverInput()
                };

                PlannedFailoverInput plannedFailoverInput = new PlannedFailoverInput()
                {
                    Properties = plannedFailoverProp
                };
                ////////////////////////////// RR ////////////////////////////////
                ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties()
                {
                    ProviderSpecificDetails = new ReverseReplicationProviderSpecificInput()
                };

                ReverseReplicationInput rrInput = new ReverseReplicationInput()
                {
                    Properties = rrProp
                };
                ////////////////////////////////// UFO /////////////////////////////
                UnplannedFailoverInputProperties ufoProp = new UnplannedFailoverInputProperties()
                {
                    ProviderSpecificDetails = new ProviderSpecificFailoverInput(),
                    SourceSiteOperations    = "NotRequired"
                };

                UnplannedFailoverInput ufoInput = new UnplannedFailoverInput()
                {
                    Properties = ufoProp
                };
                /////////////////////////////////// TFO //////////////////////////////
                TestFailoverInputProperties tfoProp = new TestFailoverInputProperties()
                {
                    ProviderSpecificDetails = new ProviderSpecificFailoverInput()
                };

                TestFailoverInput tfoInput = new TestFailoverInput()
                {
                    Properties = tfoProp
                };
                /////////////////////////////////////
                if (pfo)
                {
                    var protectedItem = client.ReplicationProtectedItem.Get(
                        selectedFabric.Name,
                        priCld,
                        replicationProtectedItemName,
                        RequestHeaders);

                    var plannedfailover = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, priCld, replicationProtectedItemName, plannedFailoverInput, RequestHeaders);

                    //var unplannedFailoverReverse = client.ReplicationProtectedItem.UnplannedFailover(
                    //    selectedFabric.Name,
                    //    priCld,
                    //    replicationProtectedItemName,
                    //    ufoInput,
                    //    RequestHeaders);
                }

                if (commit)
                {
                    var commitFailover = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, priCld, replicationProtectedItemName, RequestHeaders);
                }

                if (rr)
                {
                    var rrOp = client.ReplicationProtectedItem.Reprotect(selectedFabric.Name, priCld, replicationProtectedItemName, rrInput, RequestHeaders);
                }

                if (pfoReverse)
                {
                    //var unplannedFailoverReverse = client.ReplicationProtectedItem.UnplannedFailover(
                    //    selectedFabric.Name, priCld, replicationProtectedItemName, ufoInput, RequestHeaders);

                    var plannedFailoverReverse = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, priCld, replicationProtectedItemName, plannedFailoverInput, RequestHeaders);
                }

                if (commitReverse)
                {
                    var commitFailoverReverse = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, priCld, replicationProtectedItemName, RequestHeaders);
                }

                if (rrReverse)
                {
                    DateTime rrPostUfoStartTime = DateTime.UtcNow;
                    var      rrReverseOp        = client.ReplicationProtectedItem.Reprotect(selectedFabric.Name, priCld, replicationProtectedItemName, rrInput, RequestHeaders);

                    /*while (true)
                     * {
                     *  Thread.Sleep(5000 * 60);
                     *  Job ufoJob = MonitoringHelper.GetJobId(
                     *      MonitoringHelper.ReverseReplicationJobName,
                     *      rrPostUfoStartTime,
                     *      client,
                     *      RequestHeaders);
                     *
                     *  if (ufoJob.Properties.StateDescription.Equals(
                     *      "WaitingForFinalizeProtection",
                     *      StringComparison.InvariantCultureIgnoreCase))
                     *  {
                     *      break;
                     *  }
                     * }
                     *
                     * MonitoringHelper.MonitorJobs(MonitoringHelper.PrimaryIrJobName, rrPostUfoStartTime, client, RequestHeaders);
                     * MonitoringHelper.MonitorJobs(MonitoringHelper.SecondaryIrJobName, rrPostUfoStartTime, client, RequestHeaders);*/
                }

                if (tfo)
                {
                    DateTime startTFO = DateTime.UtcNow;

                    var tfoOp = client.ReplicationProtectedItem.TestFailover(selectedFabric.Name, priCld, replicationProtectedItemName, tfoInput, RequestHeaders);

                    var jobs = MonitoringHelper.GetJobId(MonitoringHelper.TestFailoverJobName, startTFO, client, RequestHeaders);

                    ResumeJobParamsProperties resProp = new ResumeJobParamsProperties()
                    {
                        Comments = "Res TFO"
                    };

                    ResumeJobParams resParam = new ResumeJobParams()
                    {
                        Properties = resProp
                    };

                    var resJob = client.Jobs.Resume(jobs.Name, resParam, RequestHeaders);
                }

                if (disableDR)
                {
                    var disableDROperation = client.ReplicationProtectedItem.DisableProtection(selectedFabric.Name, priCld, replicationProtectedItemName, new DisableProtectionInput(), RequestHeaders);
                }

                if (unpair)
                {
                    var unpaiClouds = client.ProtectionContainerMapping.UnconfigureProtection(
                        selectedFabric.Name,
                        priCld,
                        mappingName,
                        new RemoveProtectionContainerMappingInput(),
                        RequestHeaders);
                }

                if (removePolicy)
                {
                    var policyDeletion = client.Policies.Delete(currentPolicy.Name, RequestHeaders);
                }
            }
        }