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;
        }
 /// <summary>
 /// Write Powershell Server.
 /// </summary>
 /// <param name="server">Fabric object</param>
 /// <param name="provider">Recovery Service Provider object</param>
 private void WriteServer(Fabric fabric, RecoveryServicesProvider provider)
 {
     this.WriteObject(new ASRServer(fabric, provider));
 }
 /// <summary>
 /// Write Powershell Fabric.
 /// </summary>
 /// <param name="server">Fabric object</param>
 private void WriteFabric(Fabric fabric)
 {
     this.WriteObject(new ASRFabric(fabric));
 }
        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());
        }
        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;
        }
        public static List<ProtectionContainer> GetPairedContainers(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric)
        {
            var protectionContainers = client.ProtectionContainer.List(
                primaryFabric.Name,
                GetRequestHeaders());

            return protectionContainers.ProtectionContainers
                .ToList().TakeWhile(item => item.Properties.PairingStatus == "Paired").ToList();
        }
 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());
 }
 /// <summary>
 /// Write Powershell Site.
 /// </summary>
 /// <param name="server">Fabric object</param>
 private void WriteSite(Fabric fabric)
 {
     this.WriteObject(new ASRSite(fabric));
 }
        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());
        }
Exemple #10
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;
        }
Exemple #11
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();
            }
        }
Exemple #12
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;
 }
Exemple #13
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;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ASRSite" /> class.
 /// </summary>
 /// <param name="site">Hydra site object.</param>
 public ASRSite(Fabric fabric)
 {
     this.Name = fabric.Name;
     this.FriendlyName = fabric.Properties.FriendlyName;
     this.ID = fabric.Id;            
     this.Type = fabric.Properties.CustomDetails.InstanceType;
     this.SiteIdentifier = fabric.Properties.InternalIdentifier;
 }
Exemple #15
0
        public static StorageClassificationMappingOperationResponse PairStorageClassification(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            StorageClassification primaryClassification,
            StorageClassification recoveryClassification,
            string armResourceName)
        {
            StorageClassificationMappingInputProperties props = new StorageClassificationMappingInputProperties()
            {
                TargetStorageClassificationId = recoveryClassification.Id
            };

            StorageClassificationMappingInput input = new StorageClassificationMappingInput()
            {
                Properties = props
            };

            return client.StorageClassificationMapping.PairStorageClassification(
                primaryFabric.Name,
                primaryClassification.Name,
                armResourceName,
                input,
                GetRequestHeaders()) as StorageClassificationMappingOperationResponse;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ASRServer" /> class with required 
 /// parameters.
 /// </summary>
 /// <param name="server">Server object</param>
 public ASRServer(Fabric fabric, RecoveryServicesProvider provider)
 {
     this.ID = provider.Id;
     this.Name = provider.Name;
     this.FriendlyName = provider.Properties.FriendlyName;
     if(provider.Properties.LastHeartbeat != null)
     {
         this.LastHeartbeat = (DateTime)provider.Properties.LastHeartbeat;
     }
     this.ProviderVersion = provider.Properties.ProviderVersion;
     this.ServerVersion = provider.Properties.ServerVersion;
     this.Connected = provider.Properties.ConnectionStatus.ToLower().CompareTo("connected") == 0 ?  true: false;
     this.FabricType = provider.Properties.FabricType;
     this.Type = provider.Type;
 }
Exemple #17
0
 public static LongRunningOperationResponse UnpairStorageClassification(
     this SiteRecoveryManagementClient client,
     Fabric primaryFabric,
     StorageClassification primaryClassification,
     string armResourceName)
 {
     return client.StorageClassificationMapping.UnpairStorageClassification(
         primaryFabric.Name,
         primaryClassification.Name,
         armResourceName,
         GetRequestHeaders());
 }
 private bool IsFabricInconsistent(Fabric fabric)
 {
     return fabric.Properties.BcdrState == "ConsistencyCheckPending";
 }
Exemple #19
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();
            }
        }