Example #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')
Example #2
0
@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_billing')

    if request.method == "POST":
        form = CreateAccountRecord(request.POST, tenant_list=tenants)
        if form.is_valid():
            data = form.clean()
            # TODO Make this a real request
            try:
                accountRecord = AccountRecord(tenant_id=data['tenant_id'],amount=int(data['amount']),memo=data['memo'])
                accountRecord.save()
                msg = '%s was successfully added to .' % data['tenant_id']
                LOG.info(msg)
                messages.success(request, msg)
                return shortcuts.redirect('syspanel_billing')

            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')
        else:
            return shortcuts.render_to_response(
            'syspanel_create_account.html', {