public async Task <ActionResult> Step2Avere(AddAvereClusterModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create/Step2Avere", 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 }));
            }

            // validate the resource group doesn't exist
            var client = await GetResourceClient(model.SubscriptionId.ToString());

            if (!await ValidateResourceGroup(client, model.NewResourceGroupName))
            {
                return(View("Create/Step2Avere", model));
            }

            try
            {
                // update and save the model before we deploy as we can always retry the create
                repository.UpdateFromModel(model);

                await _assetRepoCoordinator.BeginRepositoryDeploymentAsync(
                    repository,
                    _managementClientProvider,
                    _azureResourceProvider);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", $"Failed to create repository with error: {ex}");
                return(View("Create/Step2Avere", model));
            }

            return(RedirectToAction("Overview", new { repoId = repository.Name }));
        }
Example #2
0
        public async Task <ActionResult> Step3Avere(string repoId, AddAvereClusterModel model)
        {
            if (model.UseControllerPasswordCredential && string.IsNullOrWhiteSpace(model.ControllerPassword))
            {
                ModelState.AddModelError(nameof(AddAvereClusterModel.ControllerPassword),
                                         "A controller password must be specified.");
            }

            if (!model.UseControllerPasswordCredential && string.IsNullOrWhiteSpace(model.ControllerSshKey))
            {
                ModelState.AddModelError(nameof(AddAvereClusterModel.ControllerSshKey),
                                         "A controller SSH key must be specified.");
            }

            var allowedVMSizes = new [] { "standard_e8s_v3", "standard_e16s_v3", "standard_e32s_v3", "standard_d16s_v3" };

            if (!allowedVMSizes.Contains(model.VMSize.ToLowerInvariant()))
            {
                ModelState.AddModelError(nameof(AddAvereClusterModel.VMSize),
                                         $"The Avere vFXT VM size must be one of {string.Join(", ", allowedVMSizes)}");
            }

            if (model.CacheSizeInGB != 1024 && model.CacheSizeInGB != 4096)
            {
                ModelState.AddModelError(nameof(AddAvereClusterModel.CacheSizeInGB),
                                         $"The Avere vFXT cache size must be either 1024 or 4096.");
            }

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

            var repository = await _assetRepoCoordinator.GetRepository(repoId);

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

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

            // 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/Step3Avere", model));
                }
            }

            try
            {
                // update and save the model before we deploy as we can always retry the create
                repository.UpdateFromModel(model);

                await _assetRepoCoordinator.BeginRepositoryDeploymentAsync(repository);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Failed to create repository {repository.Name} in subscription {repository.SubscriptionId}");
                ModelState.AddModelError("", $"Failed to create repository: {ex.Message}");
                return(View("Create/Step3Avere", model));
            }

            return(RedirectToAction("Overview", new { repoId = repository.Name }));
        }
Example #3
0
        public async Task <ActionResult> Step3(string repoId)
        {
            var repository = await _assetRepoCoordinator.GetRepository(repoId);

            if (repository == null)
            {
                // redirect to Step1 if no config.
                return(RedirectToAction("Index"));
            }

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

            string error        = null;
            string errorMessage = null;

            var canCreateTask = _azureResourceProvider.CanCreateResources(repository.SubscriptionId);
            var canAssign     = await _azureResourceProvider.CanCreateRoleAssignments(
                repository.SubscriptionId,
                repository.ResourceGroupName);

            var canCreate = await canCreateTask;

            if (!canCreate)
            {
                error        = "You don't have the required permissions to create resources";
                errorMessage = "In order to complete this step which involves creating resources, you must have the Owner or Contributor role for the specified Subscription. " +
                               "Either request someone with this role to complete the step, or ask your admin to make you an Owner or Contributor for the Subscription.";
            }
            else
            {
                if (!canAssign)
                {
                    error        = "You don't have the required permissions to assign roles to users";
                    errorMessage = "In order to complete this step which involves creating role assignments, you must have the Owner or User Access Administrator role for the specified Subscription. " +
                                   "Either request someone with this role to complete the step, or ask your admin to make you an Owner or User Access Administrator for the Subscription or Resource Group.";
                }
            }

            switch (repository)
            {
            case NfsFileServer nfs:
                return(View("Create/Step3FileServer", new AddNfsFileServerModel(nfs)
                {
                    VmName = "FileServer",
                    UserName = "******",
                    Password = Guid.NewGuid().ToString(),
                    FileShareName = "/exports/share",
                    Error = error,
                    ErrorMessage = errorMessage
                }));

            case AvereCluster avere:
                var model = new AddAvereClusterModel(avere)
                {
                    Error        = error,
                    ErrorMessage = errorMessage
                };

                return(View("Create/Step3Avere", model));

            default:
                throw new NotSupportedException("Unknown type of repository");
            }
        }