def settings(request): """ Project Settings; ADMIN ONLY; add/edit/delete current tenant's users """ # work around lack of keystone session; recreate keystone client on page arrival api.joinTenant(request.session['username'], request.session['password'], request.session['tenant']) tenant = api.getTenant(request.session['tenant']) users = api.listUsers(tenant) return render(request, 'settings.html', {'tenant': tenant.name, 'users': users})
def removeUser(request): """ Remove user from current project """ if request.method == "POST": form = UserRemoveForm(request.POST) if form.is_valid(): # recreate keystone client; keystone session work around api.joinTenant(request.session['username'], request.session['password'], projectName) api.removeUser(form.cleaned_data['userName'], form.cleaned_data['roleName'], projectName) return HttpResponseRedirect('/project_space/manage/settings')
def editRole(request): """ Add role to selected user for current project """ if request.method == "POST": form = RoleEditForm(request.POST) if form.is_valid(): # recreate keystone client; keystone session work around api.joinTenant(request.session['username'], request.session['password'], request.session['tenant']) if form.cleaned_data['editAction'] == 'add': api.addRole(form.cleaned_data['userName'], form.cleaned_data['roleName'], request.session['tenant']) elif form.cleaned_data['editAction'] == 'remove': api.removeUserRole(form.cleaned_data['userName'], form.cleaned_data['roleName'], request.session['tenant']) return HttpResponseRedirect('/project_space/manage/settings')
def enterProject(request): """ Called when a tenant is chosen on Projects page; attempt to enter tenant via keystone """ if request.method == 'POST': form = TenantLoginForm(request.POST) if form.is_valid(): tenantName = form.cleaned_data['tenantName'] request.session['tenant'] = tenantName tenantID = form.cleaned_data['tenantID'] # send session user/pw and selected tenant to keystone api.joinTenant(request.session['username'], request.session['password'], tenantName) return HttpResponseRedirect('/project_space/manage') print('Invalid User') return HttpResponseRedirect('/projects/')
def register(request): """ Register new user with keystone; called from login page Needs error checking """ if request.method == "POST": form = UserRegisterForm(request.POST) if form.is_valid(): request.session['username'] = form.cleaned_data['userName'] request.session['password'] = form.cleaned_data['userPwd'] email = form.cleaned_data['userEmail'] # Work around - login as admin keystone client for user creation # then logged into new user from projects page arrival api.joinTenant('admin', 'admin', 'demo') # register user with keystone api.registerUser(request.session['username'], request.session['password'], email) # login as new user #api.login(request.session['username'], request.session['password']) return HttpResponseRedirect('/projects/')
def manage(request): """ Project Management page; edit VMs, project settings """ if request.method == 'POST': form = VMCreateForm(request.POST) if form.is_valid(): VMname = form.cleaned_data['newVM'] image = form.cleaned_data['imageName'] flavor = form.cleaned_data['flavorName'] return HttpResponseRedirect('/project_space/manage/create/'+VMname+';'+image+';'+flavor) # temporary fix to ensure user stays connected to current project api.joinTenant(request.session['username'], request.session['password'], request.session['tenant']) VMs = api.listVMs() images = api.listImages() flavors = api.listFlavors() return render(request, 'manage.html', {'project_VMs':VMs, 'images':images, 'flavors':flavors, 'tenant':request.session['tenant']})
def projects(request): tenant = api.joinTenant(request, 'atmosphere') project_name = models.ClusterProject.objects.all() project_list = [] for project in project_name: project_list += [{'name': project}] return render(request, 'projects.html', {'project_list': project_list, 'project_modals': html.project_modals(request) })
def createProject(request): """ Create new project from Projects page """ if request.method == 'POST': form = TenantCreateForm(request.POST) if form.is_valid(): projectName = form.cleaned_data['tenantName'] projectDesc = form.cleaned_data['tenantDesc'] # work around for user to have project creation privileges # for some reason, unable to create a project unless # keystone client is passed a tenant_name arguement; can't create solely as user api.joinTenant('admin', 'admin', 'demo') # create project with current keystone session api.createTenant(projectName, projectDesc) # add user to new project with admin role api.addUser(request.session['username'], 'admin', projectName) print ('Unable to create new Project') return HttpResponseRedirect('/projects')