Example #1
0
def add_project_user(project_id):
    user_id = parse_request_data(required=_SCHEMA.required)['id']
    tenant = get_tenant(project_id)
    user = _get_user(user_id)
    set_audit_resource_id(user_id)

    try:
        tenant.add_user(user.id, member_role_id())
    except osc_exc.NotFound:
        user = _get_user(user_id)  # check that user still exists
        abort(404)  # if user still exists, tenant was removed

    return make_json_response(link_for_user(user))
Example #2
0
def add_project_user(project_id):
    user_id = parse_request_data(required=_SCHEMA.required)['id']
    tenant = get_tenant(project_id)
    user = _get_user(user_id)
    set_audit_resource_id(user_id)

    try:
        tenant.add_user(user.id, member_role_id())
    except osc_exc.NotFound:
        user = _get_user(user_id)  # check that user still exists
        abort(404)  # if user still exists, tenant was removed

    return make_json_response(link_for_user(user))
Example #3
0
def remove_project_user(project_id, user_id):
    tenant = get_tenant(project_id)
    if user_id != current_user_id():
        assert_admin()

    try:
        user_mgr = admin_client_set().identity_admin.users
        roles = user_mgr.list_roles(user_id, project_id)
    except osc_exc.NotFound:
        abort(404)
    if not roles:
        abort(404)  # user was not member of the project

    for role in roles:
        try:
            tenant.remove_user(user_id, role.id)
        except osc_exc.NotFound:
            pass  # already deleted by someone else
    return make_json_response(None, status_code=204)
Example #4
0
def remove_project_user(project_id, user_id):
    tenant = get_tenant(project_id)
    if user_id != current_user_id():
        assert_admin()

    try:
        user_mgr = admin_client_set().identity_admin.users
        roles = user_mgr.list_roles(user_id, project_id)
    except osc_exc.NotFound:
        abort(404)
    if not roles:
        abort(404)  # user was not member of the project

    for role in roles:
        try:
            tenant.remove_user(user_id, role.id)
        except osc_exc.NotFound:
            pass  # already deleted by someone else
    return make_json_response(None, status_code=204)
Example #5
0
def get_project_stats(project_id):
    tenant = get_tenant(project_id)
    acs = auth.admin_client_set()
    users = acs.identity_admin.tenants.list_users(tenant.id)

    tcs = auth.client_set_for_tenant(project_id, fallback_to_api=g.is_admin)
    servers = tcs.compute.servers.list()
    images = tcs.image.images.list()
    local_images = [image for image in images
                    if image.owner == tenant.id]

    return make_json_response({
        u'project': link_for_tenant(tenant),
        u'instances': len(servers),
        u'members': len(users),
        u'local-images': len(local_images),
        u'total-images': len(images),
        'href': url_for('stats.get_project_stats',
                        project_id=tenant.id)
    })
Example #6
0
def get_project_stats(project_id):
    tenant = get_tenant(project_id)
    acs = auth.admin_client_set()
    users = acs.identity_admin.tenants.list_users(tenant.id)

    tcs = auth.client_set_for_tenant(project_id, fallback_to_api=g.is_admin)
    servers = tcs.compute.servers.list()
    images = tcs.image.images.list()
    local_images = [image for image in images if image.owner == tenant.id]

    return make_json_response({
        u'project':
        link_for_tenant(tenant),
        u'instances':
        len(servers),
        u'members':
        len(users),
        u'local-images':
        len(local_images),
        u'total-images':
        len(images),
        'href':
        url_for('stats.get_project_stats', project_id=tenant.id)
    })