/// <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>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(
                    this.InputObject.Name,
                    VerbsCommon.Remove))
            {
                PSSiteRecoveryLongRunningOperation response = null;

                if (!this.Force.IsPresent)
                {
                    var inputProperties = new RemoveProtectionContainerMappingInputProperties
                    {
                        ProviderSpecificInput = new ReplicationProviderContainerUnmappingInput()
                    };

                    var input =
                        new RemoveProtectionContainerMappingInput {
                        Properties = inputProperties
                    };

                    response = this.RecoveryServicesClient.UnConfigureProtection(
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationFabrics),
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationProtectionContainers),
                        this.InputObject.Name,
                        input);
                }
                else
                {
                    response = this.RecoveryServicesClient.PurgeCloudMapping(
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationFabrics),
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationProtectionContainers),
                        this.InputObject.Name);
                }

                var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                    PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

                this.WriteObject(new ASRJob(jobResponse));
            }
        }
        /// <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 PSSiteRecoveryLongRunningOperation UnConfigureProtection(
            string fabricName,
            string protectionContainerName,
            string mappingName,
            RemoveProtectionContainerMappingInput input)
        {
            var op = this.GetSiteRecoveryClient()
                     .ReplicationProtectionContainerMappings.BeginDeleteWithHttpMessagesAsync(
                fabricName,
                protectionContainerName,
                mappingName,
                input,
                this.GetRequestHeaders(true))
                     .GetAwaiter()
                     .GetResult();
            var result = SiteRecoveryAutoMapperProfile.Mapper.Map <PSSiteRecoveryLongRunningOperation>(op);

            return(result);
        }
 /// <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()));
 }
示例#5
0
 /// <summary>
 /// Remove protection container mapping.
 /// </summary>
 /// <remarks>
 /// The operation to delete or remove a protection container mapping.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='fabricName'>
 /// Fabric name.
 /// </param>
 /// <param name='protectionContainerName'>
 /// Protection container name.
 /// </param>
 /// <param name='mappingName'>
 /// Protection container mapping name.
 /// </param>
 /// <param name='removalInput'>
 /// Removal input.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task BeginDeleteAsync(this IReplicationProtectionContainerMappingsOperations operations, string fabricName, string protectionContainerName, string mappingName, RemoveProtectionContainerMappingInput removalInput, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.BeginDeleteWithHttpMessagesAsync(fabricName, protectionContainerName, mappingName, removalInput, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
示例#6
0
 /// <summary>
 /// Remove protection container mapping.
 /// </summary>
 /// <remarks>
 /// The operation to delete or remove a protection container mapping.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='fabricName'>
 /// Fabric name.
 /// </param>
 /// <param name='protectionContainerName'>
 /// Protection container name.
 /// </param>
 /// <param name='mappingName'>
 /// Protection container mapping name.
 /// </param>
 /// <param name='removalInput'>
 /// Removal input.
 /// </param>
 public static void BeginDelete(this IReplicationProtectionContainerMappingsOperations operations, string fabricName, string protectionContainerName, string mappingName, RemoveProtectionContainerMappingInput removalInput)
 {
     operations.BeginDeleteAsync(fabricName, protectionContainerName, mappingName, removalInput).GetAwaiter().GetResult();
 }
示例#7
0
 /// <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));
 }
示例#8
0
 /// <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());
 }