Exemple #1
0
def list_stats_by_project():
    parse_collection_request(_SCHEMA)
    cs = auth.admin_client_set()

    if g.my_projects:
        tenants = g.client_set.identity_public.tenants.list()
    else:
        tenants = cs.identity_admin.tenants.list()

    result = {}
    for tenant in tenants:
        if tenant.id != auth.default_tenant_id():
            users = cs.identity_admin.tenants.list_users(tenant.id)
            result[tenant.id] = {
                'project': link_for_tenant(tenant),
                'members': len(users),
                'instances': 0,
                'local-images': 0,
                'total-images': 0,
                'href': url_for('stats.get_project_stats',
                                project_id=tenant.id)
            }

    for server in cs.compute.servers.list(search_opts={'all_tenants': 1}):
        try:
            result[server.tenant_id]['instances'] += 1
        except KeyError:
            pass

    global_images = 0
    for image in list_all_images(cs.image.images):
        if image.is_public:
            global_images += 1
        if image.owner in result:
            result[image.owner]['local-images'] += 1
            if not image.is_public:
                result[image.owner]['total-images'] += 1

    for value in result.itervalues():
        value['total-images'] += global_images
    data = sorted(result.itervalues(), key=lambda s: s['href'])
    return make_collection_response(u'stats',
                                    data,
                                    parent_href=url_for('stats.altai_stats'))
Exemple #2
0
def list_stats_by_project():
    parse_collection_request(_SCHEMA)
    cs = auth.admin_client_set()

    if g.my_projects:
        tenants = g.client_set.identity_public.tenants.list()
    else:
        tenants = cs.identity_admin.tenants.list()

    result = {}
    for tenant in tenants:
        if tenant.id != auth.default_tenant_id():
            users = cs.identity_admin.tenants.list_users(tenant.id)
            result[tenant.id] = {
                'project': link_for_tenant(tenant),
                'members': len(users),
                'instances': 0,
                'local-images': 0,
                'total-images': 0,
                'href': url_for('stats.get_project_stats',
                                project_id=tenant.id)
            }

    for server in cs.compute.servers.list(search_opts={'all_tenants': 1}):
        try:
            result[server.tenant_id]['instances'] += 1
        except KeyError:
            pass

    global_images = 0
    for image in list_all_images(cs.image.images):
        if image.is_public:
            global_images += 1
        if image.owner in result:
            result[image.owner]['local-images'] += 1
            if not image.is_public:
                result[image.owner]['total-images'] += 1

    for value in result.itervalues():
        value['total-images'] += global_images
    data = sorted(result.itervalues(), key=lambda s: s['href'])
    return make_collection_response(u'stats', data,
                                    parent_href=url_for('stats.altai_stats'))
Exemple #3
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)
    })
Exemple #4
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)
    })