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

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1415
Proposed branch: lp:~rvb/maas/expose-maas
Merge into: lp:~maas-committers/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) Approve
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.
Revision history for this message
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py 2012-12-20 11:09:21 +0000
+++ src/maasserver/api.py 2012-12-20 15:09:38 +0000
@@ -60,9 +60,12 @@
60 "api_doc",60 "api_doc",
61 "api_doc_title",61 "api_doc_title",
62 "BootImagesHandler",62 "BootImagesHandler",
63 "CommissioningScriptHandler",
64 "CommissioningScriptsHandler",
63 "CommissioningResultsHandler",65 "CommissioningResultsHandler",
64 "FilesHandler",66 "FilesHandler",
65 "get_oauth_token",67 "get_oauth_token",
68 "MaasHandler",
66 "NodeGroupsHandler",69 "NodeGroupsHandler",
67 "NodeGroupInterfaceHandler",70 "NodeGroupInterfaceHandler",
68 "NodeGroupInterfacesHandler",71 "NodeGroupInterfacesHandler",
@@ -1467,8 +1470,8 @@
1467 return ('tags_handler', [])1470 return ('tags_handler', [])
14681471
14691472
1470class MAASHandler(OperationsHandler):1473class MaasHandler(OperationsHandler):
1471 """Manage the MAAS' itself."""1474 """Manage the MAAS server."""
1472 create = read = update = delete = None1475 create = read = update = delete = None
14731476
1474 @operation(idempotent=False)1477 @operation(idempotent=False)
@@ -1497,6 +1500,10 @@
1497 value = Config.objects.get_config(name)1500 value = Config.objects.get_config(name)
1498 return HttpResponse(json.dumps(value), content_type='application/json')1501 return HttpResponse(json.dumps(value), content_type='application/json')
14991502
1503 @classmethod
1504 def resource_uri(cls, *args, **kwargs):
1505 return ('maas_handler', [])
1506
15001507
1501# Title section for the API documentation. Matches in style, format,1508# Title section for the API documentation. Matches in style, format,
1502# etc. whatever render_api_docs() produces, so that you can concatenate1509# etc. whatever render_api_docs() produces, so that you can concatenate
@@ -1780,7 +1787,7 @@
17801787
17811788
1782class CommissioningScriptsHandler(OperationsHandler):1789class CommissioningScriptsHandler(OperationsHandler):
1783 """Management of custom commissioning scripts.1790 """Manage custom commissioning scripts.
17841791
1785 This functionality is only available to administrators.1792 This functionality is only available to administrators.
1786 """1793 """
@@ -1829,9 +1836,13 @@
1829 content = Bin(get_content_parameter(request))1836 content = Bin(get_content_parameter(request))
1830 return CommissioningScript.objects.create(name=name, content=content)1837 return CommissioningScript.objects.create(name=name, content=content)
18311838
1839 @classmethod
1840 def resource_uri(cls):
1841 return ('commissioning_scripts_handler', [])
1842
18321843
1833class CommissioningScriptHandler(OperationsHandler):1844class CommissioningScriptHandler(OperationsHandler):
1834 """A CommissioningScript.1845 """Manage a custom commissioning script.
18351846
1836 This functionality is only available to administrators.1847 This functionality is only available to administrators.
1837 """1848 """
@@ -1847,6 +1858,12 @@
1847 script = get_object_or_404(CommissioningScript, name=name)1858 script = get_object_or_404(CommissioningScript, name=name)
1848 return HttpResponse(script.content, content_type='application/binary')1859 return HttpResponse(script.content, content_type='application/binary')
18491860
1861 def delete(self, request, name):
1862 """Delete a commissioning script."""
1863 script = get_object_or_404(CommissioningScript, name=name)
1864 script.delete()
1865 return rc.DELETED
1866
1850 def update(self, request, name):1867 def update(self, request, name):
1851 """Update a commissioning script."""1868 """Update a commissioning script."""
1852 content = Bin(get_content_parameter(request))1869 content = Bin(get_content_parameter(request))
@@ -1854,6 +1871,14 @@
1854 script.content = content1871 script.content = content
1855 script.save()1872 script.save()
18561873
1874 @classmethod
1875 def resource_uri(cls, script=None):
1876 # See the comment in NodeHandler.resource_uri
1877 script_name = 'name'
1878 if script is not None:
1879 script_name = script.name
1880 return ('commissioning_script_handler', (script_name, ))
1881
18571882
1858class CommissioningResultsHandler(OperationsHandler):1883class CommissioningResultsHandler(OperationsHandler):
1859 """Read the collection of NodeCommissionResult in the MAAS."""1884 """Read the collection of NodeCommissionResult in the MAAS."""
@@ -1884,6 +1909,10 @@
1884 results = results.filter(name__in=names)1909 results = results.filter(name__in=names)
1885 return results1910 return results
18861911
1912 @classmethod
1913 def resource_uri(cls, result=None):
1914 return ('commissioning_results_handler', [])
1915
18871916
1888def describe(request):1917def describe(request):
1889 """Return a description of the whole MAAS API.1918 """Return a description of the whole MAAS API.
18901919
=== modified file 'src/maasserver/urls_api.py'
--- src/maasserver/urls_api.py 2012-12-19 17:24:01 +0000
+++ src/maasserver/urls_api.py 2012-12-20 15:09:38 +0000
@@ -25,7 +25,7 @@
25 CommissioningScriptsHandler,25 CommissioningScriptsHandler,
26 describe,26 describe,
27 FilesHandler,27 FilesHandler,
28 MAASHandler,28 MaasHandler,
29 NodeGroupHandler,29 NodeGroupHandler,
30 NodeGroupInterfaceHandler,30 NodeGroupInterfaceHandler,
31 NodeGroupInterfacesHandler,31 NodeGroupInterfacesHandler,
@@ -65,7 +65,7 @@
6565
6666
67# Admin handlers.67# Admin handlers.
68maas_handler = AdminRestrictedResource(MAASHandler, authentication=api_auth)68maas_handler = AdminRestrictedResource(MaasHandler, authentication=api_auth)
69nodegroupinterface_handler = AdminRestrictedResource(69nodegroupinterface_handler = AdminRestrictedResource(
70 NodeGroupInterfaceHandler, authentication=api_auth)70 NodeGroupInterfaceHandler, authentication=api_auth)
71nodegroupinterfaces_handler = AdminRestrictedResource(71nodegroupinterfaces_handler = AdminRestrictedResource(