/// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(this.InputObject.Name, VerbsData.Update))
            {
                if (this.ShouldProcess(this.InputObject.Name, VerbsData.Update))
                {
                    var protectionContainerMapping =
                        this.RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainerMapping(
                            Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics),
                            Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ReplicationProtectionContainers),
                            Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ProtectionContainerMappings));
                    if (protectionContainerMapping == null)
                    {
                        throw new Exception(
                                  string.Format(
                                      Resources.ProtectionContainerNotFound,
                                      this.InputObject.Name,
                                      PSRecoveryServicesClient.asrVaultCreds.ResourceName));
                    }

                    var updateInput = new UpdateProtectionContainerMappingInput();
                    updateInput.Properties = new UpdateProtectionContainerMappingInputProperties();
                    updateInput.Properties.ProviderSpecificInput = new A2AUpdateContainerMappingInput();

                    switch (this.ParameterSetName)
                    {
                    case AzureToAzureEnableAutoUpdate:
                        updateInput.Properties.ProviderSpecificInput = new A2AUpdateContainerMappingInput
                        {
                            AgentAutoUpdateStatus  = AgentAutoUpdateStatus.Enabled,
                            AutomationAccountArmId = this.AutomationAccountId
                        };
                        break;

                    case AzureToAzureDisableAutoUpdate:
                        updateInput.Properties.ProviderSpecificInput = new A2AUpdateContainerMappingInput
                        {
                            AgentAutoUpdateStatus = AgentAutoUpdateStatus.Disabled
                        };
                        break;
                    }

                    var response = this.RecoveryServicesClient.UpdateAzureSiteRecoveryProtectionContainerMapping(
                        Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics),
                        Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ReplicationProtectionContainers),
                        Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ProtectionContainerMappings),
                        updateInput);
                    var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                        PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

                    this.WriteObject(new ASRJob(jobResponse));
                }
            }
        }
        /// <summary>
        ///     Update Azure Site Recovery Protection Container Mapping.
        /// </summary>
        /// <param name="fabricName">Fabric Name</param>
        /// <param name="protectionContainerName">Protection Container Name</param>
        /// <param name="mappingName">Protection Container Mapping Name</param>
        /// <param name="updateInput">Update ProtectionContainerMapping Input</param>
        /// <returns></returns>
        public PSSiteRecoveryLongRunningOperation UpdateAzureSiteRecoveryProtectionContainerMapping(
            string fabricName,
            string protectionContainerName,
            string mappingName,
            UpdateProtectionContainerMappingInput updateInput)
        {
            var op = this.GetSiteRecoveryClient()
                     .ReplicationProtectionContainerMappings.BeginUpdateWithHttpMessagesAsync(
                fabricName,
                protectionContainerName,
                mappingName,
                updateInput,
                this.GetRequestHeaders(true))
                     .GetAwaiter()
                     .GetResult()
                     .Body;
            var result = SiteRecoveryAutoMapperProfile.Mapper.Map <PSSiteRecoveryLongRunningOperation>(op);

            return(result);
        }
Пример #3
0
 /// <summary>
 /// Update protection container mapping.
 /// </summary>
 /// <remarks>
 /// The operation to update 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='updateInput'>
 /// Mapping update input.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ProtectionContainerMapping> BeginUpdateAsync(this IReplicationProtectionContainerMappingsOperations operations, string fabricName, string protectionContainerName, string mappingName, UpdateProtectionContainerMappingInput updateInput, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginUpdateWithHttpMessagesAsync(fabricName, protectionContainerName, mappingName, updateInput, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Пример #4
0
 /// <summary>
 /// Update protection container mapping.
 /// </summary>
 /// <remarks>
 /// The operation to update 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='updateInput'>
 /// Mapping update input.
 /// </param>
 public static ProtectionContainerMapping BeginUpdate(this IReplicationProtectionContainerMappingsOperations operations, string fabricName, string protectionContainerName, string mappingName, UpdateProtectionContainerMappingInput updateInput)
 {
     return(operations.BeginUpdateAsync(fabricName, protectionContainerName, mappingName, updateInput).GetAwaiter().GetResult());
 }