/// <summary>
        /// Queries by friendly name.
        /// </summary>
        private void GetByFriendlyName()
        {
            bool found = false;

            ProtectableItemListResponse protectableItemListResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(
                Utilities.GetValueFromArmId(this.ProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics),
                this.ProtectionContainer.Name);
            ProtectableItem protectableItem =
                protectableItemListResponse.ProtectableItems.SingleOrDefault(t =>
                                                                             string.Compare(t.Properties.FriendlyName, this.FriendlyName, StringComparison.OrdinalIgnoreCase) == 0);

            if (protectableItem != null)
            {
                ProtectableItemResponse protectableItemResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(
                    Utilities.GetValueFromArmId(this.ProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics),
                    this.ProtectionContainer.Name,
                    protectableItem.Name);
                WriteProtectableItem(protectableItemResponse.ProtectableItem);

                found = true;
            }

            if (!found)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Properties.Resources.ProtectionEntityNotFound,
                              this.FriendlyName,
                              this.ProtectionContainer.FriendlyName));
            }
        }
예제 #2
0
        public static List <ProtectableItem> GetUnprotectedItems(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer container)
        {
            List <ProtectableItem>      protectableItemList         = new List <ProtectableItem>();
            ProtectableItemListResponse protectableItemListResponse = client.ProtectableItem.List(
                primaryFabric.Name,
                container.Name,
                "Unprotected",
                null,
                "1000",
                GetRequestHeaders());

            protectableItemList.AddRange(protectableItemListResponse.ProtectableItems);
            while (protectableItemListResponse.NextLink != null)
            {
                protectableItemListResponse = client.ProtectableItem.ListNext(
                    protectableItemListResponse.NextLink,
                    GetRequestHeaders());
                protectableItemList.AddRange(protectableItemListResponse.ProtectableItems);
            }

            return(protectableItemList);
        }
        /// <summary>
        /// Queries all Protection Entities under given Protection Container.
        /// </summary>
        private void GetAll()
        {
            ProtectableItemListResponse protectableItemListResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(
                Utilities.GetValueFromArmId(this.ProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics),
                this.ProtectionContainer.Name);

            WriteProtectableItems(protectableItemListResponse.ProtectableItems);
        }
