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]; ContainerBase containerBase = (ContainerBase)ProviderData[ContainerParams.Container]; AzureVmWorkloadContainer container = (AzureVmWorkloadContainer)ProviderData[ContainerParams.Container]; ProtectionContainerResource protectionContainerResource = null; //Trigger Discovery ODataQuery <BMSRefreshContainersQueryObject> queryParam = new ODataQuery <BMSRefreshContainersQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureWorkload); AzureWorkloadProviderHelper.RefreshContainer(vaultName, vaultResourceGroupName, queryParam); List <ProtectableContainerResource> unregisteredVmContainers = GetUnRegisteredVmContainers(vaultName, vaultResourceGroupName); ProtectableContainerResource unregisteredVmContainer = unregisteredVmContainers.Find( vmContainer => string.Compare(vmContainer.Name.Split(';').Last(), containerName, true) == 0); if (unregisteredVmContainer != null || container != null) { protectionContainerResource = new ProtectionContainerResource(container != null ? container.Id : unregisteredVmContainer.Id, container != null ? container.Name : unregisteredVmContainer.Name); AzureVMAppContainerProtectionContainer azureVMContainer = new AzureVMAppContainerProtectionContainer( friendlyName: containerName, backupManagementType: backupManagementType, sourceResourceId: container != null ? container.SourceResourceId : unregisteredVmContainer.Properties.ContainerId, workloadType: workloadType.ToString(), operationType: container != null ? OperationType.Reregister : OperationType.Register); protectionContainerResource.Properties = azureVMContainer; AzureWorkloadProviderHelper.RegisterContainer(container != null ? container.Name : unregisteredVmContainer.Name, protectionContainerResource, vaultName, vaultResourceGroupName); } else { throw new ArgumentException(string.Format(Resources.AzureWorkloadAlreadyRegisteredException)); } }
private WorkloadProtectableItemResource GetAzureFileShareProtectableObject( string azureFileShareName, string storageAccountName, string vaultName = null, string vaultResourceGroupName = null) { //Trigger Discovery ODataQuery <BMSRefreshContainersQueryObject> queryParam = new ODataQuery <BMSRefreshContainersQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureStorage); AzureWorkloadProviderHelper.RefreshContainer(vaultName, vaultResourceGroupName, queryParam); //get registered storage accounts bool isRegistered = false; string storageContainerName = null; List <ContainerBase> registeredStorageAccounts = GetRegisteredStorageAccounts(vaultName, vaultResourceGroupName); ContainerBase registeredStorageAccount = registeredStorageAccounts.Find( storageAccount => string.Compare(storageAccount.Name.Split(';').Last(), storageAccountName, true) == 0); if (registeredStorageAccount != null) { isRegistered = true; storageContainerName = "StorageContainer;" + registeredStorageAccount.Name; } //get unregistered storage account if (!isRegistered) { List <ProtectableContainerResource> unregisteredStorageAccounts = GetUnRegisteredStorageAccounts(vaultName, vaultResourceGroupName); ProtectableContainerResource unregisteredStorageAccount = unregisteredStorageAccounts.Find( storageAccount => string.Compare(storageAccount.Name.Split(';').Last(), storageAccountName, true) == 0); if (unregisteredStorageAccount != null) { //unregistered //check for source Id for storageAccountId in ProtectionContainerResource storageContainerName = unregisteredStorageAccount.Name; ProtectionContainerResource protectionContainerResource = new ProtectionContainerResource(unregisteredStorageAccount.Id, unregisteredStorageAccount.Name); AzureStorageContainer azureStorageContainer = new AzureStorageContainer( friendlyName: storageAccountName, backupManagementType: ServiceClientModel.BackupManagementType.AzureStorage, sourceResourceId: unregisteredStorageAccount.Properties.ContainerId, resourceGroup: vaultResourceGroupName); protectionContainerResource.Properties = azureStorageContainer; AzureWorkloadProviderHelper.RegisterContainer(unregisteredStorageAccount.Name, protectionContainerResource, vaultName, vaultResourceGroupName); } } //inquiry AzureWorkloadProviderHelper.TriggerInquiry(vaultName, vaultResourceGroupName, storageContainerName, ServiceClientModel.WorkloadType.AzureFileShare); //get protectable item WorkloadProtectableItemResource protectableObjectResource = null; protectableObjectResource = GetProtectableItem(vaultName, vaultResourceGroupName, azureFileShareName, storageAccountName); if (protectableObjectResource == null) { // Container is not discovered. Throw exception string errorMessage = string.Format( Resources.AFSDiscoveryFailure, azureFileShareName, vaultResourceGroupName); Logger.Instance.WriteDebug(errorMessage); Logger.Instance.WriteError( new ErrorRecord(new Exception(Resources.FileShareNotDiscovered), string.Empty, ErrorCategory.InvalidArgument, null)); } return(protectableObjectResource); }