Пример #1
0
        public async Task <ActionResult> Step3FileServer(string repoId, AddNfsFileServerModel model)
        {
            // Validate that the share isn't a root share
            if (model.FileShareName.StartsWith("/") &&
                model.FileShareName.Split("/", StringSplitOptions.RemoveEmptyEntries).Length == 1)
            {
                ModelState.AddModelError(nameof(AddNfsFileServerModel.FileShareName), "File share cannot be at the root of the file system, e.g. /share.");
            }

            if (!ModelState.IsValid)
            {
                return(View("Create/Step3FileServer", model));
            }

            var repository = await _assetRepoCoordinator.GetRepository(repoId);

            if (repository == null)
            {
                return(RedirectToAction("Overview"));
            }

            // validate the resource group doesn't exist or is empty
            var client = await _managementClientProvider.CreateResourceManagementClient(repository.SubscriptionId);

            if (!await ValidateResourceGroup(client, model.NewResourceGroupName, nameof(model.NewResourceGroupName)))
            {
                if (!ModelState.IsValid)
                {
                    return(View("Create/Step3FileServer", model));
                }
            }

            if (repository.Enabled)
            {
                return(RedirectToAction("Overview"));
            }

            try
            {
                repository.UpdateFromModel(model);
                await _assetRepoCoordinator.BeginRepositoryDeploymentAsync(repository);
            }
            catch (Exception ex)
            {
                model.Error        = "Failed to create repository with error";
                model.ErrorMessage = ex.ToString();
                return(View("Create/Step3FileServer", model));
            }

            return(RedirectToAction("Overview", new { repoId = repository.Name }));
        }
        public async Task <ActionResult> Step2Nfs(AddNfsFileServerModel model)
        {
            // Validate that the share isn't a root share
            if (model.FileShareName.StartsWith("/") &&
                model.FileShareName.Split("/", StringSplitOptions.RemoveEmptyEntries).Length == 1)
            {
                ModelState.AddModelError(nameof(AddNfsFileServerModel.FileShareName), "File share cannot be at the root of the file system, e.g. /share.");
            }

            if (!ModelState.IsValid)
            {
                return(View("Create/Step2Nfs", model));
            }

            var repository = await _assetRepoCoordinator.GetRepository(model.RepositoryName);

            if (repository == null)
            {
                return(BadRequest("No new storage repository configuration in progress"));
            }

            if (repository.Enabled)
            {
                // not allowed to edit an existing enabled config
                return(RedirectToAction("Overview", new { repoId = repository.Name }));
            }

            try
            {
                repository.UpdateFromModel(model);
                await _assetRepoCoordinator.BeginRepositoryDeploymentAsync(repository, _managementClientProvider, _azureResourceProvider);
            }
            catch (Exception ex)
            {
                model.Error        = "Failed to create repository with error";
                model.ErrorMessage = ex.ToString();
                return(View("Create/Step2Nfs", model));
            }

            return(RedirectToAction("Deploying", new { repoId = repository.Name }));
        }