Merge lp:~rvb/maas/expose-maas into lp:maas/trunk

Proposed by Raphaël Badin on 2012-12-20
Status: Merged
Approved by: Raphaël Badin on 2012-12-20
Approved revision: 1413
Merged at revision: 1415
Proposed branch: lp:~rvb/maas/expose-maas
Merge into: lp:maas/trunk
Diff against target: 123 lines (+35/-6)
2 files modified
src/maasserver/api.py (+33/-4)
src/maasserver/urls_api.py (+2/-2)
To merge this branch: bzr merge lp:~rvb/maas/expose-maas
Reviewer Review Type Date Requested Status
Gavin Panella (community) 2012-12-20 Approve on 2012-12-20
Review via email: mp+140916@code.launchpad.net

Commit message

Fix MAASHandler (add a resource_uri method) so that it is scanned by the CLI.

Description of the change

Drive-by fix: s/MAASHandler/MaasHandler/ so that it appears on the cli as 'maas'
Drive-by fix: add resource_uri methods for CommissioningResultsHandler, CommissioningScriptsHandler and CommissioningScriptHandler.
Drive-by fix: add a 'delete' method on CommissioningScriptHandler just to have it properly documented on the API (the test for the functionality is already there)

To post a comment you must log in.
lp:~rvb/maas/expose-maas updated on 2012-12-20
1413. By Raphaël Badin on 2012-12-20

Fix resource_uri.

Gavin Panella (allenap) :
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.py'
2--- src/maasserver/api.py 2012-12-20 11:09:21 +0000
3+++ src/maasserver/api.py 2012-12-20 15:09:38 +0000
4@@ -60,9 +60,12 @@
5 "api_doc",
6 "api_doc_title",
7 "BootImagesHandler",
8+ "CommissioningScriptHandler",
9+ "CommissioningScriptsHandler",
10 "CommissioningResultsHandler",
11 "FilesHandler",
12 "get_oauth_token",
13+ "MaasHandler",
14 "NodeGroupsHandler",
15 "NodeGroupInterfaceHandler",
16 "NodeGroupInterfacesHandler",
17@@ -1467,8 +1470,8 @@
18 return ('tags_handler', [])
19
20
21-class MAASHandler(OperationsHandler):
22- """Manage the MAAS' itself."""
23+class MaasHandler(OperationsHandler):
24+ """Manage the MAAS server."""
25 create = read = update = delete = None
26
27 @operation(idempotent=False)
28@@ -1497,6 +1500,10 @@
29 value = Config.objects.get_config(name)
30 return HttpResponse(json.dumps(value), content_type='application/json')
31
32+ @classmethod
33+ def resource_uri(cls, *args, **kwargs):
34+ return ('maas_handler', [])
35+
36
37 # Title section for the API documentation. Matches in style, format,
38 # etc. whatever render_api_docs() produces, so that you can concatenate
39@@ -1780,7 +1787,7 @@
40
41
42 class CommissioningScriptsHandler(OperationsHandler):
43- """Management of custom commissioning scripts.
44+ """Manage custom commissioning scripts.
45
46 This functionality is only available to administrators.
47 """
48@@ -1829,9 +1836,13 @@
49 content = Bin(get_content_parameter(request))
50 return CommissioningScript.objects.create(name=name, content=content)
51
52+ @classmethod
53+ def resource_uri(cls):
54+ return ('commissioning_scripts_handler', [])
55+
56
57 class CommissioningScriptHandler(OperationsHandler):
58- """A CommissioningScript.
59+ """Manage a custom commissioning script.
60
61 This functionality is only available to administrators.
62 """
63@@ -1847,6 +1858,12 @@
64 script = get_object_or_404(CommissioningScript, name=name)
65 return HttpResponse(script.content, content_type='application/binary')
66
67+ def delete(self, request, name):
68+ """Delete a commissioning script."""
69+ script = get_object_or_404(CommissioningScript, name=name)
70+ script.delete()
71+ return rc.DELETED
72+
73 def update(self, request, name):
74 """Update a commissioning script."""
75 content = Bin(get_content_parameter(request))
76@@ -1854,6 +1871,14 @@
77 script.content = content
78 script.save()
79
80+ @classmethod
81+ def resource_uri(cls, script=None):
82+ # See the comment in NodeHandler.resource_uri
83+ script_name = 'name'
84+ if script is not None:
85+ script_name = script.name
86+ return ('commissioning_script_handler', (script_name, ))
87+
88
89 class CommissioningResultsHandler(OperationsHandler):
90 """Read the collection of NodeCommissionResult in the MAAS."""
91@@ -1884,6 +1909,10 @@
92 results = results.filter(name__in=names)
93 return results
94
95+ @classmethod
96+ def resource_uri(cls, result=None):
97+ return ('commissioning_results_handler', [])
98+
99
100 def describe(request):
101 """Return a description of the whole MAAS API.
102
103=== modified file 'src/maasserver/urls_api.py'
104--- src/maasserver/urls_api.py 2012-12-19 17:24:01 +0000
105+++ src/maasserver/urls_api.py 2012-12-20 15:09:38 +0000
106@@ -25,7 +25,7 @@
107 CommissioningScriptsHandler,
108 describe,
109 FilesHandler,
110- MAASHandler,
111+ MaasHandler,
112 NodeGroupHandler,
113 NodeGroupInterfaceHandler,
114 NodeGroupInterfacesHandler,
115@@ -65,7 +65,7 @@
116
117
118 # Admin handlers.
119-maas_handler = AdminRestrictedResource(MAASHandler, authentication=api_auth)
120+maas_handler = AdminRestrictedResource(MaasHandler, authentication=api_auth)
121 nodegroupinterface_handler = AdminRestrictedResource(
122 NodeGroupInterfaceHandler, authentication=api_auth)
123 nodegroupinterfaces_handler = AdminRestrictedResource(