Ejemplo n.º 1
0
        public static MappingOperationResponse PairCloudToAzure(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer primaryContainer, 
            Policy policy,
            string armResourceName)
        {
            CreateProtectionContainerMappingInputProperties pairingProps = 
                new CreateProtectionContainerMappingInputProperties()
            {
                PolicyId = policy.Id,
                TargetProtectionContainerId = "Microsoft Azure",
                ProviderSpecificInput = new ReplicationProviderContainerMappingInput()
            };

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

            return client.ProtectionContainerMapping.ConfigureProtection(
                primaryFabric.Name,
                primaryContainer.Name,
                armResourceName,
                pairingInput,
                GetRequestHeaders()) as MappingOperationResponse;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ASRProtectionContainer" /> class with 
 /// required parameters.
 /// </summary>
 /// <param name="pc">Protection container object</param>
 public ASRProtectionContainer(ProtectionContainer pc, List<ASRPolicy> availablePolicies)
 {
     this.AvailablePolicies = availablePolicies;
     this.ID = pc.Id;
     this.Name = pc.Name;
     this.FriendlyName = pc.Properties.FriendlyName;
     this.FabricFriendlyName = pc.Properties.FabricFriendlyName;
     this.Role = pc.Properties.Role;
     this.FabricType = pc.Properties.FabricType;
     this.Type = pc.Type;
 }
        /// <summary>
        /// Write Protection Container.
        /// </summary>
        /// <param name="protectionContainer">Protection Container</param>
        private void WriteProtectionContainer(ProtectionContainer protectionContainer)
        {
            List<ASRPolicy> availablePolicies = new List<ASRPolicy>();

            ProtectionContainerMappingListResponse protectionContainerMappingListResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainerMapping(
                Utilities.GetValueFromArmId(protectionContainer.Id, ARMResourceTypeConstants.ReplicationFabrics), protectionContainer.Name);
            foreach (ProtectionContainerMapping protectionContainerMapping in protectionContainerMappingListResponse.ProtectionContainerMappings)
            {
                PolicyResponse policyResponse = RecoveryServicesClient.GetAzureSiteRecoveryPolicy(
                    Utilities.GetValueFromArmId(protectionContainerMapping.Properties.PolicyId, ARMResourceTypeConstants.ReplicationPolicies));
                availablePolicies.Add(new ASRPolicy(policyResponse.Policy));
            }

            this.WriteObject(new ASRProtectionContainer(protectionContainer, availablePolicies));
        }
 /// <summary>
 /// Write Protection Container.
 /// </summary>
 /// <param name="protectionContainer">Protection Container</param>
 private void WriteProtectionContainer(ProtectionContainer protectionContainer)
 {
     this.WriteObject(new ASRProtectionContainer(protectionContainer));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ASRProtectionContainer" /> class with 
        /// required parameters.
        /// </summary>
        /// <param name="pc">Protection container object</param>
        public ASRProtectionContainer(ProtectionContainer pc)
        {
            if (pc.Properties.AvailableProtectionProfiles != null)
            {
                this.AvailableProtectionProfiles = new List<ASRProtectionProfile>();
                foreach (var profile in pc.Properties.AvailableProtectionProfiles)
                {
                    this.AvailableProtectionProfiles.Add(
                        new ASRProtectionProfile(profile));
                }
            }

            this.ID = pc.Id;
            this.Name = pc.Name;
            this.FriendlyName = pc.Properties.FriendlyName;
            this.Role = pc.Properties.Role;
            // this.ServerId = pc.Properties.ServerId;
            this.FabricObjectId = pc.Properties.FabricObjectId;
            this.FabricType = pc.Properties.FabricType;
            this.Type = pc.Type;
        }
Ejemplo n.º 6
0
        public static LongRunningOperationResponse UnpairClouds(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer primaryContainer,
            string armResourceName)
        {
            ProtectionContainerMapping mapping = 
                client.ProtectionContainerMapping.Get(
                    primaryFabric.Name,
                    primaryContainer.Name,
                    armResourceName,
                    GetRequestHeaders()).ProtectionContainerMapping;

            return client.ProtectionContainerMapping.UnconfigureProtection(
                primaryFabric.Name,
                primaryContainer.Name,
                armResourceName,
                new RemoveProtectionContainerMappingInput(), 
                GetRequestHeaders());
        }
Ejemplo n.º 7
0
        public static List<ProtectableItem> GetUnprotectedItems(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer container)
        {
            List<ProtectableItem> protectableItemList = new List<ProtectableItem>();
            ProtectableItemListResponse protectableItemListResponse = client.ProtectableItem.List(
                primaryFabric.Name,
                container.Name,
                "Unprotected",
                null,
                "1000",
                GetRequestHeaders());
            protectableItemList.AddRange(protectableItemListResponse.ProtectableItems);
            while (protectableItemListResponse.NextLink != null)
            {
                protectableItemListResponse = client.ProtectableItem.ListNext(
                    protectableItemListResponse.NextLink,
                    GetRequestHeaders());
                protectableItemList.AddRange(protectableItemListResponse.ProtectableItems);
            }

            return protectableItemList;
        }
Ejemplo n.º 8
0
        public static LongRunningOperationResponse TestFailover(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer protectionContainer,
            ReplicationProtectedItem protectedItem)
        {
            TestFailoverInput tfoInput = new TestFailoverInput()
            {
                Properties = new TestFailoverInputProperties()
                {
                    ProviderSpecificDetails = new ProviderSpecificFailoverInput()
                }
            };

            if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure")
            {
                HyperVReplicaAzureFailoverProviderInput hvrAFOInput = 
                    new HyperVReplicaAzureFailoverProviderInput()
                {
                    VaultLocation = "West US",
                };

                string networkId = (protectedItem.Properties.ProviderSpecificDetails as HyperVReplicaAzureReplicationDetails)
                        .SelectedRecoveryAzureNetworkId;
                TestFailoverInputProperties tfoProp = new TestFailoverInputProperties()
                {
                    ProviderSpecificDetails = hvrAFOInput,
                    NetworkType = string.IsNullOrEmpty(networkId) ? null : "VmNetworkAsInput",
                    NetworkId = networkId
                };

                tfoInput.Properties = tfoProp;
            }

            DateTime startTFO = DateTime.UtcNow;
            var tfoOp = client.ReplicationProtectedItem.TestFailover(
                primaryFabric.Name,
                protectionContainer.Name,
                protectedItem.Name, 
                tfoInput, 
                GetRequestHeaders());

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

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

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

            return client.Jobs.Resume(jobs.Name, resParam, GetRequestHeaders());
        }
Ejemplo n.º 9
0
        public static ReplicationProtectedItemOperationResponse UnplannedFailover(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer protectionContainer,
            ReplicationProtectedItem protectedItem)
        {
            UnplannedFailoverInput ufoInput = new UnplannedFailoverInput()
            {
                Properties = new UnplannedFailoverInputProperties()
                {
                    ProviderSpecificDetails = new ProviderSpecificFailoverInput()
                }
            };

            if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure")
            {
                HyperVReplicaAzureFailoverProviderInput hvrAFOInput =
                    new HyperVReplicaAzureFailoverProviderInput()
                {
                    VaultLocation = "West US",
                };

                UnplannedFailoverInputProperties ufoProp = new UnplannedFailoverInputProperties()
                {
                    ProviderSpecificDetails = new ProviderSpecificFailoverInput(),
                    SourceSiteOperations = "NotRequired"
                };

                ufoInput.Properties = ufoProp;
            }

            return client.ReplicationProtectedItem.UnplannedFailover(
                primaryFabric.Name,
                protectionContainer.Name,
                protectedItem.Name,
                ufoInput,
                GetRequestHeaders()) as ReplicationProtectedItemOperationResponse;
        }
Ejemplo n.º 10
0
        public static ReplicationProtectedItemOperationResponse ReverseReplication(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer protectionContainer,
            ReplicationProtectedItem protectedItem)
        {
            if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure")
            {
                ProtectableItem protectableItem = client.ProtectableItem.Get(
                    primaryFabric.Name,
                    protectionContainer.Name,
                    protectedItem.Properties.ProtectableItemId.Substring(
                        protectedItem.Properties.ProtectableItemId.LastIndexOf("/") + 1),
                    GetRequestHeaders()).ProtectableItem;

                string vhdId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails)
                    .DiskDetailsList[0].VhdId;

                DiskDetails osDisk = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails)
                    .DiskDetailsList
                    .FirstOrDefault(item => item.VhdType == "OperatingSystem");

                if (osDisk != null)
                {
                    vhdId = osDisk.VhdId;
                }

                string storageAccount =
                    (protectedItem.Properties.ProviderSpecificDetails as HyperVReplicaAzureReplicationDetails)
                    .RecoveryAzureStorageAccount;

                HyperVReplicaAzureReprotectInput hvrARRInput = new HyperVReplicaAzureReprotectInput()
                {
                    HvHostVmId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId,
                    OSType = "Windows",
                    VHDId = vhdId,
                    VmName = protectableItem.Properties.FriendlyName,
                    StorageAccountId = storageAccount,
                };

                ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties()
                {
                    FailoverDirection = "",
                    ProviderSpecificDetails = hvrARRInput
                };

                ReverseReplicationInput rrInput = new ReverseReplicationInput()
                {
                    Properties = rrProp
                };

                return client.ReplicationProtectedItem.Reprotect(
                    primaryFabric.Name,
                    protectionContainer.Name, 
                    protectedItem.Name, 
                    rrInput,
                    GetRequestHeaders()) as ReplicationProtectedItemOperationResponse;
            }
            else if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012" ||
                protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012R2")
            {
                ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties()
                {
                    ProviderSpecificDetails = new ReverseReplicationProviderSpecificInput()
                };

                ReverseReplicationInput rrInput = new ReverseReplicationInput()
                {
                    Properties = rrProp
                };

                return client.ReplicationProtectedItem.Reprotect(
                    primaryFabric.Name,
                    protectionContainer.Name,
                    protectedItem.Name,
                    rrInput,
                    GetRequestHeaders()) as ReplicationProtectedItemOperationResponse;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 11
0
 public static ReplicationProtectedItemOperationResponse CommitFailover(
     this SiteRecoveryManagementClient client,
     Fabric primaryFabric,
     ProtectionContainer protectionContainer,
     ReplicationProtectedItem protectedItem)
 {
     return client.ReplicationProtectedItem.CommitFailover(
        primaryFabric.Name,
        protectionContainer.Name,
        protectedItem.Name,
        GetRequestHeaders()) as ReplicationProtectedItemOperationResponse;
 }
Ejemplo n.º 12
0
        public static ReplicationProtectedItemOperationResponse PlannedFailover(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer protectionContainer,
            ReplicationProtectedItem protectedItem)
        {
            PlannedFailoverInputProperties plannedFailoverProp = 
                new PlannedFailoverInputProperties();

            if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure")
            {
                if (protectedItem.Properties.ActiveLocation == "Recovery")
                {
                    HyperVReplicaAzureFailbackProviderInput hvrAFBInput = new HyperVReplicaAzureFailbackProviderInput()
                    {
                        RecoveryVmCreationOption = "NoAction",
                        DataSyncOption = "ForSyncronization"
                    };

                    plannedFailoverProp.ProviderSpecificDetails = hvrAFBInput;
                }
                else
                {
                    HyperVReplicaAzureFailoverProviderInput hvrAFOInput =
                       new HyperVReplicaAzureFailoverProviderInput()
                       {
                           VaultLocation = "West US",
                       };

                    plannedFailoverProp.ProviderSpecificDetails = hvrAFOInput;
                }
            }

            PlannedFailoverInput pfoInput = new PlannedFailoverInput()
            {
                Properties = plannedFailoverProp
            };

            return client.ReplicationProtectedItem.PlannedFailover(
                primaryFabric.Name,
                protectionContainer.Name,
                protectedItem.Name,
                pfoInput,
                GetRequestHeaders()) as ReplicationProtectedItemOperationResponse;
        }
Ejemplo n.º 13
0
 public static LongRunningOperationResponse DisableDR(
     this SiteRecoveryManagementClient client,
     Fabric primaryFabric,
     ProtectionContainer protectionContainer,
     string armResourceName)
 {
     return client.ReplicationProtectedItem.DisableProtection(
         primaryFabric.Name,
         protectionContainer.Name,
         armResourceName,
         new DisableProtectionInput(),
         GetRequestHeaders());
 }
Ejemplo n.º 14
0
        public static ReplicationProtectedItemOperationResponse EnableDR(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer protectionContainer,
            Policy policy,
            ProtectableItem protectableItem,
            string armResourceName)
        {
            if (policy.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure")
            {
                string vhdId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails)
                    .DiskDetailsList[0].VhdId;

                DiskDetails osDisk = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList
                    .FirstOrDefault(item => item.VhdType == "OperatingSystem");

                if (osDisk != null)
                {
                    vhdId = osDisk.VhdId;
                }

                HyperVReplicaAzureEnableProtectionInput hvrAEnableDRInput = 
                    new HyperVReplicaAzureEnableProtectionInput()
                {
                    HvHostVmId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId,
                    OSType = "Windows",
                    VhdId = vhdId,
                    VmName = protectableItem.Properties.FriendlyName,
                    TargetStorageAccountId = 
                        (policy.Properties.ProviderSpecificDetails as HyperVReplicaAzurePolicyDetails)
                        .ActiveStorageAccountId,
                };

                EnableProtectionInputProperties enableDRProp = new EnableProtectionInputProperties()
                {
                    PolicyId = policy.Id,
                    ProtectableItemId = protectableItem.Id,
                    ProviderSpecificDetails = hvrAEnableDRInput
                };

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

                return client.ReplicationProtectedItem.EnableProtection(
                    primaryFabric.Name,
                    protectionContainer.Name,
                    armResourceName,
                    enableDRInput,
                    GetRequestHeaders()) as ReplicationProtectedItemOperationResponse;
            }
            else if (policy.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012" ||
                policy.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012R2")
            {
                var enableDRProp = new EnableProtectionInputProperties()
                {
                    PolicyId = policy.Id,
                    ProtectableItemId = protectableItem.Id,
                    ProviderSpecificDetails = new EnableProtectionProviderSpecificInput()
                };

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

                return client.ReplicationProtectedItem.EnableProtection(
                    primaryFabric.Name,
                    protectionContainer.Name,
                    armResourceName,
                    enableInput,
                    GetRequestHeaders()) as ReplicationProtectedItemOperationResponse;
            }
            else
            {
                throw new NotImplementedException();
            }
        }