public static CreatePolicyOperationResponse CreateHyperVReplicaAzurePolicy( this SiteRecoveryManagementClient client, string armResourceName, string storageAccountArmId) { HyperVReplicaAzurePolicyInput hvrAPolicy = new HyperVReplicaAzurePolicyInput() { ApplicationConsistentSnapshotFrequencyInHours = 0, Encryption = "Disable", OnlineIrStartTime = null, RecoveryPointHistoryDuration = 0, ReplicationInterval = 30, StorageAccounts = new List <string>() { storageAccountArmId } }; CreatePolicyInputProperties createInputProp = new CreatePolicyInputProperties() { ProviderSpecificInput = hvrAPolicy }; CreatePolicyInput policyInput = new CreatePolicyInput() { Properties = createInputProp }; return(client.Policies.Create(armResourceName, policyInput, GetRequestHeaders()) as CreatePolicyOperationResponse); }
public void CreateHyperVAzureProfile() { using (UndoContext context = UndoContext.Current) { context.Start(); var client = GetSiteRecoveryClient(CustomHttpHandler); string policyName = "Hydra-Profile-HyperVAzure"; HyperVReplicaAzurePolicyInput hvrAPolicy = new HyperVReplicaAzurePolicyInput() { ApplicationConsistentSnapshotFrequencyInHours = 0, Encryption = "Disable", OnlineIrStartTime = null, RecoveryPointHistoryDuration = 0, ReplicationInterval = 30, StorageAccounts = new List <string>() { "/subscriptions/c89695cf-3a29-4ff0-86da-2696d2c5322b/resourceGroups/Default-Storage-SoutheastAsia/providers/Microsoft.ClassicStorage/storageAccounts/sa03sub10v1sea" } }; CreatePolicyInputProperties createInputProp = new CreatePolicyInputProperties() { ProviderSpecificInput = hvrAPolicy }; CreatePolicyInput policyInput = new CreatePolicyInput() { Properties = createInputProp }; var policy = client.Policies.Create(policyName, policyInput, RequestHeaders); //var selectedPolicy = (client.Policies.Create(policyName, policyInput, RequestHeaders) as CreatePolicyOperationResponse).Policy; } }
/// <summary> /// Creates an E2A Policy Object /// </summary> private void HyperVToAzurePolicyObject() { if (string.Compare( this.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Resources.IncorrectReplicationProvider, this.ReplicationProvider)); } PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime); var replicationFrequencyInSeconds = PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort( this.ReplicationFrequencyInSeconds); var hyperVReplicaAzurePolicyInput = new HyperVReplicaAzurePolicyInput { ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours, OnlineReplicationStartTime = this.ReplicationStartTime == null ? null : this.ReplicationStartTime.ToString(), RecoveryPointHistoryDuration = this.NumberOfRecoveryPointsToRetain, ReplicationInterval = replicationFrequencyInSeconds }; hyperVReplicaAzurePolicyInput.StorageAccounts = new List <string>(); if (this.RecoveryAzureStorageAccountId != null) { var storageAccount = this.RecoveryAzureStorageAccountId; hyperVReplicaAzurePolicyInput.StorageAccounts.Add(storageAccount); } var createPolicyInputProperties = new CreatePolicyInputProperties { ProviderSpecificInput = hyperVReplicaAzurePolicyInput }; var createPolicyInput = new CreatePolicyInput { Properties = createPolicyInputProperties }; var response = this.RecoveryServicesClient.CreatePolicy( this.Name, createPolicyInput); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Creates an E2A Policy Object /// </summary> private void EnterpriseToAzurePolicyObject() { if (string.Compare(this.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Properties.Resources.IncorrectReplicationProvider, this.ReplicationProvider)); } PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime); ushort replicationFrequencyInSeconds = PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds); var hyperVReplicaAzurePolicyInput = new HyperVReplicaAzurePolicyInput() { ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours, Encryption = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.Encryption)) ? this.Encryption : Constants.Disable, OnlineIrStartTime = this.ReplicationStartTime, RecoveryPointHistoryDuration = this.RecoveryPoints, ReplicationInterval = replicationFrequencyInSeconds }; hyperVReplicaAzurePolicyInput.StorageAccounts = new System.Collections.Generic.List <string>(); if (RecoveryAzureStorageAccountId != null) { string storageAccount = this.RecoveryAzureStorageAccountId; hyperVReplicaAzurePolicyInput.StorageAccounts.Add(storageAccount); } var createPolicyInputProperties = new CreatePolicyInputProperties() { ProviderSpecificInput = hyperVReplicaAzurePolicyInput }; var createPolicyInput = new CreatePolicyInput() { Properties = createPolicyInputProperties }; LongRunningOperationResponse response = RecoveryServicesClient.CreatePolicy(this.Name, createPolicyInput); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Creates an E2A Policy Object /// </summary> private void HyperVToAzurePolicyObject() { if (string.Compare( this.InputObject.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Resources.IncorrectReplicationProvider, this.InputObject.ReplicationProvider)); } var replicationProviderSettings = this.InputObject.ReplicationProviderSettings as ASRHyperVReplicaAzurePolicyDetails; this.replicationFrequencyInSeconds = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicationFrequencyInSeconds)) ? PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort( this.ReplicationFrequencyInSeconds) : (ushort)replicationProviderSettings .ReplicationFrequencyInSeconds; this.recoveryPoints = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.NumberOfRecoveryPointsToRetain)) ? this.NumberOfRecoveryPointsToRetain : replicationProviderSettings.RecoveryPoints; this.applicationConsistentSnapshotFrequencyInHours = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName( () => this.ApplicationConsistentSnapshotFrequencyInHours)) ? this.ApplicationConsistentSnapshotFrequencyInHours : replicationProviderSettings.ApplicationConsistentSnapshotFrequencyInHours; this.replicationStartTime = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicationStartTime)) ? this.replicationStartTime : replicationProviderSettings.OnlineReplicationStartTime; this.recoveryAzureStorageAccountId = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryAzureStorageAccountId)) ? this.RecoveryAzureStorageAccountId : replicationProviderSettings.ActiveStorageAccountId; this.encryption = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.Encryption)) ? this.Encryption : (string.Compare( replicationProviderSettings.Encryption, "Disabled", StringComparison.OrdinalIgnoreCase) == 0 ? Constants.Disable : Constants.Enable); var hyperVReplicaAzurePolicyInput = new HyperVReplicaAzurePolicyInput { ApplicationConsistentSnapshotFrequencyInHours = this.applicationConsistentSnapshotFrequencyInHours, Encryption = this.encryption, OnlineReplicationStartTime = this.replicationStartTime.ToString(), RecoveryPointHistoryDuration = this.recoveryPoints, ReplicationInterval = this.replicationFrequencyInSeconds }; hyperVReplicaAzurePolicyInput.StorageAccounts = new List <string>(); if (this.RecoveryAzureStorageAccountId != null) { var storageAccount = this.recoveryAzureStorageAccountId; hyperVReplicaAzurePolicyInput.StorageAccounts.Add(storageAccount); } var updatePolicyProperties = new UpdatePolicyInputProperties { ReplicationProviderSettings = hyperVReplicaAzurePolicyInput }; var updatePolicyInput = new UpdatePolicyInput { Properties = updatePolicyProperties }; var response = this.RecoveryServicesClient.UpdatePolicy( this.InputObject.Name, updatePolicyInput); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
public void EndToEndB2ASingleVM() { using (UndoContext context = UndoContext.Current) { context.Start(); var client = GetSiteRecoveryClient(CustomHttpHandler); bool createPolicy = true; bool pairClouds = true; bool enableDR = true; bool pfo = true; bool commit = true; bool tfo = true; bool pfoReverse = true; bool commitReverse = true; bool reprotect = true; bool disableDR = true; bool unpair = true; bool removePolicy = true; // Process Variables string fabricName = string.Empty; string recCldName = "Microsoft Azure"; string priCldName = string.Empty; string policyName = "Hydra-EndToEndB2ASingleVM-" + (new Random()).Next(); string mappingName = "Mapping-EndToEndB2ASingleVM-" + (new Random()).Next(); string enableDRName = string.Empty; string protectedItemName = "PE" + (new Random()).Next(); // Data Variables Fabric selectedFabric = null; ProtectionContainer primaryCloud = null; Policy selectedPolicy = null; ProtectableItem protectableItem = null; ReplicationProtectedItem protectedItem = null; // Fetch HyperV if (string.IsNullOrEmpty(fabricName)) { var fabrics = client.Fabrics.List(RequestHeaders); foreach (var fabric in fabrics.Fabrics) { if (fabric.Properties.CustomDetails.InstanceType.Contains("HyperV")) { selectedFabric = fabric; fabricName = selectedFabric.Name; } } } else { selectedFabric = client.Fabrics.Get(fabricName, RequestHeaders).Fabric; } // Fetch Cloud primaryCloud = client.ProtectionContainer.List(selectedFabric.Name, RequestHeaders).ProtectionContainers[0]; priCldName = primaryCloud.Name; if (createPolicy) { HyperVReplicaAzurePolicyInput hvrAPolicy = new HyperVReplicaAzurePolicyInput() { ApplicationConsistentSnapshotFrequencyInHours = 0, Encryption = "Disable", OnlineIrStartTime = null, RecoveryPointHistoryDuration = 0, ReplicationInterval = 30, StorageAccounts = new List <string>() { "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/storageAccounts/bvtmapped2storacc" } }; CreatePolicyInputProperties createInputProp = new CreatePolicyInputProperties() { ProviderSpecificInput = hvrAPolicy }; CreatePolicyInput policyInput = new CreatePolicyInput() { Properties = createInputProp }; selectedPolicy = (client.Policies.Create(policyName, policyInput, RequestHeaders) as CreatePolicyOperationResponse).Policy; } else { selectedPolicy = client.Policies.Get(policyName, RequestHeaders).Policy; } if (pairClouds) { CreateProtectionContainerMappingInputProperties pairingProps = new CreateProtectionContainerMappingInputProperties() { PolicyId = selectedPolicy.Id, TargetProtectionContainerId = recCldName, ProviderSpecificInput = new ReplicationProviderContainerMappingInput() }; CreateProtectionContainerMappingInput pairingInput = new CreateProtectionContainerMappingInput() { Properties = pairingProps }; var pairingResponse = client.ProtectionContainerMapping.ConfigureProtection( selectedFabric.Name, primaryCloud.Name, mappingName, pairingInput, RequestHeaders); } if (enableDR) { if (string.IsNullOrEmpty(enableDRName)) { protectableItem = client.ProtectableItem.List(selectedFabric.Name, primaryCloud.Name, "Unprotected", RequestHeaders).ProtectableItems[0]; enableDRName = protectableItem.Name; } else { protectableItem = client.ProtectableItem.Get(selectedFabric.Name, primaryCloud.Name, enableDRName, RequestHeaders).ProtectableItem; } HyperVReplicaAzureEnableProtectionInput hvrAEnableDRInput = new HyperVReplicaAzureEnableProtectionInput() { HvHostVmId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId, OSType = "Windows", VhdId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList[0].VhdId, VmName = protectableItem.Properties.FriendlyName, TargetStorageAccountId = "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/storageAccounts/bvtmapped2storacc", }; EnableProtectionInputProperties enableDRProp = new EnableProtectionInputProperties() { PolicyId = selectedPolicy.Id, ProtectableItemId = protectableItem.Id, ProviderSpecificDetails = hvrAEnableDRInput }; EnableProtectionInput enableDRInput = new EnableProtectionInput() { Properties = enableDRProp }; DateTime enablStartTime = DateTime.UtcNow; protectedItem = ( client.ReplicationProtectedItem.EnableProtection( selectedFabric.Name, primaryCloud.Name, protectedItemName, enableDRInput, RequestHeaders) as ReplicationProtectedItemOperationResponse).ReplicationProtectedItem; MonitoringHelper.MonitorJobs(MonitoringHelper.AzureIrJobName, enablStartTime, client, RequestHeaders); } if (pfo || commit || tfo || pfoReverse || commitReverse || reprotect || disableDR) { protectableItem = client.ProtectableItem.Get(selectedFabric.Name, primaryCloud.Name, enableDRName, RequestHeaders).ProtectableItem; protectedItem = client.ReplicationProtectedItem.Get(selectedFabric.Name, primaryCloud.Name, protectedItemName, RequestHeaders).ReplicationProtectedItem; // Create Input for Operations ///////////////////////////// PFO ///////////////////////////////////// HyperVReplicaAzureFailoverProviderInput hvrAFOInput = new HyperVReplicaAzureFailoverProviderInput() { VaultLocation = "West US", }; PlannedFailoverInputProperties plannedFailoverProp = new PlannedFailoverInputProperties() { FailoverDirection = "", ProviderSpecificDetails = hvrAFOInput }; PlannedFailoverInput plannedFailoverInput = new PlannedFailoverInput() { Properties = plannedFailoverProp }; HyperVReplicaAzureFailbackProviderInput hvrAFBInput = new HyperVReplicaAzureFailbackProviderInput() { RecoveryVmCreationOption = "NoAction", DataSyncOption = "ForSyncronization" }; PlannedFailoverInputProperties plannedFailbackProp = new PlannedFailoverInputProperties() { FailoverDirection = "", ProviderSpecificDetails = hvrAFBInput }; PlannedFailoverInput plannedFailbackInput = new PlannedFailoverInput() { Properties = plannedFailbackProp }; ////////////////////////////// Reprotect ////////////////////////////////////// HyperVReplicaAzureReprotectInput hvrARRInput = new HyperVReplicaAzureReprotectInput() { HvHostVmId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId, OSType = "Windows", VHDId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList[0].VhdId, VmName = protectableItem.Properties.FriendlyName, StorageAccountId = "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/storageAccounts/bvtmapped2storacc", }; ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties() { FailoverDirection = "", ProviderSpecificDetails = hvrARRInput }; ReverseReplicationInput rrInput = new ReverseReplicationInput() { Properties = rrProp }; ////////////////////////////////// UFO ///////////////////////////////////////// UnplannedFailoverInputProperties ufoProp = new UnplannedFailoverInputProperties() { ProviderSpecificDetails = hvrAFOInput, SourceSiteOperations = "NotRequired" }; UnplannedFailoverInput ufoInput = new UnplannedFailoverInput() { Properties = ufoProp }; /////////////////////////////////// TFO ///////////////////////////////////////////// TestFailoverInputProperties tfoProp = new TestFailoverInputProperties() { ProviderSpecificDetails = hvrAFOInput }; TestFailoverInput tfoInput = new TestFailoverInput() { Properties = tfoProp }; ////////////////////////////////////////////////////////////////////////////////////////// if (pfo) { var plannedfailover = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, plannedFailoverInput, RequestHeaders); } if (commit) { var commitFailover = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, RequestHeaders); } if (pfoReverse) { //var unplannedFailoverReverse = client.ReplicationProtectedItem.UnplannedFailover(selectedFabric.Name, priCld, replicationProtectedItems.ReplicationProtectedItems[0].Name, ufoInput, RequestHeaders); var plannedFailoverReverse = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, plannedFailbackInput, RequestHeaders); } if (commitReverse) { var commitFailoverReverse = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, RequestHeaders); } if (reprotect) { var reprotectStartTime = DateTime.UtcNow; var rrReverseOp = client.ReplicationProtectedItem.Reprotect(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, rrInput, RequestHeaders); MonitoringHelper.MonitorJobs(MonitoringHelper.AzureIrJobName, reprotectStartTime, client, RequestHeaders); } if (tfo) { DateTime startTFO = DateTime.UtcNow; var tfoOp = client.ReplicationProtectedItem.TestFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, 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, primaryCloud.Name, protectedItem.Name, new DisableProtectionInput(), RequestHeaders); } if (unpair) { var unpairClouds = client.ProtectionContainerMapping.UnconfigureProtection( selectedFabric.Name, primaryCloud.Name, mappingName, new RemoveProtectionContainerMappingInput(), RequestHeaders); } } if (removePolicy) { var policyDeletion = client.Policies.Delete(selectedPolicy.Name, RequestHeaders); } } }