Exemplo n.º 1
0
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')
Exemplo n.º 2
0
 def handle(self, request, data):
     try:
         api.role_add_for_tenant_user(
             request, data['tenant'], data['user'],
             settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE)
         messages.success(
             request, '%s was successfully added to %s.' %
             (data['user'], data['tenant']))
     except api_exceptions.ApiException, e:
         messages.error(
             request, 'Unable to create user association: %s' % (e.message))
Exemplo n.º 3
0
 def handle(self, request, data):
     try:
         api.role_add_for_tenant_user(
                 request,
                 data['tenant'],
                 data['user'],
                 settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE)
         messages.success(request,
                         '%(user)s was successfully added to %(tenant)s.'
                         % {"user": data['user'], "tenant": data['tenant']})
     except api_exceptions.ApiException, e:
         messages.error(request, _('Unable to create user association: %s')
                        % (e.message))
Exemplo n.º 4
0
            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)

                return redirect('syspanel_users')

            except api_exceptions.ApiException, e:
                LOG.exception('ApiException while creating user\n'
                          'name: "%s", email: "%s", tenant_id: "%s"' %
                          (user['name'], user['email'], user['tenant_id']))
                messages.error(request,
                                 'Error creating user: %s'
Exemplo n.º 5
0
            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)

                return redirect('syspanel_users')

            except api_exceptions.ApiException, e:
                LOG.exception('ApiException while creating user\n'
                          'name: "%s", email: "%s", tenant_id: "%s"' %
                          (user['name'], user['email'], user['tenant_id']))
                messages.error(request,
                                 'Error creating user: %s'
Exemplo n.º 6
0
    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")

            except api_exceptions.ApiException, e:
                LOG.exception(
                    "ApiException while creating user\n"
                    'id: "%s", email: "%s", tenant_id: "%s"' % (user["id"], user["email"], user["tenant_id"])