Ejemplo n.º 1
0
 def test_limit(self):
     expected = {
         u"collection": {u"name": u"test", u"parent-href": u"/v1/test", u"size": 7},
         u"test": [{"test": 1}, {"test": 2}],
     }
     flask.g.limit = 2
     rv = make_collection_response(u"test", self.result, parent_href="/v1/test")
     data = self.check_and_parse_response(rv)
     self.assertEquals(data, expected)
Ejemplo n.º 2
0
 def test_filtered(self):
     expected = {
         u"collection": {u"name": u"test", u"parent-href": u"/v1/test", u"size": 3},
         u"test": [{"test": 5}, {"test": 6}, {"test": 7}],
     }
     flask.g.filters = {"test": {"ge": 5}}
     rv = make_collection_response(u"test", self.result, parent_href="/v1/test")
     data = self.check_and_parse_response(rv)
     self.assertEquals(data, expected)
Ejemplo n.º 3
0
 def test_it_works(self):
     expected = {
         u'collection': {
             u'name': u'test',
             u'parent-href': u'/v1/test',
             u'size': 7
         },
         u'test': self.result
     }
     rv = make_collection_response(u'test',
                                   self.result,
                                   parent_href='/v1/test')
     data = self.check_and_parse_response(rv)
     self.assertEquals(data, expected)
Ejemplo n.º 4
0
def list_nodes():
    parse_collection_request(_SCHEMA)
    host_mgr = g.client_set.compute.hosts

    names = [h._info['host_name']
             for h in host_mgr.list_all()
             if h._info['service'] == 'compute']

    result = []
    for name in names:
        try:
            result.append(_node_to_view(name, host_mgr.get(name)))
        except osc_exc.NotFound:
            pass
    return make_collection_response('nodes', result)
Ejemplo n.º 5
0
def list_nodes():
    parse_collection_request(_SCHEMA)
    host_mgr = g.client_set.compute.hosts

    names = [
        h._info['host_name'] for h in host_mgr.list_all()
        if h._info['service'] == 'compute'
    ]

    result = []
    for name in names:
        try:
            result.append(_node_to_view(name, host_mgr.get(name)))
        except osc_exc.NotFound:
            pass
    return make_collection_response('nodes', result)
Ejemplo n.º 6
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'))
Ejemplo n.º 7
0
 def test_limit(self):
     expected = {
         u'collection': {
             u'name': u'test',
             u'parent-href': u'/v1/test',
             u'size': 7
         },
         u'test': [{
             'test': 1
         }, {
             'test': 2
         }]
     }
     flask.g.limit = 2
     rv = make_collection_response(u'test',
                                   self.result,
                                   parent_href='/v1/test')
     data = self.check_and_parse_response(rv)
     self.assertEquals(data, expected)
Ejemplo n.º 8
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'))
Ejemplo n.º 9
0
 def test_filtered(self):
     expected = {
         u'collection': {
             u'name': u'test',
             u'parent-href': u'/v1/test',
             u'size': 3
         },
         u'test': [{
             'test': 5
         }, {
             'test': 6
         }, {
             'test': 7
         }]
     }
     flask.g.filters = {'test': {'ge': 5}}
     rv = make_collection_response(u'test',
                                   self.result,
                                   parent_href='/v1/test')
     data = self.check_and_parse_response(rv)
     self.assertEquals(data, expected)
Ejemplo n.º 10
0
def list_all_records():
    parse_collection_request(_SCHEMA)
    result = [record_to_view(record)
              for record in AuditDAO.list_all()]
    return make_collection_response(u'audit-log', result)
Ejemplo n.º 11
0
 def test_it_works(self):
     expected = {u"collection": {u"name": u"test", u"parent-href": u"/v1/test", u"size": 7}, u"test": self.result}
     rv = make_collection_response(u"test", self.result, parent_href="/v1/test")
     data = self.check_and_parse_response(rv)
     self.assertEquals(data, expected)