Merge lp:~blake-rouse/maas/fix-1657471 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 5966
Proposed branch: lp:~blake-rouse/maas/fix-1657471
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 66 lines (+25/-6)
2 files modified
src/maasserver/api/nodes.py (+24/-5)
src/maasserver/api/tests/test_nodes.py (+1/-1)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1657471
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
Review via email: mp+322477@code.launchpad.net

Commit message

Add is_registered as an authenticated operation as well.

To post a comment you must log in.
Revision history for this message
Newell Jensen (newell-jensen) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/nodes.py'
2--- src/maasserver/api/nodes.py 2017-04-12 16:25:49 +0000
3+++ src/maasserver/api/nodes.py 2017-04-12 19:02:03 +0000
4@@ -137,6 +137,15 @@
5 return nodes.order_by('id')
6
7
8+def is_registered(request):
9+ """Used by both `NodesHandler` and `AnonNodesHandler`."""
10+ mac_address = get_mandatory_param(request.GET, 'mac_address')
11+ interfaces = Interface.objects.filter(mac_address=mac_address)
12+ interfaces = interfaces.exclude(node__isnull=True)
13+ interfaces = interfaces.exclude(node__status=NODE_STATUS.RETIRED)
14+ return interfaces.exists()
15+
16+
17 class NodeHandler(OperationsHandler):
18 """Manage an individual Node.
19
20@@ -283,11 +292,7 @@
21
22 Returns 400 if any mandatory parameters are missing.
23 """
24- mac_address = get_mandatory_param(request.GET, 'mac_address')
25- interfaces = Interface.objects.filter(mac_address=mac_address)
26- interfaces = interfaces.exclude(node__isnull=True)
27- interfaces = interfaces.exclude(node__status=NODE_STATUS.RETIRED)
28- return interfaces.exists()
29+ return is_registered(request)
30
31 @classmethod
32 def resource_uri(cls, *args, **kwargs):
33@@ -360,6 +365,20 @@
34 nodes = nodes.prefetch_related('zone')
35 return nodes.order_by('id')
36
37+ @operation(idempotent=True)
38+ def is_registered(self, request):
39+ """Returns whether or not the given MAC address is registered within
40+ this MAAS (and attached to a non-retired node).
41+
42+ :param mac_address: The mac address to be checked.
43+ :type mac_address: unicode
44+ :return: 'true' or 'false'.
45+ :rtype: unicode
46+
47+ Returns 400 if any mandatory parameters are missing.
48+ """
49+ return is_registered(request)
50+
51 @admin_method
52 @operation(idempotent=False)
53 def set_zone(self, request):
54
55=== modified file 'src/maasserver/api/tests/test_nodes.py'
56--- src/maasserver/api/tests/test_nodes.py 2017-04-12 16:25:49 +0000
57+++ src/maasserver/api/tests/test_nodes.py 2017-04-12 19:02:03 +0000
58@@ -28,7 +28,7 @@
59 from maastesting.djangotestcase import count_queries
60
61
62-class AnonymousIsRegisteredAPITest(APITestCase.ForAnonymous):
63+class TestIsRegisteredAPI(APITestCase.ForAnonymousAndUserAndAdmin):
64
65 def test_is_registered_returns_True_if_node_registered(self):
66 mac_address = factory.make_mac_address()