auto-gen the REST api url list
diff --git a/planetstack/apigen/api.template.py b/planetstack/apigen/api.template.py
index e3f1b64..89a2b18 100644
--- a/planetstack/apigen/api.template.py
+++ b/planetstack/apigen/api.template.py
@@ -7,6 +7,7 @@
from core.models import *
from django.forms import widgets
from rest_framework import filters
+from django.conf.urls import patterns, url
"""
Schema of the generator object:
@@ -22,7 +23,14 @@
TODO: Deal with subnets
"""
-# Based on api_root.py
+def get_REST_patterns():
+ return patterns('',
+ url(r'^plstackapi/$', api_root),
+ {% for object in generator.all %}
+ url(r'plstackapi/{{ object.rest_name }}/$', {{ object.camel }}List.as_view(), name='{{ object.singular }}-list'),
+ url(r'plstackapi/{{ object.rest_name }}/(?P<pk>[a-zA-Z0-9\-]+)/$', {{ object.camel }}Detail.as_view(), name ='{{ object.singular }}-detail'),
+ {% endfor %}
+ )
@api_view(['GET'])
def api_root(request, format=None):
diff --git a/planetstack/apigen/modelgen b/planetstack/apigen/modelgen
old mode 100755
new mode 100644
index b403c0b..8d25615
--- a/planetstack/apigen/modelgen
+++ b/planetstack/apigen/modelgen
@@ -55,6 +55,24 @@
else:
return name+'s'
+ def singular(self):
+ return str(self)
+
+ def rest_name(self):
+ # These are things that either for historic reasons or due to incorrect naming,
+ # got called something different than the autogen thinks they should be
+ # called.
+ REST_FIXUP = {'networkdeploymentses': 'networkdeployments',
+ 'imagedeploymentses': 'imagedeployments',
+ 'slicedeploymentses': 'slice_deployments',
+ 'userdeploymentses': 'user_deployments',
+ 'sitedeploymentses': 'sitedeployments',
+ 'siteroles': 'site_roles',
+ 'sliceprivileges': 'slice_privileges',
+ 'sliceroles': 'slice_roles',
+ }
+ return REST_FIXUP.get(self.plural(), self.plural())
+
def camel(self):
name = str(self.model.__name__)
return name
diff --git a/planetstack/planetstack/urls.py b/planetstack/planetstack/urls.py
index ec02c71..b95e8cd 100644
--- a/planetstack/planetstack/urls.py
+++ b/planetstack/planetstack/urls.py
@@ -37,107 +37,6 @@
# url(r'^admin/xoslib/(?P<name>\w+)/$', XOSLibDataView.as_view(), name="xoslib"),
- url(r'^plstackapi/$', api_root),
-
- url(r'^plstackapi/dashboardviews/$', DashboardViewList.as_view(), name='dashboardview-list'),
- url(r'^plstackapi/dashboardview/(?P<pk>[a-zA-Z0-9\-]+)/$', DashboardViewDetail.as_view(), name='dashboardview-detail'),
-
- url(r'^plstackapi/payments/$', PaymentList.as_view(), name='payment-list'),
- url(r'^plstackapi/payments/(?P<pk>[a-zA-Z0-9\-]+)/$', PaymentDetail.as_view(), name='payment-detail'),
-
- url(r'^plstackapi/charges/$', ChargeList.as_view(), name='charge-list'),
- url(r'^plstackapi/charges/(?P<pk>[a-zA-Z0-9\-]+)/$', ChargeDetail.as_view(), name='charge-detail'),
-
- url(r'^plstackapi/accounts/$', AccountList.as_view(), name='account-list'),
- url(r'^plstackapi/accounts/(?P<pk>[a-zA-Z0-9\-]+)/$', AccountDetail.as_view(), name='account-detail'),
-
- url(r'^plstackapi/flavors/$', FlavorList.as_view(), name='flavor-list'),
- url(r'^plstackapi/flavors/(?P<pk>[a-zA-Z0-9\-]+)/$', FlavorDetail.as_view(), name='flavor-detail'),
-
- url(r'^plstackapi/deployments/$', DeploymentList.as_view(), name='deployment-list'),
- url(r'^plstackapi/deployments/(?P<pk>[a-zA-Z0-9\-]+)/$', DeploymentDetail.as_view(), name='deployment-detail'),
-
- url(r'^plstackapi/images/$', ImageList.as_view(), name='image-list'),
- url(r'^plstackapi/images/(?P<pk>[a-zA-Z0-9_\-]+)/$', ImageDetail.as_view(), name='image-detail'),
-
- url(r'^plstackapi/networkparametertypes/$', NodeList.as_view(), name='node-list'),
- url(r'^plstackapi/networkparametertypes/(?P<pk>[a-zA-Z0-9_\-]+)/$', NodeDetail.as_view(), name='node-detail'),
-
- url(r'^plstackapi/nodes/$', NodeList.as_view(), name='node-list'),
- url(r'^plstackapi/nodes/(?P<pk>[a-zA-Z0-9_\-]+)/$', NodeDetail.as_view(), name='node-detail'),
-
- url(r'^plstackapi/projects/$', ProjectList.as_view(), name='project-list'),
- url(r'^plstackapi/projects/(?P<pk>[a-zA-Z0-9_\-]+)/$', ProjectDetail.as_view(), name='project-detail'),
-
- url(r'^plstackapi/reservations/$', ReservationList.as_view(), name='reservation-list'),
- url(r'^plstackapi/reservations/(?P<pk>[a-zA-Z0-9_\-]+)/$', ReservationDetail.as_view(), name='reservation-detail'),
-
- url(r'^plstackapi/roles/$', RoleList.as_view(), name='role-list'),
- url(r'^plstackapi/roles/(?P<pk>[a-zA-Z0-9]+)/$', RoleDetail.as_view(), name='role-detail'),
-
- url(r'^plstackapi/serviceclasses/$', ServiceClassList.as_view(), name='serviceclass-list'),
- url(r'^plstackapi/serviceclasses/(?P<pk>[a-zA-Z0-9]+)/$', ServiceClassDetail.as_view(), name='serviceclass-detail'),
-
- url(r'^plstackapi/serviceresources/$', ServiceResourceList.as_view(), name='serviceresource-list'),
- url(r'^plstackapi/serviceresources/(?P<pk>[a-zA-Z0-9]+)/$', ServiceResourceDetail.as_view(), name='serviceresource-detail'),
-
- url(r'^plstackapi/site_privileges/$', SitePrivilegeList.as_view(), name='siteprivilege-list'),
- url(r'^plstackapi/site_privileges/(?P<pk>[a-zA-Z0-9_]+)/$', SitePrivilegeDetail.as_view(), name='siteprivilege-detail'),
-
- url(r'^plstackapi/site_roles/$', SiteRoleList.as_view(), name='siterole-list'),
- url(r'^plstackapi/site_roles/(?P<pk>[a-zA-Z0-9_\-]+)/$', SiteRoleDetail.as_view(), name='siterole-detail'),
-
- url(r'^plstackapi/sites/$', SiteList.as_view(), name='site-list'),
- url(r'^plstackapi/sites/(?P<pk>[a-zA-Z0-9_\-]+)/$', SiteDetail.as_view(), name='site-detail'),
-
- url(r'^plstackapi/accounts/$', AccountList.as_view(), name='account-list'),
- url(r'^plstackapi/accounts/(?P<pk>[a-zA-Z0-9_\-]+)/$', AccountDetail.as_view(), name='account-detail'),
-
- url(r'^plstackapi/networktemplates/$', NetworkTemplateList.as_view(), name='networktemplate-list'),
- url(r'^plstackapi/networktemplates/(?P<pk>[a-zA-Z0-9_\-]+)/$', NetworkTemplateDetail.as_view(), name='networktemplate-detail'),
-
- url(r'^plstackapi/networkslices/$', NetworkSliceList.as_view(), name='networkslice-list'),
- url(r'^plstackapi/networkslices/(?P<pk>[a-zA-Z0-9_\-]+)/$', NetworkSliceDetail.as_view(), name='networkslice-detail'),
-
- url(r'^plstackapi/networkslivers/$', NetworkSliverList.as_view(), name='networksliver-list'),
- url(r'^plstackapi/networkslivers/(?P<pk>[a-zA-Z0-9_\-]+)/$', NetworkSliverDetail.as_view(), name='networksliver-detail'),
-
- url(r'^plstackapi/networkdeployments/$', NetworkDeploymentsList.as_view(), name='networkdeployment-list'),
- url(r'^plstackapi/networkdeployments/(?P<pk>[a-zA-Z0-9_\-]+)/$', NetworkDeploymentsDetail.as_view(), name='networkdeployment-detail'),
-
- url(r'^plstackapi/networks/$', NetworkList.as_view(), name='network-list'),
- url(r'^plstackapi/networks/(?P<pk>[a-zA-Z0-9_\-]+)/$', NetworkDetail.as_view(), name='network-detail'),
-
- url(r'^plstackapi/services/$', ServiceList.as_view(), name='service-list'),
- url(r'^plstackapi/services/(?P<pk>[a-zA-Z0-9_\-]+)/$', ServiceDetail.as_view(), name='service-detail'),
-
- url(r'^plstackapi/slices/$', SliceList.as_view(), name='slice-list'),
- url(r'^plstackapi/slices/(?P<pk>[a-zA-Z0-9_\-]+)/$', SliceDetail.as_view(), name='slice-detail'),
-
- url(r'^plstackapi/slice_roles/$', SliceRoleList.as_view(), name='slicerole-list'),
- url(r'^plstackapi/slice_roles/(?P<pk>[a-zA-Z0-9_\-]+)/$', SliceRoleDetail.as_view(), name='slicerole-detail'),
-
- url(r'^plstackapi/slice_memberships/$', SlicePrivilegeList.as_view(), name='sliceprivilege-list'),
- url(r'^plstackapi/slice_memberships/(?P<pk>[0-9]+)/$', SlicePrivilegeDetail.as_view(), name='sliceprivilege-detail'),
-
- url(r'^plstackapi/slice_deployments/$', SliceDeploymentsList.as_view(), name='slicedeployments-list'),
- url(r'^plstackapi/slice_deployments/(?P<pk>[0-9]+)/$', SliceDeploymentsDetail.as_view(), name='slicedeployments-detail'),
-
- url(r'^plstackapi/slice_privileges/$', SlicePrivilegeList.as_view(), name='sliceprivilege-list'),
- url(r'^plstackapi/slice_privileges/(?P<pk>[0-9]+)/$', SlicePrivilegeDetail.as_view(), name='sliceprivilege-detail'),
-
- url(r'^plstackapi/slivers/$', SliverList.as_view(), name='sliver-list'),
- url(r'^plstackapi/slivers/(?P<pk>[a-zA-Z0-9_\-]+)/$', SliverDetail.as_view(), name='sliver-detail'),
-
- url(r'^plstackapi/tags/$', TagList.as_view(), name='tag-list'),
- url(r'^plstackapi/tags/(?P<pk>[a-zA-Z0-9_\-]+)/$', TagDetail.as_view(), name='tag-detail'),
-
- url(r'^plstackapi/users/$', UserList.as_view(), name='user-list'),
- url(r'^plstackapi/users/(?P<pk>[a-zA-Z0-9_\-]+)/$', UserDetail.as_view(), name='user-detail'),
-
- url(r'^plstackapi/user_deployments/$', UserDeploymentsList.as_view(), name='userdeployments-list'),
- url(r'^plstackapi/user_deployments/(?P<pk>[a-zA-Z0-9_\-]+)/$', UserDeploymentsDetail.as_view(), name='userdeployments-detail'),
-
url(r'^xmlrpc/legacyapi/$', 'core.views.legacyapi.LegacyXMLRPC', name='xmlrpc'),
# url(r'^analytics/(?P<name>\w+)/$', AnalyticsAjaxView.as_view(), name="analytics"),
@@ -148,5 +47,6 @@
url(r'^plstackapi/', include('rest_framework.urls', namespace='rest_framework')),
# XOSLib rest methods
- url(r'^xoslib/', include('core.xoslib.methods', namespace='xoslib')),
-)
+ url(r'^xoslib/', include('core.xoslib.methods', namespace='xoslib')),
+ ) + get_REST_patterns()
+