def create_user_with_bill(request): if request.method == "POST": form = CreateNewUserWithBill(request.POST) if form.is_valid(): data = form.clean() # TODO Make this a real request try: LOG.info('Creating tenant with name "%s"' % data['id']) new_tenant = api.tenant_create(request, data['id'], "Tenant", True) messages.success(request, 'tenant %s was successfully created.' % data['id']) LOG.info('Creating user with name "%s"' % data['id']) new_user = api.user_create(request, data['id'], data['id'] + "@dammyemail", data['password'], new_tenant.id, True) messages.success(request, 'User "%s" was successfully created.' % data['id']) try: api.role_add_for_tenant_user( request, new_tenant.id, new_user.id, settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE) except api_exceptions.ApiException, e: LOG.exception('ApiException while assigning\ role to new user: %s' % new_user.id) messages.error(request, 'Error assigning role to user: %s' % e.message) accountRecord = AccountRecord(tenant_id=new_tenant.id,amount=int(data['amount']),memo="Initial addtion") accountRecord.save() msg = '%s was successfully added to %s.' % (data['amount'], new_tenant.id) LOG.info(msg) messages.success(request, msg) msg = """ Please send following messege to the user: Your freecloud account is succesfully created. Url:https://www.thefreecloud.org Username: %s Password:%s Manual is here:(URL) Your inisial stack doller: %s """ % ( data['id'],data['password'],data['amount']) messages.success(request,msg) return shortcuts.redirect('syspanel_create_user_with_bill') except api_exceptions.ApiException, e: LOG.exception('ApiException while creating a record\n' '%r' % data) messages.error(request, 'Error creating record: %s' % e.message) return shortcuts.redirect('syspanel_billing')
def create(request): tenants = api.tenant_list(request) if request.method == "POST": form = UserForm(request.POST, tenant_list=tenants) if form.is_valid(): user = form.clean() # TODO Make this a real request try: api.user_create(request, user["id"], user["email"], user["password"], user["tenant_id"], True) messages.success(request, "%s was successfully created." % user["id"]) return redirect("syspanel_users") except api_exceptions.ApiException, e: messages.error(request, "Error creating user: %s" % e.message) return redirect("syspanel_users") else: return render_to_response( "syspanel_user_create.html", {"form": form}, context_instance=template.RequestContext(request) )
def test_user_create(self): account_api = self.stub_account_api() account_api.users = self.mox.CreateMockAnything() account_api.users.create(TEST_USERNAME, TEST_EMAIL, TEST_PASSWORD, TEST_TENANT_ID, True).AndReturn(TEST_RETURN) self.mox.ReplayAll() ret_val = api.user_create(self.request, TEST_USERNAME, TEST_EMAIL, TEST_PASSWORD, TEST_TENANT_ID, True) self.assertIsInstance(ret_val, api.User) self.assertEqual(ret_val._apiresource, TEST_RETURN) self.mox.VerifyAll()
def create(request): try: tenants = api.tenant_list(request) except api_exceptions.ApiException, e: messages.error(request, 'Unable to retrieve tenant list: %s' % e.message) return redirect('syspanel_users') if request.method == "POST": form = UserForm(request.POST, tenant_list=tenants) if form.is_valid(): user = form.clean() # TODO Make this a real request try: LOG.info('Creating user with id "%s"' % user['id']) api.user_create(request, user['id'], user['email'], user['password'], user['tenant_id'], True) api.account_api(request).role_refs.add_for_tenant_user( user['tenant_id'], user['id'], settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE) messages.success(request, '%s was successfully created.' % user['id']) return redirect('syspanel_users') except api_exceptions.ApiException, e: LOG.error('ApiException while creating user\n' 'id: "%s", email: "%s", tenant_id: "%s"' % (user['id'], user['email'], user['tenant_id']), exc_info=True) messages.error(request, 'Error creating user: %s' % e.message) return redirect('syspanel_users')
tenants = api.tenant_list(request) except api_exceptions.ApiException, e: messages.error(request, 'Unable to retrieve tenant list: %s' % e.message) return redirect('syspanel_users') if request.method == "POST": form = UserForm(request.POST, tenant_list=tenants) if form.is_valid(): user = form.clean() # TODO Make this a real request try: LOG.info('Creating user with name "%s"' % user['name']) new_user = api.user_create(request, user['name'], user['email'], user['password'], user['tenant_id'], True) messages.success(request, 'User "%s" was successfully created.' % user['name']) try: api.role_add_for_tenant_user( request, user['tenant_id'], new_user.id, settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE) except api_exceptions.ApiException, e: LOG.exception('ApiException while assigning\ role to new user: %s' % new_user.id) messages.error(request, 'Error assigning role to user: %s' % e.message)
tenants = api.tenant_list(request) except api_exceptions.ApiException, e: messages.error(request, 'Unable to retrieve tenant list: %s' % e.message) return redirect('syspanel_users') if request.method == "POST": form = UserForm(request.POST, tenant_list=tenants) if form.is_valid(): user = form.clean() # TODO Make this a real request try: LOG.info('Creating user with id "%s"' % user['id']) api.user_create(request, user['id'], user['email'], user['password'], user['tenant_id'], True) api.account_api(request).role_refs.add_for_tenant_user( user['tenant_id'], user['id'], settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE) messages.success(request, '%s was successfully created.' % user['id']) return redirect('syspanel_users') except api_exceptions.ApiException, e: LOG.error('ApiException while creating user\n' 'id: "%s", email: "%s", tenant_id: "%s"' % (user['id'], user['email'], user['tenant_id']),
@enforce_admin_access def create(request): try: tenants = api.tenant_list(request) except api_exceptions.ApiException, e: messages.error(request, _("Unable to retrieve tenant list: %s") % e.message) return redirect("syspanel_users") if request.method == "POST": form = UserForm(request.POST, tenant_list=tenants) if form.is_valid(): user = form.clean() # TODO Make this a real request try: LOG.info('Creating user with id "%s"' % user["id"]) api.user_create(request, user["id"], user["email"], user["password"], user["tenant_id"], True) messages.success(request, _("%s was successfully created.") % user["id"]) try: api.role_add_for_tenant_user( request, user["tenant_id"], user["id"], settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE ) except api_exceptions.ApiException, e: LOG.exception( "ApiException while assigning\ role to new user: %s" % user["id"] ) messages.error(request, _("Error assigning role to user: %s") % e.message) return redirect("syspanel_users")