From 1ac99e4cf2aa590123507a113b04954b20894dc5 Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Thu, 29 Nov 2018 13:51:20 +0530 Subject: [PATCH 1/2] commit --- .../ServiceClientHelpers.cs | 5 +- .../CommonModels/Enums.cs | 12 +- .../CommonModels/Utils.cs | 25 +++- ...s.RecoveryServices.Backup.Providers.csproj | 93 ++++++++++++ .../AzureWorkloadPsBackupProvider.cs | 138 ++++++++++++++++++ .../PsBackupProviderManager.cs | 15 +- 6 files changed, 279 insertions(+), 9 deletions(-) create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Commands.RecoveryServices.Backup.Providers.csproj create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs index 07acea7e5bbf..b6ab24a37197 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs @@ -76,6 +76,9 @@ public static string GetServiceClientProviderType(CmdletModel.WorkloadType workl case CmdletModel.WorkloadType.AzureFiles: providerType = ServiceClientModel.BackupManagementType.AzureStorage.ToString(); break; + case CmdletModel.WorkloadType.MSSQL: + providerType = ServiceClientModel.BackupManagementType.AzureWorkload.ToString(); + break; default: break; } @@ -353,4 +356,4 @@ public static string GetServiceClientWorkloadType(CmdletModel.WorkloadType workl return serviceClientWorkloadType; } } -} +} \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Enums.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Enums.cs index 1ac388827f41..1b3551a3a303 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Enums.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Enums.cs @@ -37,7 +37,12 @@ public enum ContainerType /// /// Represents any Azure Storage containers. /// - AzureStorage + AzureStorage, + + /// + /// Represents any Azure Workload containers. + /// + AzureWorkload } /// @@ -70,6 +75,7 @@ public enum BackupManagementType /// Represents Azure File Storage. https://docs.microsoft.com/en-in/azure/storage/files/storage-files-introduction /// AzureStorage, + AzureWorkload, } /// @@ -103,6 +109,7 @@ public enum WorkloadType /// Represents Azure File https://docs.microsoft.com/en-in/azure/storage/files/storage-files-introduction /// AzureFiles, + MSSQL, } /// @@ -134,6 +141,7 @@ public enum PsBackupProviderTypes /// Represents the Azure File provider for powershell cmdlets. /// AzureFiles, + AzureWorkload, } /// @@ -334,4 +342,4 @@ public enum SourceFileType File, Directory } -} +} \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Utils.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Utils.cs index 526188855a4f..019db748a1a5 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Utils.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Utils.cs @@ -218,6 +218,8 @@ public static BackupManagementType GetPsBackupManagementType(string backupManage return BackupManagementType.AzureSQL; case ServiceClientModel.BackupManagementType.AzureStorage: return BackupManagementType.AzureStorage; + case ServiceClientModel.BackupManagementType.AzureWorkload: + return BackupManagementType.AzureWorkload; default: throw new Exception("Unsupported BackupManagmentType: " + backupManagementType); } @@ -248,6 +250,11 @@ public static ContainerType GetPsContainerType(string containerType) { return ContainerType.AzureStorage; } + else if (containerType == + ServiceClientModel.BackupManagementType.AzureWorkload) + { + return ContainerType.AzureWorkload; + } else { throw new Exception("Unsupported ContainerType: " + containerType); @@ -265,14 +272,18 @@ public static WorkloadType GetPsWorkloadType(string workloadType) { return WorkloadType.AzureVM; } - if (workloadType == ServiceClientModel.WorkloadType.AzureSqlDb.ToString()) + else if (workloadType == ServiceClientModel.WorkloadType.AzureSqlDb.ToString()) { return WorkloadType.AzureSQLDatabase; } - if (workloadType == ServiceClientModel.WorkloadType.AzureFileShare) + else if (workloadType == ServiceClientModel.WorkloadType.AzureFileShare) { return WorkloadType.AzureFiles; } + else if (workloadType == ServiceClientModel.WorkloadType.SQLDataBase) + { + return WorkloadType.MSSQL; + } else { throw new Exception("Unsupported WorkloadType: " + workloadType); @@ -290,14 +301,18 @@ public static string GetServiceClientWorkloadType(string workloadType) { return ServiceClientModel.WorkloadType.VM; } - if (workloadType == WorkloadType.AzureSQLDatabase.ToString()) + else if (workloadType == WorkloadType.AzureSQLDatabase.ToString()) { return ServiceClientModel.WorkloadType.AzureSqlDb; } - if (workloadType == WorkloadType.AzureFiles.ToString()) + else if (workloadType == WorkloadType.AzureFiles.ToString()) { return ServiceClientModel.WorkloadType.AzureFileShare; } + else if (workloadType == WorkloadType.MSSQL.ToString()) + { + return ServiceClientModel.WorkloadType.SQLDataBase; + } else { throw new Exception("Unsupported WorkloadType: " + workloadType); @@ -343,4 +358,4 @@ public static string GetWorkloadTypeFromArmType(string armType) throw new Exception("Unsupported ArmType: " + armType); } } -} +} \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Commands.RecoveryServices.Backup.Providers.csproj b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Commands.RecoveryServices.Backup.Providers.csproj new file mode 100644 index 000000000000..a7c0bb54ea7e --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Commands.RecoveryServices.Backup.Providers.csproj @@ -0,0 +1,93 @@ + + + + + + Debug + AnyCPU + {02234E90-BCDE-4B20-B1F5-01B1005821DB} + Library + Properties + Microsoft.Azure.Commands.RecoveryServices.Backup.Providers + Microsoft.Azure.Commands.RecoveryServices.Backup.Providers + v4.5.2 + 512 + ..\ + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + prompt + 4 + TRACE;SIGN + true + MSSharedLibKey.snk + true + false + + + + False + ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.Backup.3.0.1-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.Backup.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + {142d7b0b-388a-4ceb-a228-7f6d423c5c2e} + Commands.Profile + + + {0e1d3f36-e6c8-4764-8c7d-6f9ee537490c} + Commands.RecoveryServices.Backup.Helpers + + + {5e675749-6139-464a-904c-59c0ffdfec82} + Commands.RecoveryServices.Backup.Logger + + + {30b92759-50b3-494e-b9f0-ec9a2ce9d57b} + Commands.RecoveryServices.Backup.Models + + + {b758fec1-35c1-4f93-a954-66dd33f6e0ec} + Commands.RecoveryServices.Backup.ServiceClientAdapter + + + + + + + + \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs new file mode 100644 index 000000000000..8a2dbc27f142 --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs @@ -0,0 +1,138 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; +using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS; +using Microsoft.Azure.Management.RecoveryServices.Backup.Models; +using System; +using System.Collections.Generic; +using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; +using RestAzureNS = Microsoft.Rest.Azure; +using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties; +using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models; +using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers; + +namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel +{ + /// + /// This class implements methods for azure DB Workload backup provider + /// + public class AzureWorkloadPsBackupProvider : IPsBackupProvider + { + private const int defaultOperationStatusRetryTimeInMilliSec = 5 * 1000; // 5 sec + private const string separator = ";"; + private const CmdletModel.RetentionDurationType defaultFileRetentionType = + CmdletModel.RetentionDurationType.Days; + private const int defaultFileRetentionCount = 30; + Dictionary ProviderData { get; set; } + ServiceClientAdapter ServiceClientAdapter { get; set; } + AzureWorkloadProviderHelper AzureWorkloadProviderHelper { get; set; } + /// + /// Initializes the provider with the data recieved from the cmdlet layer + /// + /// Data from the cmdlet layer intended for the provider + /// Service client adapter for communicating with the backend service + public void Initialize(Dictionary providerData, ServiceClientAdapter serviceClientAdapter) + { + ProviderData = providerData; + ServiceClientAdapter = serviceClientAdapter; + AzureWorkloadProviderHelper = new AzureWorkloadProviderHelper(ServiceClientAdapter); + } + + public ResourceBackupStatus CheckBackupStatus() + { + throw new NotImplementedException(); + } + + public ProtectionPolicyResource CreatePolicy() + { + throw new NotImplementedException(); + } + + public RestAzureNS.AzureOperationResponse DisableProtection() + { + throw new NotImplementedException(); + } + + public RestAzureNS.AzureOperationResponse EnableProtection() + { + throw new NotImplementedException(); + } + + public RetentionPolicyBase GetDefaultRetentionPolicyObject() + { + throw new NotImplementedException(); + } + + public SchedulePolicyBase GetDefaultSchedulePolicyObject() + { + throw new NotImplementedException(); + } + + public ProtectedItemResource GetProtectedItem() + { + throw new NotImplementedException(); + } + + public RecoveryPointBase GetRecoveryPointDetails() + { + throw new NotImplementedException(); + } + + public List ListBackupManagementServers() + { + throw new NotImplementedException(); + } + + public List ListProtectedItems() + { + throw new NotImplementedException(); + } + + public List ListProtectionContainers() + { + throw new NotImplementedException(); + } + + public List ListRecoveryPoints() + { + throw new NotImplementedException(); + } + + public RestAzureNS.AzureOperationResponse ModifyPolicy() + { + throw new NotImplementedException(); + } + + public RPMountScriptDetails ProvisionItemLevelRecoveryAccess() + { + throw new NotImplementedException(); + } + + public void RevokeItemLevelRecoveryAccess() + { + throw new NotImplementedException(); + } + + public RestAzureNS.AzureOperationResponse TriggerBackup() + { + throw new NotImplementedException(); + } + + public RestAzureNS.AzureOperationResponse TriggerRestore() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs index 3495a997a853..d241d3e99a05 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs @@ -215,6 +215,16 @@ public IPsBackupProvider GetProviderInstance( } psProviderType = PsBackupProviderTypes.AzureFiles; break; + case WorkloadType.MSSQL: + if (backupManagementType.HasValue && + backupManagementType != BackupManagementType.AzureWorkload) + { + throw new ArgumentException( + string.Format(Resources.BackupManagementTypeNotExpectedForWorkloadType, + workloadType.ToString())); + } + psProviderType = PsBackupProviderTypes.AzureWorkload; + break; default: throw new ArgumentException( string.Format(Resources.UnsupportedWorkloadTypeException, @@ -248,6 +258,9 @@ public IPsBackupProvider GetProviderInstance(PsBackupProviderTypes providerType) case PsBackupProviderTypes.AzureFiles: psBackupProvider = new AzureFilesPsBackupProvider(); break; + case PsBackupProviderTypes.AzureWorkload: + psBackupProvider = new AzureWorkloadPsBackupProvider(); + break; default: break; } @@ -277,4 +290,4 @@ public IPsBackupProvider GetProviderInstance(string resourceType) } } } -} +} \ No newline at end of file From 140a6762c74f51b9b1c44b09e0a232fdf03dc0f4 Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Mon, 12 Nov 2018 16:44:36 +0530 Subject: [PATCH 2/2] Container support for mercury --- .../Conversions/ConversionHelpers.cs | 5 + .../ServiceClientHelpers.cs | 3 + .../AzureWorkloadContainer.cs | 32 ++ .../CommonModels/Enums.cs | 12 +- .../AzureWorkloadProviderHelper.cs | 6 +- .../IPsBackupProvider.cs | 2 + .../Providers/AzureFilesPsBackupProvider.cs | 6 +- .../Providers/AzureSqlPsBackupProvider.cs | 5 + .../AzureWorkloadPsBackupProvider.cs | 88 +++++- .../Providers/DpmPsBackupProvider.cs | 5 + .../Providers/IaasVmPsBackupProvider.cs | 6 +- .../Providers/MabPsBackupProvider.cs | 5 + .../PsBackupProviderManager.cs | 17 ++ .../BMSAPIs/ContainerAPIs.cs | 4 +- ...mmands.RecoveryServices.Backup.Test.csproj | 277 ++++++++++++++++++ .../AzureWorkload/ContainerTests.cs | 51 ++++ .../AzureWorkload/ContainerTests.ps1 | 67 +++++ .../TestConstants.cs | 2 + ...tAzureRmRecoveryServicesBackupContainer.cs | 6 +- ...rAzureRmRecoveryServicesBackupContainer.cs | 98 +++++++ ...rAzureRmRecoveryServicesBackupContainer.cs | 8 +- ...nds.RecoveryServices.Backup.Cmdlets.csproj | 128 ++++++++ .../ParamHelpMsgs.cs | 1 + .../Az.RecoveryServices.psd1 | 3 +- 24 files changed, 817 insertions(+), 20 deletions(-) create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureWorkloadModels/AzureWorkloadContainer.cs create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/ContainerTests.cs create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/ContainerTests.ps1 create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/RegisterAzureRmRecoveryServicesBackupContainer.cs create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Commands.RecoveryServices.Backup.Cmdlets.csproj diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs index e3cb7027cbbd..3920273c77c3 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs @@ -55,6 +55,11 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta { containerModel = new AzureFileShareContainer(protectionContainer); } + else if (protectionContainer.Properties.GetType() == + typeof(ServiceClientModel.AzureVMAppContainerProtectionContainer)) + { + containerModel = new AzureWorkloadContainer(protectionContainer); + } } return containerModel; diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs index b6ab24a37197..beba81ab60de 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs @@ -349,6 +349,9 @@ public static string GetServiceClientWorkloadType(CmdletModel.WorkloadType workl case CmdletModel.WorkloadType.AzureVM: serviceClientWorkloadType = ServiceClientModel.WorkloadType.VM.ToString(); break; + case CmdletModel.WorkloadType.MSSQL: + serviceClientWorkloadType = ServiceClientModel.WorkloadType.SQLDataBase.ToString(); + break; default: break; } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureWorkloadModels/AzureWorkloadContainer.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureWorkloadModels/AzureWorkloadContainer.cs new file mode 100644 index 000000000000..b95d8d10a07e --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureWorkloadModels/AzureWorkloadContainer.cs @@ -0,0 +1,32 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Management.RecoveryServices.Backup.Models; + +namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models +{ + /// + /// Azure Workload specific container class. + /// + public class AzureWorkloadContainer : AzureContainer + { + /// + /// Constructor. Takes the service client object representing the container + /// and converts it in to the PS container model + /// + /// Service client object representing the container + public AzureWorkloadContainer(ProtectionContainerResource protectionContainerResource) + : base(protectionContainerResource) { } + } +} diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Enums.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Enums.cs index 1b3551a3a303..3c5ad4be75b3 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Enums.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Enums.cs @@ -40,7 +40,7 @@ public enum ContainerType AzureStorage, /// - /// Represents any Azure Workload containers. + /// Represents Azure Workload /// AzureWorkload } @@ -75,7 +75,11 @@ public enum BackupManagementType /// Represents Azure File Storage. https://docs.microsoft.com/en-in/azure/storage/files/storage-files-introduction /// AzureStorage, - AzureWorkload, + + /// + /// Represents Azure Workload + /// + AzureWorkload } /// @@ -109,6 +113,10 @@ public enum WorkloadType /// Represents Azure File https://docs.microsoft.com/en-in/azure/storage/files/storage-files-introduction /// AzureFiles, + + /// + /// Represents MSSQL in Azure VM. + /// MSSQL, } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/AzureWorkloadProviderHelper.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/AzureWorkloadProviderHelper.cs index b7fb5f2a1bd8..9e2fbaeb6680 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/AzureWorkloadProviderHelper.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/AzureWorkloadProviderHelper.cs @@ -64,12 +64,12 @@ public void RefreshContainer(string vaultName = null, string vaultResourceGroupN } } - public void RegisterContainer(string storageAccountName, + public void RegisterContainer(string containerName, ProtectionContainerResource protectionContainerResource, string vaultName, string vaultResourceGroupName) { var registerResponse = ServiceClientAdapter.RegisterContainer( - storageAccountName, + containerName, protectionContainerResource, vaultName, vaultResourceGroupName); @@ -79,7 +79,7 @@ public void RegisterContainer(string storageAccountName, operationId => ServiceClientAdapter.GetRegisterContainerOperationResult( operationId, - storageAccountName, + containerName, vaultName: vaultName, resourceGroupName: vaultResourceGroupName)); diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/IPsBackupProvider.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/IPsBackupProvider.cs index 3fa166fbaf8a..c0148a7623e2 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/IPsBackupProvider.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/IPsBackupProvider.cs @@ -60,5 +60,7 @@ public interface IPsBackupProvider RPMountScriptDetails ProvisionItemLevelRecoveryAccess(); void RevokeItemLevelRecoveryAccess(); + + void RegisterContainer(); } } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupProvider.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupProvider.cs index cd54f4a273cf..bd4298f83133 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupProvider.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupProvider.cs @@ -17,7 +17,6 @@ using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers; using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties; using Microsoft.Azure.Management.Internal.Resources.Models; -using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; using Microsoft.Azure.Management.RecoveryServices.Backup.Models; using Microsoft.Rest.Azure.OData; using System; @@ -700,6 +699,11 @@ public List ListProtectedItems() return itemModels; } + public void RegisterContainer() + { + throw new NotImplementedException(); + } + private RestAzureNS.AzureOperationResponse EnableOrModifyProtection(bool disableWithRetentionData = false) { string vaultName = (string)ProviderData[VaultParams.VaultName]; diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureSqlPsBackupProvider.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureSqlPsBackupProvider.cs index 29a4979f2013..65bbdc7a8d9d 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureSqlPsBackupProvider.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureSqlPsBackupProvider.cs @@ -485,6 +485,11 @@ public List ListProtectedItems() return itemModels; } + public void RegisterContainer() + { + throw new NotImplementedException(); + } + #region private private void ValidateAzureSqlWorkloadType(CmdletModel.WorkloadType type) { diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs index 8a2dbc27f142..b671683c9bdd 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs @@ -14,14 +14,15 @@ using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS; +using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties; using Microsoft.Azure.Management.RecoveryServices.Backup.Models; +using Microsoft.Rest.Azure.OData; using System; using System.Collections.Generic; +using System.Linq; using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; using RestAzureNS = Microsoft.Rest.Azure; -using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties; using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models; -using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers; namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel { @@ -35,9 +36,13 @@ public class AzureWorkloadPsBackupProvider : IPsBackupProvider private const CmdletModel.RetentionDurationType defaultFileRetentionType = CmdletModel.RetentionDurationType.Days; private const int defaultFileRetentionCount = 30; + Dictionary ProviderData { get; set; } + ServiceClientAdapter ServiceClientAdapter { get; set; } + AzureWorkloadProviderHelper AzureWorkloadProviderHelper { get; set; } + /// /// Initializes the provider with the data recieved from the cmdlet layer /// @@ -102,7 +107,18 @@ public List ListProtectedItems() public List ListProtectionContainers() { - throw new NotImplementedException(); + CmdletModel.BackupManagementType? backupManagementTypeNullable = + (CmdletModel.BackupManagementType?) + ProviderData[ContainerParams.BackupManagementType]; + + if (backupManagementTypeNullable.HasValue) + { + ValidateAzureWorkloadBackupManagementType(backupManagementTypeNullable.Value); + } + + return AzureWorkloadProviderHelper.ListProtectionContainers( + ProviderData, + ServiceClientModel.BackupManagementType.AzureWorkload); } public List ListRecoveryPoints() @@ -134,5 +150,71 @@ public RestAzureNS.AzureOperationResponse TriggerRestore() { throw new NotImplementedException(); } + + private void ValidateAzureWorkloadBackupManagementType( + CmdletModel.BackupManagementType backupManagementType) + { + if (backupManagementType != CmdletModel.BackupManagementType.AzureWorkload) + { + throw new ArgumentException(string.Format(Resources.UnExpectedBackupManagementTypeException, + CmdletModel.BackupManagementType.AzureWorkload.ToString(), + backupManagementType.ToString())); + } + } + + public void RegisterContainer() + { + string vaultName = (string)ProviderData[VaultParams.VaultName]; + string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; + string containerName = (string)ProviderData[ContainerParams.Name]; + string backupManagementType = (string)ProviderData[ContainerParams.BackupManagementType]; + string workloadType = (string)ProviderData[ContainerParams.ContainerType]; + + //Trigger Discovery + ODataQuery queryParam = new ODataQuery( + q => q.BackupManagementType + == ServiceClientModel.BackupManagementType.AzureWorkload); + AzureWorkloadProviderHelper.RefreshContainer(vaultName, vaultResourceGroupName, queryParam); + + List unregisteredVmContainers = + GetUnRegisteredVmContainers(vaultName, vaultResourceGroupName); + ProtectableContainerResource unregisteredVmContainer = unregisteredVmContainers.Find( + vmContainer => string.Compare(vmContainer.Name.Split(';').Last(), + containerName, true) == 0); + + if (unregisteredVmContainer != null) + { + ProtectionContainerResource protectionContainerResource = + new ProtectionContainerResource(unregisteredVmContainer.Id, + unregisteredVmContainer.Name); + AzureVMAppContainerProtectionContainer azureVMContainer = new AzureVMAppContainerProtectionContainer( + friendlyName: containerName, + backupManagementType: backupManagementType, + sourceResourceId: unregisteredVmContainer.Properties.ContainerId, + workloadType: workloadType.ToString()); + protectionContainerResource.Properties = azureVMContainer; + + AzureWorkloadProviderHelper.RegisterContainer(unregisteredVmContainer.Name, + protectionContainerResource, + vaultName, + vaultResourceGroupName); + } + } + + private List GetUnRegisteredVmContainers(string vaultName = null, + string vaultResourceGroupName = null) + { + ODataQuery queryParams = null; + queryParams = new ODataQuery( + q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureWorkload); + + var listResponse = ServiceClientAdapter.ListUnregisteredContainers( + queryParams, + vaultName: vaultName, + resourceGroupName: vaultResourceGroupName); + List containerModels = listResponse.ToList(); + + return containerModels; + } } } \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/DpmPsBackupProvider.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/DpmPsBackupProvider.cs index ece71b39e9b8..0fb67aecec02 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/DpmPsBackupProvider.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/DpmPsBackupProvider.cs @@ -154,5 +154,10 @@ public List ListProtectedItems() { throw new NotImplementedException(); } + + public void RegisterContainer() + { + throw new NotImplementedException(); + } } } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs index 979ce2eca53b..28f26d32d9b7 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs @@ -18,7 +18,6 @@ using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers; using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties; using Microsoft.Azure.Management.Internal.Resources.Models; -using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; using Microsoft.Azure.Management.RecoveryServices.Backup.Models; using Microsoft.Rest.Azure.OData; using System; @@ -812,7 +811,10 @@ public RetentionPolicyBase GetDefaultRetentionPolicyObject() return defaultRetention; } - + public void RegisterContainer() + { + throw new NotImplementedException(); + } #region private diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/MabPsBackupProvider.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/MabPsBackupProvider.cs index 5e5f8d15dd9e..02f4d477169a 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/MabPsBackupProvider.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/MabPsBackupProvider.cs @@ -157,5 +157,10 @@ public List ListProtectedItems() { throw new NotImplementedException(); } + + public void RegisterContainer() + { + throw new NotImplementedException(); + } } } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs index d241d3e99a05..b6e8854d9729 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs @@ -122,6 +122,20 @@ public IPsBackupProvider GetProviderInstance containerType)); } break; + case ContainerType.AzureWorkload: + if (backupManagementType == BackupManagementType.AzureWorkload || + backupManagementType == null) + { + providerType = PsBackupProviderTypes.AzureWorkload; + } + else + { + throw new ArgumentException( + string.Format( + Resources.BackupManagementTypeRequiredForContainerType, + containerType)); + } + break; default: throw new ArgumentException( string.Format(Resources.UnsupportedContainerType, @@ -155,6 +169,9 @@ public IPsBackupProvider GetProviderInstance(WorkloadType workloadType) case WorkloadType.AzureFiles: providerType = PsBackupProviderTypes.AzureFiles; break; + case WorkloadType.MSSQL: + providerType = PsBackupProviderTypes.AzureWorkload; + break; default: throw new ArgumentException( string.Format(Resources.BackupManagementTypeRequiredForWorkloadType, diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.ServiceClientAdapter/BMSAPIs/ContainerAPIs.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.ServiceClientAdapter/BMSAPIs/ContainerAPIs.cs index 80463338044f..6dfd7f1d4398 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.ServiceClientAdapter/BMSAPIs/ContainerAPIs.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.ServiceClientAdapter/BMSAPIs/ContainerAPIs.cs @@ -12,11 +12,11 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using System; -using System.Collections.Generic; using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers; using Microsoft.Azure.Management.RecoveryServices.Backup.Models; using Microsoft.Rest.Azure.OData; +using System; +using System.Collections.Generic; using RestAzureNS = Microsoft.Rest.Azure; namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj new file mode 100644 index 000000000000..ba18ef1ac539 --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj @@ -0,0 +1,277 @@ + + + + + + Debug + AnyCPU + {65E15D74-1E24-4600-8671-D0B420524B17} + Library + Properties + Microsoft.Azure.Commands.RecoveryServices.Backup.Test + Microsoft.Azure.Commands.RecoveryServices.Backup.Test + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\packages\Microsoft.Azure.Management.Compute.23.2.0\lib\net452\Microsoft.Azure.Management.Compute.dll + True + + + ..\..\..\packages\Microsoft.Azure.Management.Network.19.6.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll + + + False + ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.4.2.1-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.dll + + + False + ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.Backup.3.0.1-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.Backup.dll + + + ..\..\..\packages\Microsoft.Azure.Management.Storage.4.1.0-preview\lib\net45\Microsoft.Azure.Management.Storage.dll + + + + + + + + + + + + + + Designer + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + + + + + + + + + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + + + + {08cf7da7-0392-4a19-b79b-e1ff67cdb81a} + Commands.Storage + + + {52643bd5-6378-49bd-9f6e-dac9dd8a867b} + Commands.Compute + + + {98cfd96b-a6bc-4f15-ae2c-603fc2b58981} + Commands.Network + + + {604260dc-b392-4cf4-81ec-34b14591e2d2} + Commands.RecoveryServices + + + {e1f5201d-6067-430e-b303-4e367652991b} + Commands.Resources + + + {30b92759-50b3-494e-b9f0-ec9a2ce9d57b} + Commands.RecoveryServices.Backup.Models + + + {3b3e879a-f856-46bf-aff9-8ad6760cf7b9} + Commands.RecoveryServices.Backup.Cmdlets + + + + + + + + + + \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/ContainerTests.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/ContainerTests.cs new file mode 100644 index 000000000000..9b4a813d4914 --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/ContainerTests.cs @@ -0,0 +1,51 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; +using Microsoft.WindowsAzure.Commands.ScenarioTest; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Xunit; + +namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Test.ScenarioTests +{ + public partial class ContainerTests : RMTestBase + { + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + [Trait(TestConstants.Workload, TestConstants.AzureWorkload)] + public void GetAzureWorkloadContainer() + { + TestController.NewInstance.RunPsTest( + _logger, PsBackupProviderTypes.AzureWorkload, "Get-AzureWorkloadContainer"); + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + [Trait(TestConstants.Workload, TestConstants.AzureWorkload)] + public void RegisterAzureWorkloadContainer() + { + TestController.NewInstance.RunPsTest( + _logger, PsBackupProviderTypes.AzureWorkload, "Register-AzureWorkloadContainer"); + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + [Trait(TestConstants.Workload, TestConstants.AzureWorkload)] + public void UnregisterAzureWorkloadContainer() + { + TestController.NewInstance.RunPsTest( + _logger, PsBackupProviderTypes.AzureWorkload, "Unregister-AzureWorkloadContainer"); + } + } +} diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/ContainerTests.ps1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/ContainerTests.ps1 new file mode 100644 index 000000000000..56b2edbc929c --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/ContainerTests.ps1 @@ -0,0 +1,67 @@ +# ---------------------------------------------------------------------------------- +# +# Copyright Microsoft Corporation +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------------- + +function Get-AzureWorkloadContainer +{ + try + { + Get-AzureRmRecoveryServicesVault -ResourceGroupName 'sisi-RSV' -Name 'sisi-RSV-29-6' | Set-AzureRmRecoveryServicesVaultContext + + # VARIATION-1: Get All Containers with only mandatory parameters + $containers = Get-AzureRmRecoveryServicesBackupContainer ` + -ContainerType AzureWorkload + } + finally + { + + } +} + +function Register-AzureWorkloadContainer +{ + try + { + Get-AzureRmRecoveryServicesVault -ResourceGroupName 'sisi-RSV' -Name 'sisi-RSV-29-6' | Set-AzureRmRecoveryServicesVaultContext + + # VARIATION-1: Get All Containers with only mandatory parameters + $containers = Register-AzRecoveryServicesBackupContainer ` + -ResourceId "/subscriptions/da364f0f-307b-41c9-9d47-b7413ec45535/resourceGroups/sisi-RSV/providers/Microsoft.Compute/virtualMachines/sisi-vm" ` + -BackupManagementType AzureWorkload ` + -WorkloadType MSSQL + } + finally + { + + } +} + +function Unregister-AzureWorkloadContainer +{ + try + { + Get-AzureRmRecoveryServicesVault -ResourceGroupName 'sisi-RSV' -Name 'sisi-RSV-29-6' | Set-AzureRmRecoveryServicesVaultContext + + $containers = Get-AzureRmRecoveryServicesBackupContainer ` + -ContainerType AzureWorkload + + Unregister-AzureRmRecoveryServicesBackupContainer ` + -Container $containers[0] + + + } + finally + { + + } +} \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/TestConstants.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/TestConstants.cs index ed14871dd2d9..08a52174f6f8 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/TestConstants.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/TestConstants.cs @@ -30,5 +30,7 @@ public class TestConstants public const string MAB = "MAB"; public const string AzureFS = "AzureFS"; + + public const string AzureWorkload = "AzureWorkload"; } } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesBackupContainer.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesBackupContainer.cs index 59d770e5b729..06b792506bbd 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesBackupContainer.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesBackupContainer.cs @@ -12,13 +12,13 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using System; -using System.Collections.Generic; -using System.Management.Automation; using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel; using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; +using System; +using System.Collections.Generic; +using System.Management.Automation; namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets { diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/RegisterAzureRmRecoveryServicesBackupContainer.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/RegisterAzureRmRecoveryServicesBackupContainer.cs new file mode 100644 index 000000000000..f8a38e3b28e6 --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/RegisterAzureRmRecoveryServicesBackupContainer.cs @@ -0,0 +1,98 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; +using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel; +using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers; +using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; +using Microsoft.Azure.Management.RecoveryServices.Backup.Models; +using Microsoft.Rest.Azure.OData; +using System; +using System.Collections.Generic; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets +{ + /// + /// Unregisters container from the recovery services vault. + /// + [Cmdlet("Register", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesBackupContainer", SupportsShouldProcess = true), OutputType(typeof(ContainerBase))] + public class RegisterAzureRmRecoveryServicesBackupContainer + : RSBackupVaultCmdletBase + { + /// + /// Azure Vm Id. + /// + [Parameter(Mandatory = true, Position = 1, + HelpMessage = ParamHelpMsgs.Container.ResourceId)] + [ValidateNotNullOrEmpty] + public string ResourceId { get; set; } + + /// + /// The backup management type of the container(s) to be fetched. + /// + [Parameter(Mandatory = true, Position = 2, + HelpMessage = ParamHelpMsgs.Container.BackupManagementType)] + [ValidateNotNullOrEmpty] + [ValidateSet("AzureWorkload")] + public Models.BackupManagementType BackupManagementType { get; set; } + + /// + /// Workload type of the item to be returned. + /// + [Parameter(Mandatory = true, Position = 3, + HelpMessage = ParamHelpMsgs.Common.WorkloadType)] + [ValidateNotNullOrEmpty] + public Models.WorkloadType WorkloadType { get; set; } + + public override void ExecuteCmdlet() + { + ExecutionBlock(() => + { + base.ExecuteCmdlet(); + + ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); + string vaultName = resourceIdentifier.ResourceName; + string vaultResourceGroupName = resourceIdentifier.ResourceGroupName; + + string containerName = ResourceId.Split('/')[8]; + + PsBackupProviderManager providerManager = + new PsBackupProviderManager(new Dictionary() + { + { VaultParams.VaultName, vaultName }, + { VaultParams.ResourceGroupName, vaultResourceGroupName }, + { ContainerParams.Name, containerName }, + { ContainerParams.ContainerType, ServiceClientHelpers.GetServiceClientWorkloadType(WorkloadType).ToString() }, + { ContainerParams.BackupManagementType, BackupManagementType.ToString() }, + }, ServiceClientAdapter); + + IPsBackupProvider psBackupProvider = + providerManager.GetProviderInstance(WorkloadType, BackupManagementType); + psBackupProvider.RegisterContainer(); + + // List containers + string backupManagementType = BackupManagementType.ToString(); + ODataQuery queryParams = new ODataQuery( + q => q.FriendlyName == containerName && + q.BackupManagementType == backupManagementType); + + var listResponse = ServiceClientAdapter.ListContainers(queryParams, + vaultName: vaultName, resourceGroupName: vaultResourceGroupName); + var containerModels = ConversionHelpers.GetContainerModelList(listResponse); + WriteObject(containerModels, enumerateCollection: true); + }, ShouldProcess(ResourceId, VerbsLifecycle.Register)); + } + } +} diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/UnregisterAzureRmRecoveryServicesBackupContainer.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/UnregisterAzureRmRecoveryServicesBackupContainer.cs index 68a2977e19e4..7cc073eac105 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/UnregisterAzureRmRecoveryServicesBackupContainer.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Cmdlets/Container/UnregisterAzureRmRecoveryServicesBackupContainer.cs @@ -12,11 +12,11 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using System; -using System.Management.Automation; using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties; using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; +using System; +using System.Management.Automation; namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets { @@ -56,7 +56,9 @@ public override void ExecuteCmdlet() (Container.ContainerType == ContainerType.AzureSQL && Container.BackupManagementType == BackupManagementType.AzureSQL) || (Container.ContainerType == ContainerType.AzureStorage && - Container.BackupManagementType == BackupManagementType.AzureStorage))) + Container.BackupManagementType == BackupManagementType.AzureStorage) || + (Container.ContainerType == ContainerType.AzureWorkload && + Container.BackupManagementType == BackupManagementType.AzureWorkload))) { throw new ArgumentException(string.Format(Resources.UnsupportedContainerException, Container.ContainerType, Container.BackupManagementType)); diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Commands.RecoveryServices.Backup.Cmdlets.csproj b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Commands.RecoveryServices.Backup.Cmdlets.csproj new file mode 100644 index 000000000000..58e7a4d0112f --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/Commands.RecoveryServices.Backup.Cmdlets.csproj @@ -0,0 +1,128 @@ + + + + + + Debug + AnyCPU + {3B3E879A-F856-46BF-AFF9-8AD6760CF7B9} + Library + Properties + Microsoft.Azure.Commands.RecoveryServices.Backup + Microsoft.Azure.Commands.RecoveryServices.Backup + v4.5.2 + 512 + .\ + true + + + true + full + false + ..\..\..\Package\Debug\ResourceManager\AzureResourceManager\AzureRM.RecoveryServices.Backup\ + TRACE;DEBUG;CODE_ANALYSIS + prompt + 4 + true + + + + + pdbonly + true + ..\..\..\Package\Release\ResourceManager\AzureResourceManager\AzureRM.RecoveryServices.Backup\ + prompt + 4 + TRACE;SIGN + true + MSSharedLibKey.snk + true + false + + + + False + ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.Backup.3.0.1-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.Backup.dll + + + ..\..\..\packages\Microsoft.WindowsAzure.Management.Scheduler.6.0.0\lib\net40\Microsoft.WindowsAzure.Management.Scheduler.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {142d7b0b-388a-4ceb-a228-7f6d423c5c2e} + Commands.Profile + + + {0e1d3f36-e6c8-4764-8c7d-6f9ee537490c} + Commands.RecoveryServices.Backup.Helpers + + + {5e675749-6139-464a-904c-59c0ffdfec82} + Commands.RecoveryServices.Backup.Logger + + + {30b92759-50b3-494e-b9f0-ec9a2ce9d57b} + Commands.RecoveryServices.Backup.Models + + + {02234e90-bcde-4b20-b1f5-01b1005821db} + Commands.RecoveryServices.Backup.Providers + + + {b758fec1-35c1-4f93-a954-66dd33f6e0ec} + Commands.RecoveryServices.Backup.ServiceClientAdapter + + + + + Always + + + Always + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/ParamHelpMsgs.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/ParamHelpMsgs.cs index 3a14c9d7553d..7ad1fda9a18b 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/ParamHelpMsgs.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup/ParamHelpMsgs.cs @@ -30,6 +30,7 @@ internal static class Container public const string RegisteredContainer = "The recovery services backup container."; public const string FriendlyName = "The name of the resource being managed by the" + " Azure Backup service (for example: resource name of the VM)."; + public const string ResourceId = "Azure VM Id"; } internal static class Common diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Az.RecoveryServices.psd1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Az.RecoveryServices.psd1 index 3e71809e8fa6..e7d3532cdb1b 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Az.RecoveryServices.psd1 +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Az.RecoveryServices.psd1 @@ -155,7 +155,8 @@ CmdletsToExport = 'Get-AzRecoveryServicesBackupProperty', 'Set-AzRecoveryServicesVaultContext', 'Backup-AzRecoveryServicesBackupItem', 'Get-AzRecoveryServicesBackupManagementServer', - 'Get-AzRecoveryServicesBackupContainer', + 'Get-AzRecoveryServicesBackupContainer', + 'Register-AzRecoveryServicesBackupContainer', 'Unregister-AzRecoveryServicesBackupContainer', 'Disable-AzRecoveryServicesBackupProtection', 'Enable-AzRecoveryServicesBackupProtection',