예제 #4
0
        public void EnumerateProtectableItems()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                string fabricId = "6adf9420-b02f-4377-8ab7-ff384e6d792f";
                //string containerId = "4f94127d-2eb3-449d-a708-250752e93cb4";
                string containerId = "8cc5a958-d437-41d0-9411-fad0841c0445";

                List <ProtectableItem>      protectableItemList         = new List <ProtectableItem>();
                ProtectableItemListResponse protectableItemListResponse = client.ProtectableItem.List(fabricId, containerId, "All", null, "1000", RequestHeaders);
                protectableItemList.AddRange(protectableItemListResponse.ProtectableItems);
                while (protectableItemListResponse.NextLink != null)
                {
                    protectableItemListResponse = client.ProtectableItem.ListNext(protectableItemListResponse.NextLink, RequestHeaders);
                    protectableItemList.AddRange(protectableItemListResponse.ProtectableItems);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Retrieves Protectable Items.
        /// </summary>
        /// <param name="protectionContainerName">Protection Container Name</param>
        /// <returns>Protection entity list response</returns>
        public ProtectableItemListResponse GetAzureSiteRecoveryProtectableItem(string fabricName,
                                                                               string protectionContainerName)
        {
            ProtectableItemListResponse output           = new ProtectableItemListResponse();
            List <ProtectableItem>      protectableItems = new List <ProtectableItem>();
            ProtectableItemListResponse response         = this
                                                           .GetSiteRecoveryClient()
                                                           .ProtectableItem.List(fabricName, protectionContainerName, null, null, null, this.GetRequestHeaders());

            protectableItems.AddRange(response.ProtectableItems);
            while (response.NextLink != null)
            {
                response = this
                           .GetSiteRecoveryClient()
                           .ProtectableItem.ListNext(response.NextLink, this.GetRequestHeaders());
                protectableItems.AddRange(response.ProtectableItems);
            }

            output.ProtectableItems = protectableItems;
            return(output);
        }
예제 #6
0
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            this.targetNameOrId = this.ProtectionEntity.FriendlyName;
            this.ConfirmAction(
                this.Force.IsPresent || 0 != string.CompareOrdinal(this.Protection, Constants.DisableProtection),
                string.Format(Properties.Resources.DisableProtectionWarning, this.targetNameOrId),
                string.Format(Properties.Resources.DisableProtectionWhatIfMessage, this.Protection),
                this.targetNameOrId,
                () =>
            {
                try
                {
                    if (this.Protection == Constants.EnableProtection)
                    {
                        if (string.Compare(this.ParameterSetName, ASRParameterSets.DisableDR, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            throw new PSArgumentException(Properties.Resources.PassingPolicyMandatoryForEnablingDR);
                        }

                        EnableProtectionProviderSpecificInput enableProtectionProviderSpecificInput = new EnableProtectionProviderSpecificInput();

                        EnableProtectionInputProperties inputProperties = new EnableProtectionInputProperties()
                        {
                            PolicyId                = this.Policy.ID,
                            ProtectableItemId       = this.ProtectionEntity.ID,
                            ProviderSpecificDetails = enableProtectionProviderSpecificInput
                        };

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

                        // Process if block only if policy is not null, policy is created for E2A or B2A and parameter set is for enable DR of E2A or B2A
                        if (this.Policy != null &&
                            0 == string.Compare(this.Policy.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) &&
                            (0 == string.Compare(this.ParameterSetName, ASRParameterSets.EnterpriseToAzure, StringComparison.OrdinalIgnoreCase) ||
                             0 == string.Compare(this.ParameterSetName, ASRParameterSets.HyperVSiteToAzure, StringComparison.OrdinalIgnoreCase)))
                        {
                            HyperVReplicaAzureEnableProtectionInput providerSettings = new HyperVReplicaAzureEnableProtectionInput();
                            providerSettings.HvHostVmId = this.ProtectionEntity.FabricObjectId;
                            providerSettings.VmName     = this.ProtectionEntity.FriendlyName;

                            // Id disk details are missing in input PE object, get the latest PE.
                            if (string.IsNullOrEmpty(this.ProtectionEntity.OS))
                            {
                                // Just checked for OS to see whether the disk details got filled up or not
                                ProtectableItemResponse protectableItemResponse =
                                    RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(
                                        Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationFabrics),
                                        this.ProtectionEntity.ProtectionContainerId,
                                        this.ProtectionEntity.Name);

                                this.ProtectionEntity = new ASRProtectionEntity(protectableItemResponse.ProtectableItem);
                            }

                            if (string.IsNullOrWhiteSpace(this.OS))
                            {
                                providerSettings.OSType = ((string.Compare(this.ProtectionEntity.OS, Constants.OSWindows) == 0) || (string.Compare(this.ProtectionEntity.OS, Constants.OSLinux) == 0)) ? this.ProtectionEntity.OS : Constants.OSWindows;
                            }
                            else
                            {
                                providerSettings.OSType = this.OS;
                            }

                            if (string.IsNullOrWhiteSpace(this.OSDiskName))
                            {
                                providerSettings.VhdId = this.ProtectionEntity.OSDiskId;
                            }
                            else
                            {
                                foreach (var disk in this.ProtectionEntity.Disks)
                                {
                                    if (0 == string.Compare(disk.Name, this.OSDiskName, true))
                                    {
                                        providerSettings.VhdId = disk.Id;
                                        break;
                                    }
                                }
                            }

                            if (RecoveryAzureStorageAccountId != null)
                            {
                                providerSettings.TargetStorageAccountId = RecoveryAzureStorageAccountId;
                            }

                            input.Properties.ProviderSpecificDetails = providerSettings;
                        }
                        else if (this.Policy != null &&
                                 0 == string.Compare(this.Policy.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) &&
                                 0 == string.Compare(this.ParameterSetName, ASRParameterSets.EnterpriseToEnterprise, StringComparison.OrdinalIgnoreCase))
                        {
                            throw new PSArgumentException(Properties.Resources.PassingStorageMandatoryForEnablingDRInAzureScenarios);
                        }

                        this.response =
                            RecoveryServicesClient.EnableProtection(
                                Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationFabrics),
                                Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationProtectionContainers),
                                this.ProtectionEntity.Name,
                                input);
                    }
                    else
                    {
                        DisableProtectionInput input = new DisableProtectionInput();
                        input.Properties             = new DisableProtectionInputProperties()
                        {
                            ProviderSettings = new DisableProtectionProviderSpecificInput()
                        };

                        // fetch the latest PE object
                        ProtectableItemListResponse protectableItemListResponse =
                            RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationFabrics),
                                                                                       this.ProtectionEntity.ProtectionContainerId);
                        ProtectableItem protectableItem = protectableItemListResponse.ProtectableItems.SingleOrDefault(t => t.Name.CompareTo(this.ProtectionEntity.Name) == 0);

                        this.response =
                            RecoveryServicesClient.DisableProtection(
                                Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationFabrics),
                                Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationProtectionContainers),
                                Utilities.GetValueFromArmId(protectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems),
                                input);
                    }

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

                    WriteObject(new ASRJob(jobResponse.Job));

                    if (this.WaitForCompletion.IsPresent)
                    {
                        this.WaitForJobCompletion(this.jobResponse.Job.Name);

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

                        WriteObject(new ASRJob(jobResponse.Job));
                    }
                }
                catch (Exception exception)
                {
                    this.HandleException(exception);
                }
            });
        }