Add support for GET /v1/nodes to return a list.
Adds the db/api and db/sqlalchemy/api methods, and the 'get' method in the API service. Partially implements bp:node-api-actions Change-Id: I214687c19150e65183f663d99f165d7fdea9915f
This commit is contained in:
parent
1f168e96bd
commit
4c160cd562
@ -90,6 +90,11 @@ class Node(APIBase):
|
||||
class NodesController(rest.RestController):
|
||||
"""REST controller for Nodes."""
|
||||
|
||||
@wsme_pecan.wsexpose([unicode])
|
||||
def get(self):
|
||||
"""Retrieve a list of nodes."""
|
||||
return pecan.request.dbapi.get_node_list()
|
||||
|
||||
@wsme_pecan.wsexpose(Node, unicode)
|
||||
def get_one(self, uuid):
|
||||
"""Retrieve information about the given node."""
|
||||
|
@ -47,6 +47,10 @@ class Connection(object):
|
||||
:param columns: List of columns to return.
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_node_list(self):
|
||||
"""Return a list of node UUIDs."""
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_associated_nodes(self):
|
||||
"""Return a list of ids of all associated nodes."""
|
||||
|
@ -89,6 +89,10 @@ class Connection(api.Connection):
|
||||
def get_nodes(self, columns):
|
||||
pass
|
||||
|
||||
def get_node_list(self):
|
||||
query = model_query(models.Node.uuid)
|
||||
return [i[0] for i in query.all()]
|
||||
|
||||
@objects.objectify(objects.Node)
|
||||
def get_associated_nodes(self):
|
||||
pass
|
||||
|
@ -67,6 +67,17 @@ class DbNodeTestCase(base.DbTestCase):
|
||||
self.assertRaises(exception.InvalidUUID,
|
||||
self.dbapi.get_node, 'not-a-uuid')
|
||||
|
||||
def test_get_node_list(self):
|
||||
uuids = []
|
||||
for i in xrange(1, 6):
|
||||
n = utils.get_test_node(id=i, uuid=uuidutils.generate_uuid())
|
||||
self.dbapi.create_node(n)
|
||||
uuids.append(unicode(n['uuid']))
|
||||
res = self.dbapi.get_node_list()
|
||||
uuids.sort()
|
||||
res.sort()
|
||||
self.assertEqual(uuids, res)
|
||||
|
||||
def test_get_node_by_instance(self):
|
||||
n = self._create_test_node()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user