public void FetchNodesListAndAutoProtectionPolicy(List <ProtectableItemBase> itemModels, string vaultName, string resourceGroupName) { foreach (var itemModel in itemModels) { AzureWorkloadProtectableItem protectableItem = ((AzureWorkloadProtectableItem)itemModel); string itemType = ""; string itemName = ""; string containerUri = ""; string backupManagementType = ""; Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(protectableItem.Id); itemType = HelperUtils.GetProtectableItemUri(keyValueDict, protectableItem.Id).Split(';')[0]; itemName = HelperUtils.GetProtectableItemUri(keyValueDict, protectableItem.Id).Split(';')[1]; containerUri = HelperUtils.GetContainerUri(keyValueDict, protectableItem.Id); // fetch AutoProtectionPolicy for non DBs if (protectableItem.ProtectableItemType != "SQLDataBase") { // fetch the policy using backup intent ODataQuery <ServiceClientModel.ProtectionIntentQueryObject> queryParams = null; backupManagementType = ServiceClientModel.BackupManagementType.AzureWorkload; queryParams = new ODataQuery <ServiceClientModel.ProtectionIntentQueryObject>( q => q.ItemType == itemType && q.ItemName == itemName && q.ParentName == containerUri && q.BackupManagementType == backupManagementType); var intentList = ServiceClientAdapter.ListProtectionIntent( queryParams, vaultName: vaultName, resourceGroupName: resourceGroupName); foreach (var intent in intentList) { protectableItem.AutoProtectionPolicy = intent.Properties.PolicyId; } } // fetch Nodelist for SQLAGs if (protectableItem.ProtectableItemType == "SQLAvailabilityGroup") { // add the NodeList ProtectionContainerResource cont = ServiceClientAdapter.GetContainer(vaultName, resourceGroupName, containerUri); AzureSQLAGWorkloadContainerProtectionContainer protectionContainer = (AzureSQLAGWorkloadContainerProtectionContainer)cont.Properties; if (protectionContainer.ExtendedInfo != null) { protectableItem.NodesList = protectionContainer.ExtendedInfo.NodesList; } } } }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; string shouldProcessName = InputItem.Id; string itemType = ""; string itemName = ""; string containerUri = ""; if (ShouldProcess(shouldProcessName, VerbsLifecycle.Disable)) { Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(InputItem.Id); itemType = HelperUtils.GetProtectableItemUri( keyValueDict, InputItem.Id).Split(';')[0]; itemName = HelperUtils.GetProtectableItemUri( keyValueDict, InputItem.Id).Split(';')[1]; containerUri = HelperUtils.GetContainerUri( keyValueDict, InputItem.Id); bool isDisableAutoProtectionSuccessful = false; try { ODataQuery <ServiceClientModel.ProtectionIntentQueryObject> queryParams = null; string backupManagementType = ServiceClientModel.BackupManagementType.AzureWorkload; queryParams = new ODataQuery <ServiceClientModel.ProtectionIntentQueryObject>( q => q.ItemType == itemType && q.ItemName == itemName && q.ParentName == containerUri && q.BackupManagementType == backupManagementType); var itemResponses = ServiceClientAdapter.ListProtectionIntent( queryParams, vaultName: vaultName, resourceGroupName: resourceGroupName); string intentName = null; foreach (var itemResponse in itemResponses) { string itemNameResponse = ""; string containerNameResponse = ""; Dictionary <UriEnums, string> keyValueDictResponse = HelperUtils.ParseUri(itemResponse.Properties.ItemId); itemNameResponse = HelperUtils.GetProtectableItemUri( keyValueDictResponse, itemResponse.Properties.ItemId).ToLower(); containerNameResponse = HelperUtils.GetContainerUri( keyValueDictResponse, itemResponse.Properties.ItemId); if (String.Compare(itemNameResponse, itemName, true) == 0 && String.Compare(containerUri.Split(';')[3], containerNameResponse.Split(';')[2], true) == 0) { intentName = itemResponse.Name; break; } } var deleteResponse = ServiceClientAdapter.DeleteProtectionIntent( intentName, vaultName: vaultName, resourceGroupName: resourceGroupName); isDisableAutoProtectionSuccessful = true; } catch { } if (PassThru.IsPresent) { WriteObject(isDisableAutoProtectionSuccessful); } } }); }