/// <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> /// UnPair Cloud /// </summary> /// <param name="fabricName">Fabric Name</param> /// <param name="protectionContainerName">Protection Container Input</param> /// <param name="mappingName">Mapping Name</param> /// <param name="input">UnPairing input</param> /// <returns></returns> public LongRunningOperationResponse UnConfigureProtection(string fabricName, string protectionContainerName, string mappingName, RemoveProtectionContainerMappingInput input) { return this.GetSiteRecoveryClient().ProtectionContainerMapping.BeginUnconfigureProtection(fabricName, protectionContainerName, mappingName, input, this.GetRequestHeaders()); }
/// <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)); }
/// <summary> /// Unconfigures protection for given protection container /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.SiteRecovery.IProtectionContainerMappingOperations. /// </param> /// <param name='fabricName'> /// Required. Fabric name. /// </param> /// <param name='protectionContainerName'> /// Required. Protection container name. /// </param> /// <param name='mappingName'> /// Required. Container mapping name. /// </param> /// <param name='input'> /// Required. Unconfigure protection input. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static Task<LongRunningOperationResponse> UnconfigureProtectionAsync(this IProtectionContainerMappingOperations operations, string fabricName, string protectionContainerName, string mappingName, RemoveProtectionContainerMappingInput input, CustomRequestHeaders customRequestHeaders) { return operations.UnconfigureProtectionAsync(fabricName, protectionContainerName, mappingName, input, customRequestHeaders, CancellationToken.None); }
/// <summary> /// Unconfigures protection for given protection container /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.SiteRecovery.IProtectionContainerMappingOperations. /// </param> /// <param name='fabricName'> /// Required. Fabric name. /// </param> /// <param name='protectionContainerName'> /// Required. Protection container name. /// </param> /// <param name='mappingName'> /// Required. Container mapping name. /// </param> /// <param name='input'> /// Required. Unconfigure protection input. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static LongRunningOperationResponse UnconfigureProtection(this IProtectionContainerMappingOperations operations, string fabricName, string protectionContainerName, string mappingName, RemoveProtectionContainerMappingInput input, CustomRequestHeaders customRequestHeaders) { return Task.Factory.StartNew((object s) => { return ((IProtectionContainerMappingOperations)s).UnconfigureProtectionAsync(fabricName, protectionContainerName, mappingName, input, customRequestHeaders); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }