Exemplo n.º 1
0
        /// <summary>
        /// Helper to configure cloud
        /// </summary>
        private void Associate(string targetProtectionContainerId)
        {
            CreateProtectionContainerMappingInputProperties inputProperties = new CreateProtectionContainerMappingInputProperties()
            {
                PolicyId = this.Policy.ID,
                ProviderSpecificInput       = new ReplicationProviderContainerMappingInput(),
                TargetProtectionContainerId = targetProtectionContainerId
            };

            CreateProtectionContainerMappingInput input = new CreateProtectionContainerMappingInput()
            {
                Properties = inputProperties
            };

            LongRunningOperationResponse response = RecoveryServicesClient.ConfigureProtection(
                Utilities.GetValueFromArmId(this.PrimaryProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics),
                this.PrimaryProtectionContainer.Name,
                this.Name,
                input);

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

            this.WriteObject(new ASRJob(jobResponse.Job));
        }
        /// <summary>
        /// Helper to configure cloud
        /// </summary>
        private void Associate(string targetProtectionContainerId)
        {
            CreateProtectionContainerMappingInputProperties inputProperties = new CreateProtectionContainerMappingInputProperties()
            {
                PolicyId = this.Policy.ID,
                ProviderSpecificInput       = new ReplicationProviderContainerMappingInput(),
                TargetProtectionContainerId = targetProtectionContainerId
            };

            CreateProtectionContainerMappingInput input = new CreateProtectionContainerMappingInput()
            {
                Properties = inputProperties
            };

            string targetProtectionContainerName;

            if (string.Compare(targetProtectionContainerId, Constants.AzureContainer, StringComparison.OrdinalIgnoreCase) == 0)
            {
                targetProtectionContainerName = Constants.AzureContainer;
            }
            else
            {
                targetProtectionContainerName = Utilities.GetValueFromArmId(targetProtectionContainerId, ARMResourceTypeConstants.ReplicationProtectionContainers);
            }

            HashAlgorithm algorithm = new SHA256CryptoServiceProvider();

            byte[] hashedBytes      = algorithm.ComputeHash(Encoding.UTF8.GetBytes(this.PrimaryProtectionContainer.Name + targetProtectionContainerName));
            string hashedCloudNames = BitConverter.ToString(hashedBytes).ToLower().Replace("-", string.Empty);

            string mappingName = string.Format("ContainerMapping_{0}_{1}", this.Policy.Name.ToLower(), hashedCloudNames);
            LongRunningOperationResponse response = RecoveryServicesClient.ConfigureProtection(
                Utilities.GetValueFromArmId(this.PrimaryProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics),
                this.PrimaryProtectionContainer.Name, mappingName, input);

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

            this.WriteObject(new ASRJob(jobResponse.Job));
        }