예제 #1
0
        public RestAzureNS.AzureOperationResponse DisableProtectionWithDeleteData()
        {
            string vaultName = (string)ProviderData[VaultParams.VaultName];
            string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            bool   deleteBackupData       = ProviderData.ContainsKey(ItemParams.DeleteBackupData) ?
                                            (bool)ProviderData[ItemParams.DeleteBackupData] : false;

            ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item];

            AzureFileShareItem item = (AzureFileShareItem)ProviderData[ItemParams.Item];

            string containerUri     = "";
            string protectedItemUri = "";
            AzureFileshareProtectedItem properties = new AzureFileshareProtectedItem();

            ValidateAzureFileShareDisableProtectionRequest(itemBase);

            Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id);

            containerUri     = HelperUtils.GetContainerUri(keyValueDict, item.Id);
            protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id);

            return(ServiceClientAdapter.DeleteProtectedItem(
                       containerUri,
                       protectedItemUri,
                       vaultName: vaultName,
                       resourceGroupName: vaultResourceGroupName));
        }
예제 #2
0
        /// <summary>
        /// Triggers the disable protection operation for the given item
        /// </summary>
        /// <returns>The job response returned from the service</returns>
        public RestAzureNS.AzureOperationResponse <ProtectedItemResource> DisableProtection()
        {
            string vaultName = (string)ProviderData[VaultParams.VaultName];
            string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            bool   deleteBackupData       = ProviderData.ContainsKey(ItemParams.DeleteBackupData) ?
                                            (bool)ProviderData[ItemParams.DeleteBackupData] : false;

            ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item];

            AzureFileShareItem item = (AzureFileShareItem)ProviderData[ItemParams.Item];

            AzureFileshareProtectedItem properties = new AzureFileshareProtectedItem();

            return(EnableOrModifyProtection(disableWithRetentionData: true));
        }
예제 #3
0
        public RestAzureNS.AzureOperationResponse TriggerBackup()
        {
            string                      vaultName = (string)ProviderData[VaultParams.VaultName];
            string                      vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            ItemBase                    item                        = (ItemBase)ProviderData[ItemParams.Item];
            DateTime?                   expiryDateTime              = (DateTime?)ProviderData[ItemParams.ExpiryDateTimeUTC];
            AzureFileShareItem          azureFileShareItem          = item as AzureFileShareItem;
            BackupRequestResource       triggerBackupRequest        = new BackupRequestResource();
            AzureFileShareBackupRequest azureFileShareBackupRequest = new AzureFileShareBackupRequest();

            azureFileShareBackupRequest.RecoveryPointExpiryTimeInUTC = expiryDateTime;
            triggerBackupRequest.Properties = azureFileShareBackupRequest;

            return(ServiceClientAdapter.TriggerBackup(
                       IdUtils.GetValueByName(azureFileShareItem.Id, IdUtils.IdNames.ProtectionContainerName),
                       IdUtils.GetValueByName(azureFileShareItem.Id, IdUtils.IdNames.ProtectedItemName),
                       triggerBackupRequest,
                       vaultName: vaultName,
                       resourceGroupName: vaultResourceGroupName));
        }
예제 #4
0
        private static ItemBase GetAzureFileShareItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
        {
            ItemBase itemModel;
            string   policyName = null;
            string   policyId   = ((ServiceClientModel.AzureFileshareProtectedItem)protectedItem.Properties).PolicyId;

            if (!string.IsNullOrEmpty(policyId))
            {
                Dictionary <UriEnums, string> keyValueDict =
                    HelperUtils.ParseUri(policyId);
                policyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policyId);
            }

            string containerUri = HelperUtils.GetContainerUri(
                HelperUtils.ParseUri(protectedItem.Id),
                protectedItem.Id);

            itemModel = new AzureFileShareItem(
                protectedItem,
                IdUtils.GetNameFromUri(containerUri),
                ContainerType.AzureStorage,
                policyName);
            return(itemModel);
        }
예제 #5
0
        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));
        }