/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteSiteRecoveryCmdlet() { base.ExecuteSiteRecoveryCmdlet(); if (ShouldProcess(this.ProtectionContainerMapping.Name, VerbsCommon.Remove)) { LongRunningOperationResponse response = null; if (!this.Force.IsPresent) { RemoveProtectionContainerMappingInputProperties inputProperties = new RemoveProtectionContainerMappingInputProperties() { ProviderSpecificInput = new ReplicationProviderContainerUnmappingInput() }; RemoveProtectionContainerMappingInput input = new RemoveProtectionContainerMappingInput() { Properties = inputProperties }; response = RecoveryServicesClient.UnConfigureProtection( Utilities.GetValueFromArmId(this.ProtectionContainerMapping.ID, ARMResourceTypeConstants.ReplicationFabrics), Utilities.GetValueFromArmId(this.ProtectionContainerMapping.ID, ARMResourceTypeConstants.ReplicationProtectionContainers), this.ProtectionContainerMapping.Name, input); } else { response = RecoveryServicesClient.PurgeCloudMapping( Utilities.GetValueFromArmId(this.ProtectionContainerMapping.ID, ARMResourceTypeConstants.ReplicationFabrics), Utilities.GetValueFromArmId(this.ProtectionContainerMapping.ID, ARMResourceTypeConstants.ReplicationProtectionContainers), this.ProtectionContainerMapping.Name); } JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse.Job)); } }
/// <summary> /// Helper to configure cloud /// </summary> private void Dissociate(string targetProtectionContainerId) { RemoveProtectionContainerMappingInputProperties inputProperties = new RemoveProtectionContainerMappingInputProperties() { ProviderSpecificInput = new ReplicationProviderContainerUnmappingInput() }; RemoveProtectionContainerMappingInput input = new RemoveProtectionContainerMappingInput() { Properties = inputProperties }; ProtectionContainerMappingListResponse protectionContainerMappingListResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainerMapping(Utilities.GetValueFromArmId(PrimaryProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics), PrimaryProtectionContainer.Name); ProtectionContainerMapping protectionContainerMapping = protectionContainerMappingListResponse.ProtectionContainerMappings.SingleOrDefault(t => (t.Properties.PolicyId.CompareTo(this.Policy.ID) == 0 && t.Properties.TargetProtectionContainerId.CompareTo(targetProtectionContainerId) == 0)); if (protectionContainerMapping == null) { throw new Exception("Cloud is not paired"); } LongRunningOperationResponse response = RecoveryServicesClient.UnConfigureProtection(Utilities.GetValueFromArmId(this.PrimaryProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics), this.PrimaryProtectionContainer.Name, protectionContainerMapping.Name, input); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse.Job)); }