private WorkloadProtectableItemResource GetProtectableItem(string vaultName, string vaultResourceGroupName, string azureFileShareName, string storageAccountName) { WorkloadProtectableItemResource protectableObjectResource = null; ODataQuery <BMSPOQueryObject> queryParam = new ODataQuery <BMSPOQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureStorage); var protectableItemList = ServiceClientAdapter.ListProtectableItem( queryParam, vaultName: vaultName, resourceGroupName: vaultResourceGroupName); if (protectableItemList.Count == 0) { //Container is not discovered Logger.Instance.WriteDebug(Resources.ContainerNotDiscovered); } foreach (var protectableItem in protectableItemList) { AzureFileShareProtectableItem azureFileShareProtectableItem = (AzureFileShareProtectableItem)protectableItem.Properties; if (azureFileShareProtectableItem != null && string.Compare(azureFileShareProtectableItem.FriendlyName, azureFileShareName, true) == 0 && string.Compare(azureFileShareProtectableItem.ParentContainerFriendlyName, storageAccountName, true) == 0) { protectableObjectResource = protectableItem; break; } } return(protectableObjectResource); }
private RestAzureNS.AzureOperationResponse <ProtectedItemResource> EnableOrModifyProtection(bool disableWithRetentionData = false) { string vaultName = (string)ProviderData[VaultParams.VaultName]; string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; string azureFileShareName = ProviderData.ContainsKey(ItemParams.ItemName) ? (string)ProviderData[ItemParams.ItemName] : null; string storageAccountName = ProviderData.ContainsKey(ItemParams.StorageAccountName) ? (string)ProviderData[ItemParams.StorageAccountName] : null; string parameterSetName = ProviderData.ContainsKey(ItemParams.ParameterSetName) ? (string)ProviderData[ItemParams.ParameterSetName] : null; PolicyBase policy = ProviderData.ContainsKey(ItemParams.Policy) ? (PolicyBase)ProviderData[ItemParams.Policy] : null; ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item]; AzureFileShareItem item = (AzureFileShareItem)ProviderData[ItemParams.Item]; string containerUri = ""; string protectedItemUri = ""; string sourceResourceId = null; AzureFileshareProtectedItem properties = new AzureFileshareProtectedItem(); if (itemBase == null) { //Enable protection ValidateAzureFilesWorkloadType(policy.WorkloadType); ValidateFileShareEnableProtectionRequest( azureFileShareName, storageAccountName); WorkloadProtectableItemResource protectableObjectResource = GetAzureFileShareProtectableObject( azureFileShareName, storageAccountName, vaultName: vaultName, vaultResourceGroupName: vaultResourceGroupName); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(protectableObjectResource.Id); containerUri = HelperUtils.GetContainerUri( keyValueDict, protectableObjectResource.Id); protectedItemUri = HelperUtils.GetProtectableItemUri( keyValueDict, protectableObjectResource.Id); AzureFileShareProtectableItem azureFileShareProtectableItem = (AzureFileShareProtectableItem)protectableObjectResource.Properties; if (azureFileShareProtectableItem != null) { sourceResourceId = azureFileShareProtectableItem.ParentContainerFabricId; } // construct Service Client protectedItem request properties.PolicyId = policy.Id; properties.SourceResourceId = sourceResourceId; } else if (itemBase != null && !disableWithRetentionData) { //modify policy with new policy ValidateAzureFilesWorkloadType(item.WorkloadType, policy.WorkloadType); ValidateAzureFilesModifyProtectionRequest(itemBase, policy); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); sourceResourceId = item.SourceResourceId; // construct Service Client protectedItem request properties.PolicyId = policy.Id; properties.SourceResourceId = sourceResourceId; } else if (disableWithRetentionData) { //Disable protection while retaining backup data ValidateAzureFileShareDisableProtectionRequest(itemBase); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); properties.PolicyId = string.Empty; properties.ProtectionState = ProtectionState.ProtectionStopped; properties.SourceResourceId = item.SourceResourceId; } ProtectedItemResource serviceClientRequest = new ProtectedItemResource() { Properties = properties }; return(ServiceClientAdapter.CreateOrUpdateProtectedItem( containerUri, protectedItemUri, serviceClientRequest, vaultName: vaultName, resourceGroupName: vaultResourceGroupName)); }