public void RP_PFO_Failback_Test() { using (UndoContext context = UndoContext.Current) { context.Start(); var client = GetSiteRecoveryClient(CustomHttpHandler); var requestHeaders = RequestHeaders; requestHeaders.AgentAuthenticationHeader = GenerateAgentAuthenticationHeader(requestHeaders.ClientRequestId); var responseRP = client.RecoveryPlan.List(RequestHeaders); JobResponse response = new JobResponse(); foreach (var rp in responseRP.RecoveryPlans) { RpPlannedFailoverRequest request = new RpPlannedFailoverRequest(); request.FailoverDirection = "RecoveryToPrimary"; request.ReplicationProvider = "HyperVReplicaAzure"; AzureFailbackInput fbInput = new AzureFailbackInput(); fbInput.CreateRecoveryVmIfDoesntExist = true; fbInput.SkipDataSync = true; request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailbackInput> (fbInput); response = client.RecoveryPlan.RecoveryPlanPlannedFailover( rp.ID, request, requestHeaders); } Assert.NotNull(response.Job); Assert.NotNull(response.Job.ID); Assert.True(response.Job.Errors.Count < 1, "Errors found while doing planned failover operation"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { this.WriteWarningWithTimestamp( string.Format( Properties.Resources.CmdletWillBeDeprecatedSoon, this.MyInvocation.MyCommand.Name)); string recoveryPlanXml = System.IO.File.ReadAllText(this.File); this.jobResponse = RecoveryServicesClient.UpdateAzureSiteRecoveryRecoveryPlan( recoveryPlanXml); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { this.jobResponse = RecoveryServicesClient .RemoveAzureSiteRecoveryNetworkMapping( this.NetworkMapping.PrimaryServerId, this.NetworkMapping.PrimaryNetworkId, this.NetworkMapping.RecoveryServerId); this.WriteJob(this.jobResponse.Job); } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { string recoveryPlanXml = FileUtilities.DataStore.ReadFileAsText(this.File); this.jobResponse = RecoveryServicesClient.CreateAzureSiteRecoveryRecoveryPlan( recoveryPlanXml); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { this.jobResponse = RecoveryServicesClient .NewAzureSiteRecoveryStorageMapping( this.PrimaryStorage.ServerId, this.PrimaryStorage.ID, this.RecoveryStorage.ServerId, this.RecoveryStorage.ID); this.WriteJob(this.jobResponse.Job); } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { string recoveryPlanXml = System.IO.File.ReadAllText(this.File); this.jobResponse = RecoveryServicesClient.UpdateAzureSiteRecoveryRecoveryPlan( recoveryPlanXml); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } } catch (Exception exception) { this.HandleException(exception); } }
public void SyncOwnerInformationTest() { using (UndoContext context = UndoContext.Current) { context.Start(); var client = GetSiteRecoveryClient(CustomHttpHandler); var requestHeaders = RequestHeaders; requestHeaders.AgentAuthenticationHeader = GenerateAgentAuthenticationHeader(requestHeaders.ClientRequestId); var responsePC = client.ProtectionContainer.List(RequestHeaders); JobResponse response = new JobResponse(); bool desiredPEFound = false; foreach (var pc in responsePC.ProtectionContainers) { var responsePEs = client.ProtectionEntity.List(pc.ID, RequestHeaders); response = null; foreach (var pe in responsePEs.ProtectionEntities) { if (pe.Protected == true) { response = client.ProtectionEntity.SyncOwnerInformation(pe.ProtectionContainerId, pe.ID, requestHeaders); desiredPEFound = true; break; } } if (desiredPEFound) { break; } } Assert.NotNull(response.Job); Assert.NotNull(response.Job.ID); Assert.True(response.Job.Errors.Count < 1, "Errors found while doing Sync Owner Information operation"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { this.WriteWarningWithTimestamp( string.Format( Properties.Resources.CmdletWillBeDeprecatedSoon, this.MyInvocation.MyCommand.Name)); this.jobResponse = RecoveryServicesClient .RemoveAzureSiteRecoveryNetworkMapping( this.NetworkMapping.PrimaryServerId, this.NetworkMapping.PrimaryNetworkId, this.NetworkMapping.RecoveryServerId); this.WriteJob(this.jobResponse.Job); } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// Starts PE Test failover. /// </summary> private void StartPETestFailover() { var request = new TestFailoverRequest(); if (this.ProtectionEntity == null) { var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionContainerId, this.ProtectionEntityId); this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity); this.ValidateUsageById( this.ProtectionEntity.ReplicationProvider, Constants.ProtectionEntityId); } request.ReplicationProviderSettings = string.Empty; if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure) { if (this.Direction == Constants.PrimaryToRecovery) { var blob = new AzureFailoverInput(); blob.VaultLocation = this.GetCurrentValutLocation(); request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput>(blob); } } request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider; request.FailoverDirection = this.Direction; request.NetworkID = this.networkId; request.NetworkType = this.networkType; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.ProtectionContainerId, this.ProtectionEntityId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Enterprise to enterprise network mapping. /// </summary> private void EnterpriseToEnterpriseNetworkMapping() { this.jobResponse = RecoveryServicesClient .NewAzureSiteRecoveryNetworkMapping( this.PrimaryNetwork.ServerId, this.PrimaryNetwork.ID, this.RecoveryNetwork.ServerId, this.RecoveryNetwork.ID); this.WriteJob(this.jobResponse.Job); }
protected void ValidateResponse(JobResponse response) { Assert.NotNull(response.Job); Assert.NotNull(response.Job.ID); Assert.True(response.Job.Errors.Count < 1, "Errors found while doing planned failover operation"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
/// <summary> /// Associates protection profile with one enterprise based and an Azure protection container /// </summary> private void EnterpriseToAzureAssociation() { if (string.Compare( this.ProtectionProfile.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Properties.Resources.IncorrectReplicationProvider, this.ProtectionProfile.ReplicationProvider)); } HyperVReplicaAzureProtectionProfileInput hyperVReplicaAzureProtectionProfileInput = new HyperVReplicaAzureProtectionProfileInput() { ApplicationConsistentSnapshotFrequencyInHours = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ApplicationConsistentSnapshotFrequencyInHours, ReplicationInterval = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationFrequencyInSeconds, OnlineReplicationStartTime = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationStartTime, RecoveryPointHistoryDuration = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryPoints, EncryptionEnabled = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.EncryptStoredData }; var storageAccount = new CustomerStorageAccount(); storageAccount.StorageAccountName = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureStorageAccountName; storageAccount.SubscriptionId = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureSubscription; hyperVReplicaAzureProtectionProfileInput.StorageAccounts = new System.Collections.Generic.List<CustomerStorageAccount>(); hyperVReplicaAzureProtectionProfileInput.StorageAccounts.Add(storageAccount); CreateProtectionProfileInput createProtectionProfileInput = new CreateProtectionProfileInput( string.IsNullOrEmpty(this.ProtectionProfile.Name) ? this.PrimaryProtectionContainer.Name : this.ProtectionProfile.Name, this.ProtectionProfile.ReplicationProvider, DataContractUtils<HyperVReplicaAzureProtectionProfileInput>.Serialize(hyperVReplicaAzureProtectionProfileInput)); ProtectionProfileAssociationInput protectionProfileAssociationInput = new ProtectionProfileAssociationInput( this.PrimaryProtectionContainer.ID, Constants.AzureContainer); CreateAndAssociateProtectionProfileInput createAndAssociateProtectionProfileInput = new CreateAndAssociateProtectionProfileInput( createProtectionProfileInput, protectionProfileAssociationInput); this.jobResponse = RecoveryServicesClient.StartCreateAndAssociateAzureSiteRecoveryProtectionProfileJob( createAndAssociateProtectionProfileInput); this.WriteJob(this.jobResponse.Job); }
/// <summary> /// Enterprise to Azure network mapping. /// </summary> private void EnterpriseToAzureNetworkMapping() { // Verify whether the subscription is associated with the account or not. RecoveryServicesClient.ValidateSubscriptionAccountAssociation(this.AzureSubscriptionId); // Check if the Azure VM Network is associated with the Subscription or not. string azureVMNetworkName; RecoveryServicesClient.ValidateVMNetworkSubscriptionAssociation( this.AzureSubscriptionId, this.AzureVMNetworkId, out azureVMNetworkName); this.jobResponse = RecoveryServicesClient .NewAzureSiteRecoveryAzureNetworkMapping( this.PrimaryNetwork.ServerId, this.PrimaryNetwork.ID, azureVMNetworkName, this.AzureVMNetworkId); this.WriteJob(this.jobResponse.Job); }
public void RP_TFO_E2A_Test() { using (UndoContext context = UndoContext.Current) { context.Start(); var client = GetSiteRecoveryClient(CustomHttpHandler); var requestHeaders = RequestHeaders; requestHeaders.AgentAuthenticationHeader = GenerateAgentAuthenticationHeader(requestHeaders.ClientRequestId); var responseRP = client.RecoveryPlan.List(RequestHeaders); JobResponse response = new JobResponse(); foreach (var rp in responseRP.RecoveryPlans) { RpTestFailoverRequest request = new RpTestFailoverRequest(); request.NetworkID = "ID"; request.NetworkType = "Type"; request.FailoverDirection = "PrimaryToRecovery"; request.ReplicationProvider = "HyperVReplicaAzure"; AzureFailoverInput foInput = new AzureFailoverInput(); foInput.VaultLocation = VaultLocation; request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput> (foInput); response = client.RecoveryPlan.RecoveryPlanTestFailover( rp.ID, request, requestHeaders); } Assert.NotNull(response.Job); Assert.NotNull(response.Job.ID); Assert.True(response.Job.Errors.Count < 1, "Errors found while doing unplanned failover operation"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
/// <summary> /// Associates protection profile with enterprise based protection containers /// </summary> private void EnterpriseToEnterpriseAssociation() { if (string.Compare( this.ProtectionProfile.ReplicationProvider, Constants.HyperVReplica, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Properties.Resources.IncorrectReplicationProvider, this.ProtectionProfile.ReplicationProvider)); } HyperVReplicaProtectionProfileInput hyperVReplicaProtectionProfileInput = new HyperVReplicaProtectionProfileInput() { ApplicationConsistentSnapshotFrequencyInHours = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.ApplicationConsistentSnapshotFrequencyInHours, ReplicationFrequencyInSeconds = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.ReplicationFrequencyInSeconds, OnlineReplicationStartTime = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.ReplicationStartTime, CompressionEnabled = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.CompressionEnabled, OnlineReplicationMethod = (string.Compare(this.ProtectionProfile.HyperVReplicaProviderSettingsObject.ReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0) ? true : false, RecoveryPoints = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.RecoveryPoints, ReplicationPort = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.ReplicationPort, AllowReplicaDeletion = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.AllowReplicaDeletion, AllowedAuthenticationType = (ushort)((string.Compare(this.ProtectionProfile.HyperVReplicaProviderSettingsObject.Authentication, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0) ? 1 : 2), }; CreateProtectionProfileInput createProtectionProfileInput = new CreateProtectionProfileInput( //// Name of the protection profile as the name of the protection container if not given string.IsNullOrEmpty(this.ProtectionProfile.Name) ? this.PrimaryProtectionContainer.Name : this.ProtectionProfile.Name, this.ProtectionProfile.ReplicationProvider, DataContractUtils<HyperVReplicaProtectionProfileInput>.Serialize(hyperVReplicaProtectionProfileInput)); ProtectionProfileAssociationInput protectionProfileAssociationInput = new ProtectionProfileAssociationInput( this.PrimaryProtectionContainer.ID, this.RecoveryProtectionContainer.ID); CreateAndAssociateProtectionProfileInput createAndAssociateProtectionProfileInput = new CreateAndAssociateProtectionProfileInput( createProtectionProfileInput, protectionProfileAssociationInput); this.jobResponse = RecoveryServicesClient.StartCreateAndAssociateAzureSiteRecoveryProtectionProfileJob( createAndAssociateProtectionProfileInput); this.WriteJob(this.jobResponse.Job); }
/// <summary> /// Start PE Commit. /// </summary> private void SetPECommit() { var request = new CommitFailoverRequest(); if (this.ProtectionEntity == null) { var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionContainerId, this.ProtectionEntityId); this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity); this.ValidateUsageById( this.ProtectionEntity.ReplicationProvider, Constants.ProtectionEntityId); } request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider; request.ReplicationProviderSettings = string.Empty; if (this.ProtectionEntity.ActiveLocation == Constants.PrimaryLocation) { request.FailoverDirection = Constants.RecoveryToPrimary; } else { request.FailoverDirection = Constants.PrimaryToRecovery; } this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover( this.ProtectionContainerId, this.ProtectionEntityId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Sets RP Commit. /// </summary> private void SetRpCommit() { this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover( this.RPId); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Start PE Commit. /// </summary> private void SetPECommit() { this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover( this.ProtectionContainerId, this.ProtectionEntityId); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Starts RP test failover. /// </summary> private void StartRpTestFailover() { RpTestFailoverRequest recoveryPlanTestFailoverRequest = new RpTestFailoverRequest(); recoveryPlanTestFailoverRequest.FailoverDirection = this.Direction; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.RpId, recoveryPlanTestFailoverRequest); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Starts PE Unplanned failover. /// </summary> private void StartPEUnplannedFailover() { var ufoReqeust = new UnplannedFailoverRequest(); ufoReqeust.FailoverDirection = this.Direction; ufoReqeust.SourceSiteOperations = this.PerformSourceSiteOperations; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover( this.ProtectionContainerId, this.ProtectionEntityId, ufoReqeust); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { // Check for at least one option if (string.IsNullOrEmpty(this.Name) && string.IsNullOrEmpty(this.Size) && string.IsNullOrEmpty(this.PrimaryNic) && string.IsNullOrEmpty(this.RecoveryNetworkId)) { this.WriteWarning(Properties.Resources.ArgumentsMissingForUpdateVmProperties.ToString()); return; } // Both primary & recovery inputs should be present if (string.IsNullOrEmpty(this.PrimaryNic) ^ string.IsNullOrEmpty(this.RecoveryNetworkId)) { this.WriteWarning(Properties.Resources.NetworkArgumentsMissingForUpdateVmProperties.ToString()); return; } UpdateVmPropertiesInput updateVmPropertiesInput = new UpdateVmPropertiesInput(); updateVmPropertiesInput.RecoveryAzureVmGivenName = this.Name; updateVmPropertiesInput.RecoveryAzureVmSize = this.Size; updateVmPropertiesInput.SelectedPrimaryNicId = this.PrimaryNic; updateVmPropertiesInput.RecoveryAzureNetworkId = this.RecoveryNetworkId; this.jobResponse = RecoveryServicesClient.UpdateVmProperties( this.VirtualMachine.ProtectionContainerId, this.VirtualMachine.ID, updateVmPropertiesInput); this.WriteJob(this.jobResponse.Job); }
/// <summary> /// Starts RP Planned failover. /// </summary> private void StartRpUnPlannedFailover() { RpUnplannedFailoverRequest request = new RpUnplannedFailoverRequest(); if (this.RecoveryPlan == null) { var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan( this.RPId); this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan); this.ValidateUsageById( this.RecoveryPlan.ReplicationProvider, Constants.RPId); } request.ReplicationProviderSettings = string.Empty; if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure) { request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider; if (this.Direction == Constants.PrimaryToRecovery) { var blob = new AzureFailoverInput(); blob.VaultLocation = this.GetCurrentValutLocation(); request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput>(blob); } } request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider; request.FailoverDirection = this.Direction; request.PrimaryAction = this.PerformSourceSideActions; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover( this.RPId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Starts PE Test failover. /// </summary> private void StartPETestFailover() { var tfoReqeust = new TestFailoverRequest(); tfoReqeust.NetworkID = this.networkId; tfoReqeust.FailoverDirection = this.Direction; tfoReqeust.NetworkType = this.networkType; tfoReqeust.ReplicationProvider = string.Empty; tfoReqeust.ReplicationProviderSettings = string.Empty; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.ProtectionContainerId, this.ProtectionEntityId, tfoReqeust); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { switch (this.ParameterSetName) { case ASRParameterSets.ByPEObject: this.Id = this.ProtectionEntity.ID; this.ProtectionContainerId = this.ProtectionEntity.ProtectionContainerId; this.targetNameOrId = this.ProtectionEntity.Name; this.alreadyEnabled = this.ProtectionEntity.Protected; break; case ASRParameterSets.ByIDs: this.targetNameOrId = this.Id; ProtectionEntityResponse protectionEntityResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionContainerId, this.Id); this.alreadyEnabled = protectionEntityResponse.ProtectionEntity.Protected; this.targetNameOrId = protectionEntityResponse.ProtectionEntity.Name; break; } if (this.alreadyEnabled && this.Protection.Equals(Constants.EnableProtection, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException( string.Format( Properties.Resources.ProtectionEntityAlreadyEnabled, this.targetNameOrId)); } else if (!this.alreadyEnabled && this.Protection.Equals(Constants.DisableProtection, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException( Properties.Resources.ProtectionEntityAlreadyDisabled, this.targetNameOrId); } this.ConfirmAction( this.Force.IsPresent || 0 != string.CompareOrdinal(this.Protection, Constants.DisableProtection), string.Format(Properties.Resources.DisableProtectionWarning, this.targetNameOrId), string.Format(Properties.Resources.DisableProtectionWhatIfMessage, this.Protection), this.targetNameOrId, () => { try { if (this.Protection == Constants.EnableProtection) { string profileId = string.Empty; var input = new EnableProtectionInput(); if (this.ProtectionEntity == null) { var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionContainerId, this.Id); this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity); } // Get the replciation provider from profile object otherwise assume its E2E. // Let the call go without profileId set. string replicationProvider = null; if (this.ProtectionProfile != null) { profileId = this.ProtectionProfile.ID; replicationProvider = this.ProtectionProfile.ReplicationProvider; } else { string pcId = this.ProtectionContainerId ?? this.ProtectionEntity.ProtectionContainerId; var pc = RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainer( pcId); // PC will have all profiles associated with same replciation providers only. replicationProvider = pc.ProtectionContainer.AvailableProtectionProfiles.Count < 1 ? null : pc.ProtectionContainer.AvailableProtectionProfiles[0].ReplicationProvider; if (replicationProvider != Constants.HyperVReplica) { throw new Exception("Please provide the protection profile object. It can be chosen from available protection profiles of the protection container."); } } if (this.ParameterSetName == ASRParameterSets.ByIDs) { this.ValidateUsageById(replicationProvider, "Id"); } if (replicationProvider == Constants.HyperVReplicaAzure) { input.ProtectionProfileId = this.ProtectionProfile.ID; AzureEnableProtectionInput azureInput = new AzureEnableProtectionInput(); azureInput.HvHostVmId = this.ProtectionEntity.FabricObjectId; azureInput.VmName = this.ProtectionEntity.Name; azureInput.OSType = this.OS; if (string.IsNullOrWhiteSpace(this.OS)) { azureInput.OSType = this.ProtectionEntity.OS; } if (string.IsNullOrWhiteSpace(this.OSDiskName)) { azureInput.VHDId = this.ProtectionEntity.OSDiskId; } else { foreach (var disk in this.ProtectionEntity.Disks) { if (disk.Name == this.OSDiskName) { azureInput.VHDId = disk.Id; break; } } } input.ReplicationProviderInput = DataContractUtils.Serialize<AzureEnableProtectionInput>(azureInput); } else if (string.IsNullOrWhiteSpace(profileId)) { input = null; } else { input.ReplicationProviderInput = string.Empty; input.ProtectionProfileId = profileId; } this.jobResponse = RecoveryServicesClient.EnableProtection( this.ProtectionContainerId, this.Id, input); } else { this.jobResponse = RecoveryServicesClient.DisbleProtection( this.ProtectionContainerId, this.Id); } this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } } catch (Exception exception) { this.HandleException(exception); } }); }
/// <summary> /// Sets RP Commit. /// </summary> private void SetRpCommit() { var request = new CommitFailoverRequest(); if (this.RecoveryPlan == null) { var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan( this.RPId); this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan); this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider, "RPId"); } request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider; request.ReplicationProviderSettings = string.Empty; request.FailoverDirection = this.Direction; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover( this.RPId); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Set PE protection. /// </summary> private void SetPEReprotect() { if ((this.Direction == Constants.PrimaryToRecovery && this.ProtectionEntity.ActiveLocation == Constants.RecoveryLocation) || (this.Direction == Constants.RecoveryToPrimary && this.ProtectionEntity.ActiveLocation == Constants.PrimaryLocation)) { throw new ArgumentException("Parameter value is not correct.", "Direction"); } var request = new ReprotectRequest(); if (this.ProtectionEntity == null) { var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionContainerId, this.ProtectionEntityId); this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity); this.ValidateUsageById( this.ProtectionEntity.ReplicationProvider, this.ProtectionEntityId); } request.ReplicationProviderSettings = string.Empty; if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure) { if (this.Direction == Constants.PrimaryToRecovery) { var blob = new AzureReProtectionInput(); blob.HvHostVmId = this.ProtectionEntity.FabricObjectId; blob.VmName = this.ProtectionEntity.Name; blob.OSType = this.ProtectionEntity.OS; blob.VHDId = this.ProtectionEntity.OSDiskId; request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureReProtectionInput>(blob); } } request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider; request.FailoverDirection = this.Direction; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryReprotection( this.ProtectionContainerId, this.ProtectionEntityId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Syncs the owner information. /// </summary> private void SyncOwnerInformationOnPE() { this.jobResponse = RecoveryServicesClient.UpdateAzureSiteRecoveryProtectionEntity( this.protectionContainerId, this.protectionEntityId); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { this.WriteWarningWithTimestamp( string.Format( Properties.Resources.CmdletWillBeDeprecatedSoon, this.MyInvocation.MyCommand.Name)); string recoveryContainerId = string.Empty; switch (this.ParameterSetName) { case ASRParameterSets.EnterpriseToAzure: if (this.ProtectionProfile.ReplicationProvider != Constants.HyperVReplicaAzure) { throw new Exception("Please provide recovery container object."); } else { recoveryContainerId = Constants.AzureContainer; } break; case ASRParameterSets.EnterpriseToEnterprise: recoveryContainerId = this.RecoveryProtectionContainer.ID; break; } ProtectionProfileAssociationInput protectionProfileAssociationInput = new ProtectionProfileAssociationInput( this.PrimaryProtectionContainer.ID, recoveryContainerId); this.jobResponse = RecoveryServicesClient.StartDeleteAndDissociateAzureSiteRecoveryProtectionProfileJob( this.ProtectionProfile.ID, protectionProfileAssociationInput); this.WriteJob(this.jobResponse.Job); } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { switch (this.ParameterSetName) { case ASRParameterSets.ByRPObject: this.Id = this.RecoveryPlan.ID; this.targetNameOrId = this.RecoveryPlan.Name; break; case ASRParameterSets.ById: this.targetNameOrId = this.Id; break; } this.ConfirmAction( this.Force.IsPresent, string.Format(Properties.Resources.RemoveRPWarning, this.targetNameOrId), Properties.Resources.RemoveRPWhatIfMessage, this.targetNameOrId, () => { try { this.jobResponse = RecoveryServicesClient.RemoveAzureSiteRecoveryRecoveryPlan( this.Id); this.WriteJob(this.jobResponse.Job); string jobId = this.jobResponse.Job.ID; if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } } catch (Exception exception) { this.HandleException(exception); } }); }
/// <summary> /// Starts RP Planned failover. /// </summary> private void StartRpPlannedFailover() { RpPlannedFailoverRequest request = new RpPlannedFailoverRequest(); if (this.RecoveryPlan == null) { var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan( this.RPId); this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan); this.ValidateUsageById( this.RecoveryPlan.ReplicationProvider, Constants.RPId); } if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure) { if (this.Direction == Constants.PrimaryToRecovery) { var blob = new AzureFailoverInput(); blob.VaultLocation = this.GetCurrentValutLocation(); request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput>(blob); } else { var blob = new AzureFailbackInput(); blob.CreateRecoveryVmIfDoesntExist = false; blob.SkipDataSync = this.Optimize == Constants.ForDowntime ? true : false; request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailbackInput>(blob); } } request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider; request.FailoverDirection = this.Direction; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover( this.RPId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }