launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06862
[Merge] lp:~julian-edwards/maas/list_allocated_filter into lp:maas
Julian Edwards has proposed merging lp:~julian-edwards/maas/list_allocated_filter into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #962224 in MAAS: "list_allocated should support the id= parameter"
https://bugs.launchpad.net/maas/+bug/962224
For more details, see:
https://code.launchpad.net/~julian-edwards/maas/list_allocated_filter/+merge/98966
--
https://code.launchpad.net/~julian-edwards/maas/list_allocated_filter/+merge/98966
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/maas/list_allocated_filter into lp:maas.
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py 2012-03-22 15:30:45 +0000
+++ src/maasserver/api.py 2012-03-23 04:19:18 +0000
@@ -414,7 +414,10 @@
assert key is not None, (
"Invalid Authorization header on request.")
token = Token.objects.get(key=key)
- nodes = Node.objects.get_allocated_visible_nodes(token)
+ match_ids = request.GET.getlist('id')
+ if match_ids == []:
+ match_ids = None
+ nodes = Node.objects.get_allocated_visible_nodes(token, match_ids)
return nodes.order_by('id')
@api_exported('acquire', 'POST')
=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py 2012-03-22 15:10:57 +0000
+++ src/maasserver/models.py 2012-03-23 04:19:18 +0000
@@ -230,19 +230,24 @@
models.Q(owner__isnull=True) | models.Q(owner=user))
return self.filter_by_ids(visible_nodes, ids)
- def get_allocated_visible_nodes(self, token):
+ def get_allocated_visible_nodes(self, token, ids):
"""Fetch Nodes that were allocated to the User_/oauth token.
:param user: The user whose nodes to fetch
:type user: User_
:param token: The OAuth token associated with the Nodes.
:type token: piston.models.Token.
+ :param ids: Optional set of IDs to filter by. If given, nodes whose
+ system_ids are not in `ids` will be ignored.
+ :type param_ids: Sequence
.. _User: https://
docs.djangoproject.com/en/dev/topics/auth/
#django.contrib.auth.models.User
"""
nodes = self.filter(token=token)
+ if ids is not None:
+ nodes = self.filter(system_id__in=ids)
return nodes
def get_editable_nodes(self, user, ids=None):
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-03-22 19:03:24 +0000
+++ src/maasserver/tests/test_api.py 2012-03-23 04:19:18 +0000
@@ -726,6 +726,26 @@
self.assertItemsEqual(
[node_1.system_id], extract_system_ids(parsed_result))
+ def test_GET_list_allocated_filters_by_id(self):
+ # list_allocated takes an optional list of 'id' parameters to
+ # filter returned results.
+ current_token = get_auth_tokens(self.logged_in_user)[0]
+ nodes = []
+ for i in range(3):
+ nodes.append(factory.make_node(
+ status=NODE_STATUS.ALLOCATED,
+ owner=self.logged_in_user, token=current_token))
+
+ required_node_ids = [nodes[0].system_id, nodes[1].system_id]
+ response = self.client.get(self.get_uri('nodes/'), {
+ 'op': 'list_allocated',
+ 'id': required_node_ids,
+ })
+ self.assertEqual(httplib.OK, response.status_code)
+ parsed_result = json.loads(response.content)
+ self.assertItemsEqual(
+ required_node_ids, extract_system_ids(parsed_result))
+
def test_POST_acquire_returns_available_node(self):
# The "acquire" operation returns an available node.
available_status = NODE_STATUS.READY
Follow ups