blob: 6fdc919849b1b468316ef70435dc818aa1778fd8 [file] [log] [blame]
Sapan Bhatiadea39432014-06-13 03:10:36 -04001from rest_framework.decorators import api_view
2from rest_framework.response import Response
3from rest_framework.reverse import reverse
4from rest_framework import serializers
Scott Baker0caeaf02014-06-19 11:12:55 -07005from rest_framework import generics
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07006from rest_framework import status
Scott Bakerf3816ac2014-11-12 01:13:53 -08007from rest_framework.generics import GenericAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04008from core.models import *
9from django.forms import widgets
Scott Baker46b58542014-08-11 17:26:12 -070010from rest_framework import filters
Scott Baker55a2e292014-11-10 16:31:15 -080011from django.conf.urls import patterns, url
Sapan Bhatiadea39432014-06-13 03:10:36 -040012
13"""
Scott Baker08898c12014-10-29 23:41:11 -070014 Schema of the generator object:
15 all: Set of all Model objects
16 all_if(regex): Set of Model objects that match regex
Scott Bakerf3816ac2014-11-12 01:13:53 -080017
Scott Baker08898c12014-10-29 23:41:11 -070018 Model object:
19 plural: English plural of object name
20 camel: CamelCase version of object name
21 refs: list of references to other Model objects
22 props: list of properties minus refs
Sapan Bhatiadea39432014-06-13 03:10:36 -040023
Scott Baker08898c12014-10-29 23:41:11 -070024 TODO: Deal with subnets
Sapan Bhatiadea39432014-06-13 03:10:36 -040025"""
26
Scott Baker55a2e292014-11-10 16:31:15 -080027def get_REST_patterns():
28 return patterns('',
29 url(r'^plstackapi/$', api_root),
30
31 url(r'plstackapi/serviceattributes/$', ServiceAttributeList.as_view(), name='serviceattribute-list'),
32 url(r'plstackapi/serviceattributes/(?P<pk>[a-zA-Z0-9\-]+)/$', ServiceAttributeDetail.as_view(), name ='serviceattribute-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080033# url(r'plstackapi/serviceattributes/!new/$', ServiceAttributeNew.as_view(), name ='serviceattribute-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080034
35 url(r'plstackapi/images/$', ImageList.as_view(), name='image-list'),
36 url(r'plstackapi/images/(?P<pk>[a-zA-Z0-9\-]+)/$', ImageDetail.as_view(), name ='image-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080037# url(r'plstackapi/images/!new/$', ImageNew.as_view(), name ='image-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080038
39 url(r'plstackapi/networkparameters/$', NetworkParameterList.as_view(), name='networkparameter-list'),
40 url(r'plstackapi/networkparameters/(?P<pk>[a-zA-Z0-9\-]+)/$', NetworkParameterDetail.as_view(), name ='networkparameter-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080041# url(r'plstackapi/networkparameters/!new/$', NetworkParameterNew.as_view(), name ='networkparameter-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080042
43 url(r'plstackapi/sites/$', SiteList.as_view(), name='site-list'),
44 url(r'plstackapi/sites/(?P<pk>[a-zA-Z0-9\-]+)/$', SiteDetail.as_view(), name ='site-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080045# url(r'plstackapi/sites/!new/$', SiteNew.as_view(), name ='site-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080046
47 url(r'plstackapi/slice_roles/$', SliceRoleList.as_view(), name='slicerole-list'),
48 url(r'plstackapi/slice_roles/(?P<pk>[a-zA-Z0-9\-]+)/$', SliceRoleDetail.as_view(), name ='slicerole-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080049# url(r'plstackapi/slice_roles/!new/$', SliceRoleNew.as_view(), name ='slicerole-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080050
51 url(r'plstackapi/tags/$', TagList.as_view(), name='tag-list'),
52 url(r'plstackapi/tags/(?P<pk>[a-zA-Z0-9\-]+)/$', TagDetail.as_view(), name ='tag-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080053# url(r'plstackapi/tags/!new/$', TagNew.as_view(), name ='tag-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080054
55 url(r'plstackapi/invoices/$', InvoiceList.as_view(), name='invoice-list'),
56 url(r'plstackapi/invoices/(?P<pk>[a-zA-Z0-9\-]+)/$', InvoiceDetail.as_view(), name ='invoice-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080057# url(r'plstackapi/invoices/!new/$', InvoiceNew.as_view(), name ='invoice-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080058
59 url(r'plstackapi/slice_privileges/$', SlicePrivilegeList.as_view(), name='sliceprivilege-list'),
60 url(r'plstackapi/slice_privileges/(?P<pk>[a-zA-Z0-9\-]+)/$', SlicePrivilegeDetail.as_view(), name ='sliceprivilege-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080061# url(r'plstackapi/slice_privileges/!new/$', SlicePrivilegeNew.as_view(), name ='sliceprivilege-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080062
63 url(r'plstackapi/planetstackroles/$', PlanetStackRoleList.as_view(), name='planetstackrole-list'),
64 url(r'plstackapi/planetstackroles/(?P<pk>[a-zA-Z0-9\-]+)/$', PlanetStackRoleDetail.as_view(), name ='planetstackrole-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080065# url(r'plstackapi/planetstackroles/!new/$', PlanetStackRoleNew.as_view(), name ='planetstackrole-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080066
67 url(r'plstackapi/networkslivers/$', NetworkSliverList.as_view(), name='networksliver-list'),
68 url(r'plstackapi/networkslivers/(?P<pk>[a-zA-Z0-9\-]+)/$', NetworkSliverDetail.as_view(), name ='networksliver-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080069# url(r'plstackapi/networkslivers/!new/$', NetworkSliverNew.as_view(), name ='networksliver-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080070
71 url(r'plstackapi/networkdeployments/$', NetworkDeploymentsList.as_view(), name='networkdeployments-list'),
72 url(r'plstackapi/networkdeployments/(?P<pk>[a-zA-Z0-9\-]+)/$', NetworkDeploymentsDetail.as_view(), name ='networkdeployments-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080073# url(r'plstackapi/networkdeployments/!new/$', NetworkDeploymentsNew.as_view(), name ='networkdeployments-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080074
75 url(r'plstackapi/flavors/$', FlavorList.as_view(), name='flavor-list'),
76 url(r'plstackapi/flavors/(?P<pk>[a-zA-Z0-9\-]+)/$', FlavorDetail.as_view(), name ='flavor-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080077# url(r'plstackapi/flavors/!new/$', FlavorNew.as_view(), name ='flavor-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080078
79 url(r'plstackapi/projects/$', ProjectList.as_view(), name='project-list'),
80 url(r'plstackapi/projects/(?P<pk>[a-zA-Z0-9\-]+)/$', ProjectDetail.as_view(), name ='project-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080081# url(r'plstackapi/projects/!new/$', ProjectNew.as_view(), name ='project-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080082
83 url(r'plstackapi/slices/$', SliceList.as_view(), name='slice-list'),
84 url(r'plstackapi/slices/(?P<pk>[a-zA-Z0-9\-]+)/$', SliceDetail.as_view(), name ='slice-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080085# url(r'plstackapi/slices/!new/$', SliceNew.as_view(), name ='slice-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080086
87 url(r'plstackapi/networks/$', NetworkList.as_view(), name='network-list'),
88 url(r'plstackapi/networks/(?P<pk>[a-zA-Z0-9\-]+)/$', NetworkDetail.as_view(), name ='network-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080089# url(r'plstackapi/networks/!new/$', NetworkNew.as_view(), name ='network-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080090
91 url(r'plstackapi/services/$', ServiceList.as_view(), name='service-list'),
92 url(r'plstackapi/services/(?P<pk>[a-zA-Z0-9\-]+)/$', ServiceDetail.as_view(), name ='service-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080093# url(r'plstackapi/services/!new/$', ServiceNew.as_view(), name ='service-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080094
95 url(r'plstackapi/serviceclasses/$', ServiceClassList.as_view(), name='serviceclass-list'),
96 url(r'plstackapi/serviceclasses/(?P<pk>[a-zA-Z0-9\-]+)/$', ServiceClassDetail.as_view(), name ='serviceclass-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -080097# url(r'plstackapi/serviceclasses/!new/$', ServiceClassNew.as_view(), name ='serviceclass-new'),
Scott Baker55a2e292014-11-10 16:31:15 -080098
Scott Baker645dc9d2014-11-17 22:32:19 -080099 url(r'plstackapi/planetstacks/$', PlanetStackList.as_view(), name='planetstack-list'),
100 url(r'plstackapi/planetstacks/(?P<pk>[a-zA-Z0-9\-]+)/$', PlanetStackDetail.as_view(), name ='planetstack-detail'),
101# url(r'plstackapi/planetstacks/!new/$', PlanetStackNew.as_view(), name ='planetstack-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800102
103 url(r'plstackapi/charges/$', ChargeList.as_view(), name='charge-list'),
104 url(r'plstackapi/charges/(?P<pk>[a-zA-Z0-9\-]+)/$', ChargeDetail.as_view(), name ='charge-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800105# url(r'plstackapi/charges/!new/$', ChargeNew.as_view(), name ='charge-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800106
107 url(r'plstackapi/roles/$', RoleList.as_view(), name='role-list'),
108 url(r'plstackapi/roles/(?P<pk>[a-zA-Z0-9\-]+)/$', RoleDetail.as_view(), name ='role-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800109# url(r'plstackapi/roles/!new/$', RoleNew.as_view(), name ='role-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800110
111 url(r'plstackapi/usableobjects/$', UsableObjectList.as_view(), name='usableobject-list'),
112 url(r'plstackapi/usableobjects/(?P<pk>[a-zA-Z0-9\-]+)/$', UsableObjectDetail.as_view(), name ='usableobject-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800113# url(r'plstackapi/usableobjects/!new/$', UsableObjectNew.as_view(), name ='usableobject-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800114
115 url(r'plstackapi/site_roles/$', SiteRoleList.as_view(), name='siterole-list'),
116 url(r'plstackapi/site_roles/(?P<pk>[a-zA-Z0-9\-]+)/$', SiteRoleDetail.as_view(), name ='siterole-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800117# url(r'plstackapi/site_roles/!new/$', SiteRoleNew.as_view(), name ='siterole-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800118
119 url(r'plstackapi/slicecredentials/$', SliceCredentialList.as_view(), name='slicecredential-list'),
120 url(r'plstackapi/slicecredentials/(?P<pk>[a-zA-Z0-9\-]+)/$', SliceCredentialDetail.as_view(), name ='slicecredential-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800121# url(r'plstackapi/slicecredentials/!new/$', SliceCredentialNew.as_view(), name ='slicecredential-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800122
123 url(r'plstackapi/slivers/$', SliverList.as_view(), name='sliver-list'),
124 url(r'plstackapi/slivers/(?P<pk>[a-zA-Z0-9\-]+)/$', SliverDetail.as_view(), name ='sliver-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800125# url(r'plstackapi/slivers/!new/$', SliverNew.as_view(), name ='sliver-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800126
127 url(r'plstackapi/nodes/$', NodeList.as_view(), name='node-list'),
128 url(r'plstackapi/nodes/(?P<pk>[a-zA-Z0-9\-]+)/$', NodeDetail.as_view(), name ='node-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800129# url(r'plstackapi/nodes/!new/$', NodeNew.as_view(), name ='node-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800130
131 url(r'plstackapi/dashboardviews/$', DashboardViewList.as_view(), name='dashboardview-list'),
132 url(r'plstackapi/dashboardviews/(?P<pk>[a-zA-Z0-9\-]+)/$', DashboardViewDetail.as_view(), name ='dashboardview-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800133# url(r'plstackapi/dashboardviews/!new/$', DashboardViewNew.as_view(), name ='dashboardview-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800134
Scott Baker55a2e292014-11-10 16:31:15 -0800135 url(r'plstackapi/reservedresources/$', ReservedResourceList.as_view(), name='reservedresource-list'),
136 url(r'plstackapi/reservedresources/(?P<pk>[a-zA-Z0-9\-]+)/$', ReservedResourceDetail.as_view(), name ='reservedresource-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800137# url(r'plstackapi/reservedresources/!new/$', ReservedResourceNew.as_view(), name ='reservedresource-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800138
Scott Baker645dc9d2014-11-17 22:32:19 -0800139 url(r'plstackapi/payments/$', PaymentList.as_view(), name='payment-list'),
140 url(r'plstackapi/payments/(?P<pk>[a-zA-Z0-9\-]+)/$', PaymentDetail.as_view(), name ='payment-detail'),
141# url(r'plstackapi/payments/!new/$', PaymentNew.as_view(), name ='payment-new'),
142
Scott Baker55a2e292014-11-10 16:31:15 -0800143 url(r'plstackapi/networkslices/$', NetworkSliceList.as_view(), name='networkslice-list'),
144 url(r'plstackapi/networkslices/(?P<pk>[a-zA-Z0-9\-]+)/$', NetworkSliceDetail.as_view(), name ='networkslice-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800145# url(r'plstackapi/networkslices/!new/$', NetworkSliceNew.as_view(), name ='networkslice-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800146
147 url(r'plstackapi/userdashboardviews/$', UserDashboardViewList.as_view(), name='userdashboardview-list'),
148 url(r'plstackapi/userdashboardviews/(?P<pk>[a-zA-Z0-9\-]+)/$', UserDashboardViewDetail.as_view(), name ='userdashboardview-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800149# url(r'plstackapi/userdashboardviews/!new/$', UserDashboardViewNew.as_view(), name ='userdashboardview-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800150
Scott Baker645dc9d2014-11-17 22:32:19 -0800151 url(r'plstackapi/sitedeployments/$', SiteDeploymentList.as_view(), name='sitedeployment-list'),
152 url(r'plstackapi/sitedeployments/(?P<pk>[a-zA-Z0-9\-]+)/$', SiteDeploymentDetail.as_view(), name ='sitedeployment-detail'),
153# url(r'plstackapi/sitedeployments/!new/$', SiteDeploymentNew.as_view(), name ='sitedeployment-new'),
154
Scott Baker55a2e292014-11-10 16:31:15 -0800155 url(r'plstackapi/planetstackprivileges/$', PlanetStackPrivilegeList.as_view(), name='planetstackprivilege-list'),
156 url(r'plstackapi/planetstackprivileges/(?P<pk>[a-zA-Z0-9\-]+)/$', PlanetStackPrivilegeDetail.as_view(), name ='planetstackprivilege-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800157# url(r'plstackapi/planetstackprivileges/!new/$', PlanetStackPrivilegeNew.as_view(), name ='planetstackprivilege-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800158
159 url(r'plstackapi/users/$', UserList.as_view(), name='user-list'),
160 url(r'plstackapi/users/(?P<pk>[a-zA-Z0-9\-]+)/$', UserDetail.as_view(), name ='user-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800161# url(r'plstackapi/users/!new/$', UserNew.as_view(), name ='user-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800162
163 url(r'plstackapi/deployments/$', DeploymentList.as_view(), name='deployment-list'),
164 url(r'plstackapi/deployments/(?P<pk>[a-zA-Z0-9\-]+)/$', DeploymentDetail.as_view(), name ='deployment-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800165# url(r'plstackapi/deployments/!new/$', DeploymentNew.as_view(), name ='deployment-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800166
167 url(r'plstackapi/reservations/$', ReservationList.as_view(), name='reservation-list'),
168 url(r'plstackapi/reservations/(?P<pk>[a-zA-Z0-9\-]+)/$', ReservationDetail.as_view(), name ='reservation-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800169# url(r'plstackapi/reservations/!new/$', ReservationNew.as_view(), name ='reservation-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800170
Scott Baker55a2e292014-11-10 16:31:15 -0800171 url(r'plstackapi/siteprivileges/$', SitePrivilegeList.as_view(), name='siteprivilege-list'),
172 url(r'plstackapi/siteprivileges/(?P<pk>[a-zA-Z0-9\-]+)/$', SitePrivilegeDetail.as_view(), name ='siteprivilege-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800173# url(r'plstackapi/siteprivileges/!new/$', SitePrivilegeNew.as_view(), name ='siteprivilege-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800174
Scott Baker645dc9d2014-11-17 22:32:19 -0800175 url(r'plstackapi/slicedeployments/$', SliceDeploymentList.as_view(), name='slicedeployment-list'),
176 url(r'plstackapi/slicedeployments/(?P<pk>[a-zA-Z0-9\-]+)/$', SliceDeploymentDetail.as_view(), name ='slicedeployment-detail'),
177# url(r'plstackapi/slicedeployments/!new/$', SliceDeploymentNew.as_view(), name ='slicedeployment-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800178
Scott Baker645dc9d2014-11-17 22:32:19 -0800179 url(r'plstackapi/userdeployments/$', UserDeploymentList.as_view(), name='userdeployment-list'),
180 url(r'plstackapi/userdeployments/(?P<pk>[a-zA-Z0-9\-]+)/$', UserDeploymentDetail.as_view(), name ='userdeployment-detail'),
181# url(r'plstackapi/userdeployments/!new/$', UserDeploymentNew.as_view(), name ='userdeployment-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800182
183 url(r'plstackapi/accounts/$', AccountList.as_view(), name='account-list'),
184 url(r'plstackapi/accounts/(?P<pk>[a-zA-Z0-9\-]+)/$', AccountDetail.as_view(), name ='account-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800185# url(r'plstackapi/accounts/!new/$', AccountNew.as_view(), name ='account-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800186
187 url(r'plstackapi/networkparametertypes/$', NetworkParameterTypeList.as_view(), name='networkparametertype-list'),
188 url(r'plstackapi/networkparametertypes/(?P<pk>[a-zA-Z0-9\-]+)/$', NetworkParameterTypeDetail.as_view(), name ='networkparametertype-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800189# url(r'plstackapi/networkparametertypes/!new/$', NetworkParameterTypeNew.as_view(), name ='networkparametertype-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800190
191 url(r'plstackapi/sitecredentials/$', SiteCredentialList.as_view(), name='sitecredential-list'),
192 url(r'plstackapi/sitecredentials/(?P<pk>[a-zA-Z0-9\-]+)/$', SiteCredentialDetail.as_view(), name ='sitecredential-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800193# url(r'plstackapi/sitecredentials/!new/$', SiteCredentialNew.as_view(), name ='sitecredential-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800194
195 url(r'plstackapi/deploymentprivileges/$', DeploymentPrivilegeList.as_view(), name='deploymentprivilege-list'),
196 url(r'plstackapi/deploymentprivileges/(?P<pk>[a-zA-Z0-9\-]+)/$', DeploymentPrivilegeDetail.as_view(), name ='deploymentprivilege-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800197# url(r'plstackapi/deploymentprivileges/!new/$', DeploymentPrivilegeNew.as_view(), name ='deploymentprivilege-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800198
Scott Baker645dc9d2014-11-17 22:32:19 -0800199 url(r'plstackapi/imagedeployments/$', ImageDeploymentList.as_view(), name='imagedeployment-list'),
200 url(r'plstackapi/imagedeployments/(?P<pk>[a-zA-Z0-9\-]+)/$', ImageDeploymentDetail.as_view(), name ='imagedeployment-detail'),
201# url(r'plstackapi/imagedeployments/!new/$', ImageDeploymentNew.as_view(), name ='imagedeployment-new'),
202
Scott Baker55a2e292014-11-10 16:31:15 -0800203 url(r'plstackapi/deploymentroles/$', DeploymentRoleList.as_view(), name='deploymentrole-list'),
204 url(r'plstackapi/deploymentroles/(?P<pk>[a-zA-Z0-9\-]+)/$', DeploymentRoleDetail.as_view(), name ='deploymentrole-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800205# url(r'plstackapi/deploymentroles/!new/$', DeploymentRoleNew.as_view(), name ='deploymentrole-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800206
207 url(r'plstackapi/usercredentials/$', UserCredentialList.as_view(), name='usercredential-list'),
208 url(r'plstackapi/usercredentials/(?P<pk>[a-zA-Z0-9\-]+)/$', UserCredentialDetail.as_view(), name ='usercredential-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800209# url(r'plstackapi/usercredentials/!new/$', UserCredentialNew.as_view(), name ='usercredential-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800210
Scott Baker55a2e292014-11-10 16:31:15 -0800211 url(r'plstackapi/slicetags/$', SliceTagList.as_view(), name='slicetag-list'),
212 url(r'plstackapi/slicetags/(?P<pk>[a-zA-Z0-9\-]+)/$', SliceTagDetail.as_view(), name ='slicetag-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800213# url(r'plstackapi/slicetags/!new/$', SliceTagNew.as_view(), name ='slicetag-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800214
215 url(r'plstackapi/networktemplates/$', NetworkTemplateList.as_view(), name='networktemplate-list'),
216 url(r'plstackapi/networktemplates/(?P<pk>[a-zA-Z0-9\-]+)/$', NetworkTemplateDetail.as_view(), name ='networktemplate-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800217# url(r'plstackapi/networktemplates/!new/$', NetworkTemplateNew.as_view(), name ='networktemplate-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800218
219 url(r'plstackapi/routers/$', RouterList.as_view(), name='router-list'),
220 url(r'plstackapi/routers/(?P<pk>[a-zA-Z0-9\-]+)/$', RouterDetail.as_view(), name ='router-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800221# url(r'plstackapi/routers/!new/$', RouterNew.as_view(), name ='router-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800222
223 url(r'plstackapi/serviceresources/$', ServiceResourceList.as_view(), name='serviceresource-list'),
224 url(r'plstackapi/serviceresources/(?P<pk>[a-zA-Z0-9\-]+)/$', ServiceResourceDetail.as_view(), name ='serviceresource-detail'),
Scott Bakerf3816ac2014-11-12 01:13:53 -0800225# url(r'plstackapi/serviceresources/!new/$', ServiceResourceNew.as_view(), name ='serviceresource-new'),
Scott Baker55a2e292014-11-10 16:31:15 -0800226
227 )
Sapan Bhatiadea39432014-06-13 03:10:36 -0400228
229@api_view(['GET'])
230def api_root(request, format=None):
231 return Response({
Scott Baker08898c12014-10-29 23:41:11 -0700232 'serviceattributes': reverse('serviceattribute-list', request=request, format=format),
233 'images': reverse('image-list', request=request, format=format),
234 'networkparameters': reverse('networkparameter-list', request=request, format=format),
235 'sites': reverse('site-list', request=request, format=format),
236 'sliceroles': reverse('slicerole-list', request=request, format=format),
237 'tags': reverse('tag-list', request=request, format=format),
238 'invoices': reverse('invoice-list', request=request, format=format),
239 'sliceprivileges': reverse('sliceprivilege-list', request=request, format=format),
240 'planetstackroles': reverse('planetstackrole-list', request=request, format=format),
241 'networkslivers': reverse('networksliver-list', request=request, format=format),
242 'networkdeploymentses': reverse('networkdeployments-list', request=request, format=format),
243 'flavors': reverse('flavor-list', request=request, format=format),
244 'projects': reverse('project-list', request=request, format=format),
245 'slices': reverse('slice-list', request=request, format=format),
246 'networks': reverse('network-list', request=request, format=format),
247 'services': reverse('service-list', request=request, format=format),
248 'serviceclasses': reverse('serviceclass-list', request=request, format=format),
Scott Baker645dc9d2014-11-17 22:32:19 -0800249 'planetstacks': reverse('planetstack-list', request=request, format=format),
Scott Baker08898c12014-10-29 23:41:11 -0700250 'charges': reverse('charge-list', request=request, format=format),
251 'roles': reverse('role-list', request=request, format=format),
252 'usableobjects': reverse('usableobject-list', request=request, format=format),
253 'siteroles': reverse('siterole-list', request=request, format=format),
254 'slicecredentials': reverse('slicecredential-list', request=request, format=format),
255 'slivers': reverse('sliver-list', request=request, format=format),
256 'nodes': reverse('node-list', request=request, format=format),
257 'dashboardviews': reverse('dashboardview-list', request=request, format=format),
Scott Baker08898c12014-10-29 23:41:11 -0700258 'reservedresources': reverse('reservedresource-list', request=request, format=format),
Scott Baker645dc9d2014-11-17 22:32:19 -0800259 'payments': reverse('payment-list', request=request, format=format),
Scott Baker08898c12014-10-29 23:41:11 -0700260 'networkslices': reverse('networkslice-list', request=request, format=format),
261 'userdashboardviews': reverse('userdashboardview-list', request=request, format=format),
Scott Baker645dc9d2014-11-17 22:32:19 -0800262 'sitedeployments': reverse('sitedeployment-list', request=request, format=format),
Scott Baker08898c12014-10-29 23:41:11 -0700263 'planetstackprivileges': reverse('planetstackprivilege-list', request=request, format=format),
264 'users': reverse('user-list', request=request, format=format),
265 'deployments': reverse('deployment-list', request=request, format=format),
266 'reservations': reverse('reservation-list', request=request, format=format),
Scott Baker08898c12014-10-29 23:41:11 -0700267 'siteprivileges': reverse('siteprivilege-list', request=request, format=format),
Scott Baker645dc9d2014-11-17 22:32:19 -0800268 'slicedeployments': reverse('slicedeployment-list', request=request, format=format),
269 'userdeployments': reverse('userdeployment-list', request=request, format=format),
Scott Baker08898c12014-10-29 23:41:11 -0700270 'accounts': reverse('account-list', request=request, format=format),
271 'networkparametertypes': reverse('networkparametertype-list', request=request, format=format),
272 'sitecredentials': reverse('sitecredential-list', request=request, format=format),
273 'deploymentprivileges': reverse('deploymentprivilege-list', request=request, format=format),
Scott Baker645dc9d2014-11-17 22:32:19 -0800274 'imagedeployments': reverse('imagedeployment-list', request=request, format=format),
Scott Baker08898c12014-10-29 23:41:11 -0700275 'deploymentroles': reverse('deploymentrole-list', request=request, format=format),
276 'usercredentials': reverse('usercredential-list', request=request, format=format),
Scott Baker08898c12014-10-29 23:41:11 -0700277 'slicetags': reverse('slicetag-list', request=request, format=format),
278 'networktemplates': reverse('networktemplate-list', request=request, format=format),
279 'routers': reverse('router-list', request=request, format=format),
280 'serviceresources': reverse('serviceresource-list', request=request, format=format),
281
Sapan Bhatiadea39432014-06-13 03:10:36 -0400282 })
283
284# Based on serializers.py
285
286
287
Scott Baker0caeaf02014-06-19 11:12:55 -0700288class ServiceAttributeSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700289 id = serializers.Field()
290
291 class Meta:
292 model = ServiceAttribute
293 fields = ('id','created','updated','enacted','backend_status','deleted','name','value','service',)
Scott Baker46b58542014-08-11 17:26:12 -0700294
295class ServiceAttributeIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700296 id = serializers.Field()
297
298 class Meta:
299 model = ServiceAttribute
300 fields = ('id','created','updated','enacted','backend_status','deleted','name','value','service',)
Scott Baker46b58542014-08-11 17:26:12 -0700301
302
Sapan Bhatiadea39432014-06-13 03:10:36 -0400303
304
305class ImageSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700306 id = serializers.Field()
307
308 class Meta:
309 model = Image
310 fields = ('id','created','updated','enacted','backend_status','deleted','name','disk_format','container_format','path',)
Scott Baker46b58542014-08-11 17:26:12 -0700311
312class ImageIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700313 id = serializers.Field()
314
315 class Meta:
316 model = Image
317 fields = ('id','created','updated','enacted','backend_status','deleted','name','disk_format','container_format','path',)
Scott Baker46b58542014-08-11 17:26:12 -0700318
319
Sapan Bhatiadea39432014-06-13 03:10:36 -0400320
321
Scott Baker0caeaf02014-06-19 11:12:55 -0700322class NetworkParameterSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700323 id = serializers.Field()
324
325 class Meta:
326 model = NetworkParameter
327 fields = ('id','created','updated','enacted','backend_status','deleted','parameter','value','content_type','object_id',)
Scott Baker46b58542014-08-11 17:26:12 -0700328
329class NetworkParameterIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700330 id = serializers.Field()
331
332 class Meta:
333 model = NetworkParameter
334 fields = ('id','created','updated','enacted','backend_status','deleted','parameter','value','content_type','object_id',)
Scott Baker46b58542014-08-11 17:26:12 -0700335
336
Sapan Bhatiadea39432014-06-13 03:10:36 -0400337
338
339class SiteSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700340 id = serializers.Field()
341
342 class Meta:
343 model = Site
344 fields = ('id','created','updated','enacted','backend_status','deleted','name','site_url','enabled','location','longitude','latitude','login_base','is_public','abbreviated_name',)
Scott Baker46b58542014-08-11 17:26:12 -0700345
346class SiteIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700347 id = serializers.Field()
348
349 class Meta:
350 model = Site
351 fields = ('id','created','updated','enacted','backend_status','deleted','name','site_url','enabled','location','longitude','latitude','login_base','is_public','abbreviated_name',)
Scott Baker46b58542014-08-11 17:26:12 -0700352
353
Sapan Bhatiadea39432014-06-13 03:10:36 -0400354
355
Scott Baker0caeaf02014-06-19 11:12:55 -0700356class SliceRoleSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700357 id = serializers.Field()
358
359 class Meta:
360 model = SliceRole
361 fields = ('id','created','updated','enacted','backend_status','deleted','role',)
Scott Baker46b58542014-08-11 17:26:12 -0700362
363class SliceRoleIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700364 id = serializers.Field()
365
366 class Meta:
367 model = SliceRole
368 fields = ('id','created','updated','enacted','backend_status','deleted','role',)
Scott Baker46b58542014-08-11 17:26:12 -0700369
370
Sapan Bhatiadea39432014-06-13 03:10:36 -0400371
372
373class TagSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700374 id = serializers.Field()
375
376 class Meta:
377 model = Tag
378 fields = ('id','created','updated','enacted','backend_status','deleted','service','name','value','content_type','object_id',)
Scott Baker46b58542014-08-11 17:26:12 -0700379
380class TagIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700381 id = serializers.Field()
382
383 class Meta:
384 model = Tag
385 fields = ('id','created','updated','enacted','backend_status','deleted','service','name','value','content_type','object_id',)
Scott Baker46b58542014-08-11 17:26:12 -0700386
387
Sapan Bhatiadea39432014-06-13 03:10:36 -0400388
389
390class InvoiceSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700391 id = serializers.Field()
392
393 class Meta:
394 model = Invoice
395 fields = ('id','created','updated','enacted','backend_status','deleted','date','account',)
Scott Baker46b58542014-08-11 17:26:12 -0700396
397class InvoiceIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700398 id = serializers.Field()
399
400 class Meta:
401 model = Invoice
402 fields = ('id','created','updated','enacted','backend_status','deleted','date','account',)
Scott Baker46b58542014-08-11 17:26:12 -0700403
404
Sapan Bhatiadea39432014-06-13 03:10:36 -0400405
406
Scott Baker0caeaf02014-06-19 11:12:55 -0700407class SlicePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700408 id = serializers.Field()
409
410 class Meta:
411 model = SlicePrivilege
412 fields = ('id','created','updated','enacted','backend_status','deleted','user','slice','role',)
Scott Baker46b58542014-08-11 17:26:12 -0700413
414class SlicePrivilegeIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700415 id = serializers.Field()
416
417 class Meta:
418 model = SlicePrivilege
419 fields = ('id','created','updated','enacted','backend_status','deleted','user','slice','role',)
Scott Baker46b58542014-08-11 17:26:12 -0700420
421
Scott Baker0caeaf02014-06-19 11:12:55 -0700422
423
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700424class PlanetStackRoleSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700425 id = serializers.Field()
426
427 class Meta:
428 model = PlanetStackRole
429 fields = ('id','created','updated','enacted','backend_status','deleted','role',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700430
431class PlanetStackRoleIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700432 id = serializers.Field()
433
434 class Meta:
435 model = PlanetStackRole
436 fields = ('id','created','updated','enacted','backend_status','deleted','role',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700437
438
439
440
Scott Baker0caeaf02014-06-19 11:12:55 -0700441class NetworkSliverSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700442 id = serializers.Field()
443
444 class Meta:
445 model = NetworkSliver
446 fields = ('id','created','updated','enacted','backend_status','deleted','network','sliver','ip','port_id',)
Scott Baker46b58542014-08-11 17:26:12 -0700447
448class NetworkSliverIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700449 id = serializers.Field()
450
451 class Meta:
452 model = NetworkSliver
453 fields = ('id','created','updated','enacted','backend_status','deleted','network','sliver','ip','port_id',)
Scott Baker46b58542014-08-11 17:26:12 -0700454
455
Scott Baker0caeaf02014-06-19 11:12:55 -0700456
457
458class NetworkDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700459 id = serializers.Field()
460
461 class Meta:
462 model = NetworkDeployments
463 fields = ('id','created','updated','enacted','backend_status','deleted','network','deployment','net_id','router_id','subnet_id','subnet',)
Scott Baker46b58542014-08-11 17:26:12 -0700464
465class NetworkDeploymentsIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700466 id = serializers.Field()
467
468 class Meta:
469 model = NetworkDeployments
470 fields = ('id','created','updated','enacted','backend_status','deleted','network','deployment','net_id','router_id','subnet_id','subnet',)
Scott Baker46b58542014-08-11 17:26:12 -0700471
472
Sapan Bhatiadea39432014-06-13 03:10:36 -0400473
474
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700475class FlavorSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700476 id = serializers.Field()
477
478 class Meta:
479 model = Flavor
480 fields = ('id','created','updated','enacted','backend_status','deleted','name','description','flavor','order','default',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700481
482class FlavorIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700483 id = serializers.Field()
484
485 class Meta:
486 model = Flavor
487 fields = ('id','created','updated','enacted','backend_status','deleted','name','description','flavor','order','default',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700488
489
490
491
492class ProjectSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700493 id = serializers.Field()
494
495 class Meta:
496 model = Project
497 fields = ('id','created','updated','enacted','backend_status','deleted','name',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700498
499class ProjectIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700500 id = serializers.Field()
501
502 class Meta:
503 model = Project
504 fields = ('id','created','updated','enacted','backend_status','deleted','name',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700505
506
507
508
Sapan Bhatiadea39432014-06-13 03:10:36 -0400509class SliceSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700510 id = serializers.Field()
511
512
513 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
514
515
516
517 availableNetworks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
518
519
520
521 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
522
523
524
525 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
526
527
528 class Meta:
529 model = Slice
530 fields = ('id','created','updated','enacted','backend_status','deleted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','imagePreference','service','network','mountDataSets','serviceClass','creator','networks','availableNetworks','networks','networks',)
Scott Baker46b58542014-08-11 17:26:12 -0700531
532class SliceIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700533 id = serializers.Field()
534
535
536 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
537
538
539
540 availableNetworks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
541
542
543
544 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
545
546
547
548 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
549
550
551 class Meta:
552 model = Slice
553 fields = ('id','created','updated','enacted','backend_status','deleted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','imagePreference','service','network','mountDataSets','serviceClass','creator','networks','availableNetworks','networks','networks',)
Scott Baker46b58542014-08-11 17:26:12 -0700554
555
Sapan Bhatiadea39432014-06-13 03:10:36 -0400556
557
558class NetworkSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700559 id = serializers.Field()
560
561
562 routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
563
564
565
566 availableRouters = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
567
568
569
570 routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
571
572
573
574 routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
575
576
577 class Meta:
578 model = Network
Scott Baker645dc9d2014-11-17 22:32:19 -0800579 fields = ('id','created','updated','enacted','backend_status','deleted','name','template','subnet','ports','labels','owner','guaranteedBandwidth','permitAllSlices','topologyParameters','controllerUrl','controllerParameters','network_id','router_id','subnet_id','routers','availableRouters','routers','routers',)
Scott Baker46b58542014-08-11 17:26:12 -0700580
581class NetworkIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700582 id = serializers.Field()
583
584
585 routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
586
587
588
589 availableRouters = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
590
591
592
593 routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
594
595
596
597 routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
598
599
600 class Meta:
601 model = Network
Scott Baker645dc9d2014-11-17 22:32:19 -0800602 fields = ('id','created','updated','enacted','backend_status','deleted','name','template','subnet','ports','labels','owner','guaranteedBandwidth','permitAllSlices','topologyParameters','controllerUrl','controllerParameters','network_id','router_id','subnet_id','routers','availableRouters','routers','routers',)
Scott Baker46b58542014-08-11 17:26:12 -0700603
604
Sapan Bhatiadea39432014-06-13 03:10:36 -0400605
606
607class ServiceSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700608 id = serializers.Field()
609
610 class Meta:
611 model = Service
612 fields = ('id','created','updated','enacted','backend_status','deleted','description','enabled','name','versionNumber','published',)
Scott Baker46b58542014-08-11 17:26:12 -0700613
614class ServiceIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700615 id = serializers.Field()
616
617 class Meta:
618 model = Service
619 fields = ('id','created','updated','enacted','backend_status','deleted','description','enabled','name','versionNumber','published',)
Scott Baker46b58542014-08-11 17:26:12 -0700620
621
Sapan Bhatiadea39432014-06-13 03:10:36 -0400622
623
Scott Baker0caeaf02014-06-19 11:12:55 -0700624class ServiceClassSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700625 id = serializers.Field()
626
627 class Meta:
628 model = ServiceClass
629 fields = ('id','created','updated','enacted','backend_status','deleted','name','description','commitment','membershipFee','membershipFeeMonths','upgradeRequiresApproval',)
Scott Baker46b58542014-08-11 17:26:12 -0700630
631class ServiceClassIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700632 id = serializers.Field()
633
634 class Meta:
635 model = ServiceClass
636 fields = ('id','created','updated','enacted','backend_status','deleted','name','description','commitment','membershipFee','membershipFeeMonths','upgradeRequiresApproval',)
Scott Baker46b58542014-08-11 17:26:12 -0700637
638
Sapan Bhatiadea39432014-06-13 03:10:36 -0400639
640
Scott Baker645dc9d2014-11-17 22:32:19 -0800641class PlanetStackSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700642 id = serializers.Field()
643
644 class Meta:
Scott Baker645dc9d2014-11-17 22:32:19 -0800645 model = PlanetStack
646 fields = ('id','created','updated','enacted','backend_status','deleted','description',)
Scott Baker46b58542014-08-11 17:26:12 -0700647
Scott Baker645dc9d2014-11-17 22:32:19 -0800648class PlanetStackIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700649 id = serializers.Field()
650
651 class Meta:
Scott Baker645dc9d2014-11-17 22:32:19 -0800652 model = PlanetStack
653 fields = ('id','created','updated','enacted','backend_status','deleted','description',)
Scott Baker46b58542014-08-11 17:26:12 -0700654
655
Sapan Bhatiadea39432014-06-13 03:10:36 -0400656
657
658class ChargeSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700659 id = serializers.Field()
660
661 class Meta:
662 model = Charge
663 fields = ('id','created','updated','enacted','backend_status','deleted','account','slice','kind','state','date','object','amount','coreHours','invoice',)
Scott Baker46b58542014-08-11 17:26:12 -0700664
665class ChargeIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700666 id = serializers.Field()
667
668 class Meta:
669 model = Charge
670 fields = ('id','created','updated','enacted','backend_status','deleted','account','slice','kind','state','date','object','amount','coreHours','invoice',)
Scott Baker46b58542014-08-11 17:26:12 -0700671
672
Sapan Bhatiadea39432014-06-13 03:10:36 -0400673
674
675class RoleSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700676 id = serializers.Field()
677
678 class Meta:
679 model = Role
680 fields = ('id','created','updated','enacted','backend_status','deleted','role_type','role','description','content_type',)
Scott Baker46b58542014-08-11 17:26:12 -0700681
682class RoleIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700683 id = serializers.Field()
684
685 class Meta:
686 model = Role
687 fields = ('id','created','updated','enacted','backend_status','deleted','role_type','role','description','content_type',)
Scott Baker46b58542014-08-11 17:26:12 -0700688
689
Sapan Bhatiadea39432014-06-13 03:10:36 -0400690
691
Scott Baker0caeaf02014-06-19 11:12:55 -0700692class UsableObjectSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700693 id = serializers.Field()
694
695 class Meta:
696 model = UsableObject
697 fields = ('id','created','updated','enacted','backend_status','deleted','name',)
Scott Baker46b58542014-08-11 17:26:12 -0700698
699class UsableObjectIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700700 id = serializers.Field()
701
702 class Meta:
703 model = UsableObject
704 fields = ('id','created','updated','enacted','backend_status','deleted','name',)
Scott Baker46b58542014-08-11 17:26:12 -0700705
706
Sapan Bhatiadea39432014-06-13 03:10:36 -0400707
708
Scott Baker0caeaf02014-06-19 11:12:55 -0700709class SiteRoleSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700710 id = serializers.Field()
711
712 class Meta:
713 model = SiteRole
714 fields = ('id','created','updated','enacted','backend_status','deleted','role',)
Scott Baker46b58542014-08-11 17:26:12 -0700715
716class SiteRoleIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700717 id = serializers.Field()
718
719 class Meta:
720 model = SiteRole
721 fields = ('id','created','updated','enacted','backend_status','deleted','role',)
Scott Baker46b58542014-08-11 17:26:12 -0700722
723
Scott Baker0caeaf02014-06-19 11:12:55 -0700724
725
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700726class SliceCredentialSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700727 id = serializers.Field()
728
729 class Meta:
730 model = SliceCredential
731 fields = ('id','created','updated','enacted','backend_status','deleted','slice','name','key_id','enc_value',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700732
733class SliceCredentialIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700734 id = serializers.Field()
735
736 class Meta:
737 model = SliceCredential
738 fields = ('id','created','updated','enacted','backend_status','deleted','slice','name','key_id','enc_value',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -0700739
740
741
742
Sapan Bhatiadea39432014-06-13 03:10:36 -0400743class SliverSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700744 id = serializers.Field()
745
746
747 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
748
749
750
751 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
752
753
754 class Meta:
755 model = Sliver
756 fields = ('id','created','updated','enacted','backend_status','deleted','instance_id','name','instance_name','ip','image','creator','slice','node','deploymentNetwork','numberCores','flavor','userData','networks','networks',)
Scott Baker46b58542014-08-11 17:26:12 -0700757
758class SliverIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700759 id = serializers.Field()
760
761
762 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
763
764
765
766 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
767
768
769 class Meta:
770 model = Sliver
771 fields = ('id','created','updated','enacted','backend_status','deleted','instance_id','name','instance_name','ip','image','creator','slice','node','deploymentNetwork','numberCores','flavor','userData','networks','networks',)
Scott Baker46b58542014-08-11 17:26:12 -0700772
773
Sapan Bhatiadea39432014-06-13 03:10:36 -0400774
775
776class NodeSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700777 id = serializers.Field()
778
779 class Meta:
780 model = Node
781 fields = ('id','created','updated','enacted','backend_status','deleted','name','site','deployment',)
Scott Baker46b58542014-08-11 17:26:12 -0700782
783class NodeIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700784 id = serializers.Field()
785
786 class Meta:
787 model = Node
788 fields = ('id','created','updated','enacted','backend_status','deleted','name','site','deployment',)
Scott Baker46b58542014-08-11 17:26:12 -0700789
790
Sapan Bhatiadea39432014-06-13 03:10:36 -0400791
792
Scott Baker0caeaf02014-06-19 11:12:55 -0700793class DashboardViewSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700794 id = serializers.Field()
795
796 class Meta:
797 model = DashboardView
798 fields = ('id','created','updated','enacted','backend_status','deleted','name','url',)
Scott Baker46b58542014-08-11 17:26:12 -0700799
800class DashboardViewIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700801 id = serializers.Field()
802
803 class Meta:
804 model = DashboardView
805 fields = ('id','created','updated','enacted','backend_status','deleted','name','url',)
Scott Baker46b58542014-08-11 17:26:12 -0700806
807
Sapan Bhatiadea39432014-06-13 03:10:36 -0400808
809
Scott Baker0caeaf02014-06-19 11:12:55 -0700810class ReservedResourceSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700811 id = serializers.Field()
812
813 class Meta:
814 model = ReservedResource
815 fields = ('id','created','updated','enacted','backend_status','deleted','sliver','resource','quantity','reservationSet',)
Scott Baker46b58542014-08-11 17:26:12 -0700816
817class ReservedResourceIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700818 id = serializers.Field()
819
820 class Meta:
821 model = ReservedResource
822 fields = ('id','created','updated','enacted','backend_status','deleted','sliver','resource','quantity','reservationSet',)
Scott Baker46b58542014-08-11 17:26:12 -0700823
824
Sapan Bhatiadea39432014-06-13 03:10:36 -0400825
826
Scott Baker645dc9d2014-11-17 22:32:19 -0800827class PaymentSerializer(serializers.HyperlinkedModelSerializer):
828 id = serializers.Field()
829
830 class Meta:
831 model = Payment
832 fields = ('id','created','updated','enacted','backend_status','deleted','account','amount','date',)
833
834class PaymentIdSerializer(serializers.ModelSerializer):
835 id = serializers.Field()
836
837 class Meta:
838 model = Payment
839 fields = ('id','created','updated','enacted','backend_status','deleted','account','amount','date',)
840
841
842
843
Scott Baker0caeaf02014-06-19 11:12:55 -0700844class NetworkSliceSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700845 id = serializers.Field()
846
847 class Meta:
848 model = NetworkSlice
849 fields = ('id','created','updated','enacted','backend_status','deleted','network','slice',)
Scott Baker46b58542014-08-11 17:26:12 -0700850
851class NetworkSliceIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700852 id = serializers.Field()
853
854 class Meta:
855 model = NetworkSlice
856 fields = ('id','created','updated','enacted','backend_status','deleted','network','slice',)
Scott Baker46b58542014-08-11 17:26:12 -0700857
858
Scott Baker0caeaf02014-06-19 11:12:55 -0700859
860
861class UserDashboardViewSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700862 id = serializers.Field()
863
864 class Meta:
865 model = UserDashboardView
866 fields = ('id','created','updated','enacted','backend_status','deleted','user','dashboardView','order',)
Scott Baker46b58542014-08-11 17:26:12 -0700867
868class UserDashboardViewIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700869 id = serializers.Field()
870
871 class Meta:
872 model = UserDashboardView
873 fields = ('id','created','updated','enacted','backend_status','deleted','user','dashboardView','order',)
Scott Baker46b58542014-08-11 17:26:12 -0700874
875
Scott Baker0caeaf02014-06-19 11:12:55 -0700876
877
Scott Baker645dc9d2014-11-17 22:32:19 -0800878class SiteDeploymentSerializer(serializers.HyperlinkedModelSerializer):
879 id = serializers.Field()
880
881 class Meta:
882 model = SiteDeployment
883 fields = ('id','created','updated','enacted','backend_status','deleted','site','deployment','tenant_id',)
884
885class SiteDeploymentIdSerializer(serializers.ModelSerializer):
886 id = serializers.Field()
887
888 class Meta:
889 model = SiteDeployment
890 fields = ('id','created','updated','enacted','backend_status','deleted','site','deployment','tenant_id',)
891
892
893
894
Scott Baker0caeaf02014-06-19 11:12:55 -0700895class PlanetStackPrivilegeSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700896 id = serializers.Field()
897
898 class Meta:
899 model = PlanetStackPrivilege
900 fields = ('id','created','updated','enacted','backend_status','deleted','user','planetstack','role',)
Scott Baker46b58542014-08-11 17:26:12 -0700901
902class PlanetStackPrivilegeIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700903 id = serializers.Field()
904
905 class Meta:
906 model = PlanetStackPrivilege
907 fields = ('id','created','updated','enacted','backend_status','deleted','user','planetstack','role',)
Scott Baker46b58542014-08-11 17:26:12 -0700908
909
Sapan Bhatiadea39432014-06-13 03:10:36 -0400910
911
912class UserSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700913 id = serializers.Field()
914
915 class Meta:
916 model = User
917 fields = ('id','password','last_login','email','username','firstname','lastname','phone','user_url','site','public_key','is_active','is_admin','is_staff','is_readonly','created','updated','enacted','backend_status','deleted','timezone',)
Scott Baker46b58542014-08-11 17:26:12 -0700918
919class UserIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700920 id = serializers.Field()
921
922 class Meta:
923 model = User
924 fields = ('id','password','last_login','email','username','firstname','lastname','phone','user_url','site','public_key','is_active','is_admin','is_staff','is_readonly','created','updated','enacted','backend_status','deleted','timezone',)
Scott Baker46b58542014-08-11 17:26:12 -0700925
926
Sapan Bhatiadea39432014-06-13 03:10:36 -0400927
928
929class DeploymentSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700930 id = serializers.Field()
931
932
933 sites = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='site-detail')
934
935
936
937 sites = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='site-detail')
938
939
940
941 flavors = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='flavor-detail')
942
943
944
945 flavors = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='flavor-detail')
946
947
948 class Meta:
949 model = Deployment
950 fields = ('id','created','updated','enacted','backend_status','deleted','name','admin_user','admin_password','admin_tenant','auth_url','backend_type','availability_zone','accessControl','sites','sites','flavors','flavors',)
Scott Baker46b58542014-08-11 17:26:12 -0700951
952class DeploymentIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700953 id = serializers.Field()
954
955
956 sites = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='site-detail')
957
958
959
960 sites = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='site-detail')
961
962
963
964 flavors = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='flavor-detail')
965
966
967
968 flavors = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='flavor-detail')
969
970
971 class Meta:
972 model = Deployment
973 fields = ('id','created','updated','enacted','backend_status','deleted','name','admin_user','admin_password','admin_tenant','auth_url','backend_type','availability_zone','accessControl','sites','sites','flavors','flavors',)
Scott Baker46b58542014-08-11 17:26:12 -0700974
975
Sapan Bhatiadea39432014-06-13 03:10:36 -0400976
977
978class ReservationSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700979 id = serializers.Field()
980
981 class Meta:
982 model = Reservation
983 fields = ('id','created','updated','enacted','backend_status','deleted','startTime','slice','duration',)
Scott Baker46b58542014-08-11 17:26:12 -0700984
985class ReservationIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700986 id = serializers.Field()
987
988 class Meta:
989 model = Reservation
990 fields = ('id','created','updated','enacted','backend_status','deleted','startTime','slice','duration',)
Scott Baker46b58542014-08-11 17:26:12 -0700991
992
Sapan Bhatiadea39432014-06-13 03:10:36 -0400993
994
Scott Baker0caeaf02014-06-19 11:12:55 -0700995class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -0700996 id = serializers.Field()
997
998 class Meta:
999 model = SitePrivilege
1000 fields = ('id','created','updated','enacted','backend_status','deleted','user','site','role',)
Scott Baker46b58542014-08-11 17:26:12 -07001001
1002class SitePrivilegeIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001003 id = serializers.Field()
1004
1005 class Meta:
1006 model = SitePrivilege
1007 fields = ('id','created','updated','enacted','backend_status','deleted','user','site','role',)
Scott Baker46b58542014-08-11 17:26:12 -07001008
1009
Scott Baker0caeaf02014-06-19 11:12:55 -07001010
1011
Scott Baker645dc9d2014-11-17 22:32:19 -08001012class SliceDeploymentSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001013 id = serializers.Field()
1014
1015 class Meta:
Scott Baker645dc9d2014-11-17 22:32:19 -08001016 model = SliceDeployment
1017 fields = ('id','created','updated','enacted','backend_status','deleted','slice','deployment','tenant_id','network_id','router_id','subnet_id',)
Scott Baker46b58542014-08-11 17:26:12 -07001018
Scott Baker645dc9d2014-11-17 22:32:19 -08001019class SliceDeploymentIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001020 id = serializers.Field()
1021
1022 class Meta:
Scott Baker645dc9d2014-11-17 22:32:19 -08001023 model = SliceDeployment
1024 fields = ('id','created','updated','enacted','backend_status','deleted','slice','deployment','tenant_id','network_id','router_id','subnet_id',)
Scott Baker46b58542014-08-11 17:26:12 -07001025
1026
Sapan Bhatiadea39432014-06-13 03:10:36 -04001027
1028
Scott Baker645dc9d2014-11-17 22:32:19 -08001029class UserDeploymentSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001030 id = serializers.Field()
1031
1032 class Meta:
Scott Baker645dc9d2014-11-17 22:32:19 -08001033 model = UserDeployment
Scott Baker08898c12014-10-29 23:41:11 -07001034 fields = ('id','created','updated','enacted','backend_status','deleted','user','deployment','kuser_id',)
Scott Baker46b58542014-08-11 17:26:12 -07001035
Scott Baker645dc9d2014-11-17 22:32:19 -08001036class UserDeploymentIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001037 id = serializers.Field()
1038
1039 class Meta:
Scott Baker645dc9d2014-11-17 22:32:19 -08001040 model = UserDeployment
Scott Baker08898c12014-10-29 23:41:11 -07001041 fields = ('id','created','updated','enacted','backend_status','deleted','user','deployment','kuser_id',)
Scott Baker46b58542014-08-11 17:26:12 -07001042
1043
Scott Baker0caeaf02014-06-19 11:12:55 -07001044
1045
Sapan Bhatiadea39432014-06-13 03:10:36 -04001046class AccountSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001047 id = serializers.Field()
1048
1049 class Meta:
1050 model = Account
1051 fields = ('id','created','updated','enacted','backend_status','deleted','site',)
Scott Baker46b58542014-08-11 17:26:12 -07001052
1053class AccountIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001054 id = serializers.Field()
1055
1056 class Meta:
1057 model = Account
1058 fields = ('id','created','updated','enacted','backend_status','deleted','site',)
Scott Baker46b58542014-08-11 17:26:12 -07001059
1060
Sapan Bhatiadea39432014-06-13 03:10:36 -04001061
1062
Scott Baker0caeaf02014-06-19 11:12:55 -07001063class NetworkParameterTypeSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001064 id = serializers.Field()
1065
1066 class Meta:
1067 model = NetworkParameterType
1068 fields = ('id','created','updated','enacted','backend_status','deleted','name','description',)
Scott Baker46b58542014-08-11 17:26:12 -07001069
1070class NetworkParameterTypeIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001071 id = serializers.Field()
1072
1073 class Meta:
1074 model = NetworkParameterType
1075 fields = ('id','created','updated','enacted','backend_status','deleted','name','description',)
Scott Baker46b58542014-08-11 17:26:12 -07001076
1077
Sapan Bhatiadea39432014-06-13 03:10:36 -04001078
1079
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001080class SiteCredentialSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001081 id = serializers.Field()
1082
1083 class Meta:
1084 model = SiteCredential
1085 fields = ('id','created','updated','enacted','backend_status','deleted','site','name','key_id','enc_value',)
Scott Baker46b58542014-08-11 17:26:12 -07001086
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001087class SiteCredentialIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001088 id = serializers.Field()
1089
1090 class Meta:
1091 model = SiteCredential
1092 fields = ('id','created','updated','enacted','backend_status','deleted','site','name','key_id','enc_value',)
Scott Baker46b58542014-08-11 17:26:12 -07001093
1094
Scott Baker0caeaf02014-06-19 11:12:55 -07001095
1096
1097class DeploymentPrivilegeSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001098 id = serializers.Field()
1099
1100 class Meta:
1101 model = DeploymentPrivilege
1102 fields = ('id','created','updated','enacted','backend_status','deleted','user','deployment','role',)
Scott Baker46b58542014-08-11 17:26:12 -07001103
1104class DeploymentPrivilegeIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001105 id = serializers.Field()
1106
1107 class Meta:
1108 model = DeploymentPrivilege
1109 fields = ('id','created','updated','enacted','backend_status','deleted','user','deployment','role',)
Scott Baker46b58542014-08-11 17:26:12 -07001110
1111
Scott Baker0caeaf02014-06-19 11:12:55 -07001112
1113
Scott Baker645dc9d2014-11-17 22:32:19 -08001114class ImageDeploymentSerializer(serializers.HyperlinkedModelSerializer):
1115 id = serializers.Field()
1116
1117 class Meta:
1118 model = ImageDeployment
1119 fields = ('id','created','updated','enacted','backend_status','deleted','image','deployment','glance_image_id',)
1120
1121class ImageDeploymentIdSerializer(serializers.ModelSerializer):
1122 id = serializers.Field()
1123
1124 class Meta:
1125 model = ImageDeployment
1126 fields = ('id','created','updated','enacted','backend_status','deleted','image','deployment','glance_image_id',)
1127
1128
1129
1130
Scott Baker0caeaf02014-06-19 11:12:55 -07001131class DeploymentRoleSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001132 id = serializers.Field()
1133
1134 class Meta:
1135 model = DeploymentRole
1136 fields = ('id','created','updated','enacted','backend_status','deleted','role',)
Scott Baker46b58542014-08-11 17:26:12 -07001137
1138class DeploymentRoleIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001139 id = serializers.Field()
1140
1141 class Meta:
1142 model = DeploymentRole
1143 fields = ('id','created','updated','enacted','backend_status','deleted','role',)
Scott Baker46b58542014-08-11 17:26:12 -07001144
1145
Sapan Bhatiadea39432014-06-13 03:10:36 -04001146
1147
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001148class UserCredentialSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001149 id = serializers.Field()
1150
1151 class Meta:
1152 model = UserCredential
1153 fields = ('id','created','updated','enacted','backend_status','deleted','user','name','key_id','enc_value',)
Scott Baker46b58542014-08-11 17:26:12 -07001154
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001155class UserCredentialIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001156 id = serializers.Field()
1157
1158 class Meta:
1159 model = UserCredential
1160 fields = ('id','created','updated','enacted','backend_status','deleted','user','name','key_id','enc_value',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001161
1162
1163
1164
Scott Baker0caeaf02014-06-19 11:12:55 -07001165class SliceTagSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001166 id = serializers.Field()
1167
1168 class Meta:
1169 model = SliceTag
1170 fields = ('id','created','updated','enacted','backend_status','deleted','slice','name','value',)
Scott Baker46b58542014-08-11 17:26:12 -07001171
1172class SliceTagIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001173 id = serializers.Field()
1174
1175 class Meta:
1176 model = SliceTag
1177 fields = ('id','created','updated','enacted','backend_status','deleted','slice','name','value',)
Scott Baker46b58542014-08-11 17:26:12 -07001178
1179
Scott Baker0caeaf02014-06-19 11:12:55 -07001180
1181
1182class NetworkTemplateSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001183 id = serializers.Field()
1184
1185 class Meta:
1186 model = NetworkTemplate
Scott Baker645dc9d2014-11-17 22:32:19 -08001187 fields = ('id','created','updated','enacted','backend_status','deleted','name','description','guaranteedBandwidth','visibility','translation','sharedNetworkName','sharedNetworkId','topologyKind','controllerKind',)
Scott Baker46b58542014-08-11 17:26:12 -07001188
1189class NetworkTemplateIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001190 id = serializers.Field()
1191
1192 class Meta:
1193 model = NetworkTemplate
Scott Baker645dc9d2014-11-17 22:32:19 -08001194 fields = ('id','created','updated','enacted','backend_status','deleted','name','description','guaranteedBandwidth','visibility','translation','sharedNetworkName','sharedNetworkId','topologyKind','controllerKind',)
Scott Baker46b58542014-08-11 17:26:12 -07001195
1196
Sapan Bhatiadea39432014-06-13 03:10:36 -04001197
1198
1199class RouterSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001200 id = serializers.Field()
1201
1202 class Meta:
1203 model = Router
1204 fields = ('id','created','updated','enacted','backend_status','deleted','name','owner',)
Scott Baker46b58542014-08-11 17:26:12 -07001205
1206class RouterIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001207 id = serializers.Field()
1208
1209 class Meta:
1210 model = Router
1211 fields = ('id','created','updated','enacted','backend_status','deleted','name','owner',)
Scott Baker46b58542014-08-11 17:26:12 -07001212
1213
Sapan Bhatiadea39432014-06-13 03:10:36 -04001214
1215
Scott Baker0caeaf02014-06-19 11:12:55 -07001216class ServiceResourceSerializer(serializers.HyperlinkedModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001217 id = serializers.Field()
1218
1219 class Meta:
1220 model = ServiceResource
1221 fields = ('id','created','updated','enacted','backend_status','deleted','serviceClass','name','maxUnitsDeployment','maxUnitsNode','maxDuration','bucketInRate','bucketMaxSize','cost','calendarReservable',)
Scott Baker46b58542014-08-11 17:26:12 -07001222
1223class ServiceResourceIdSerializer(serializers.ModelSerializer):
Scott Baker08898c12014-10-29 23:41:11 -07001224 id = serializers.Field()
1225
1226 class Meta:
1227 model = ServiceResource
1228 fields = ('id','created','updated','enacted','backend_status','deleted','serviceClass','name','maxUnitsDeployment','maxUnitsNode','maxDuration','bucketInRate','bucketMaxSize','cost','calendarReservable',)
Scott Baker46b58542014-08-11 17:26:12 -07001229
1230
Sapan Bhatiadea39432014-06-13 03:10:36 -04001231
1232
1233serializerLookUp = {
1234
Scott Baker0caeaf02014-06-19 11:12:55 -07001235 ServiceAttribute: ServiceAttributeSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001236
1237 Image: ImageSerializer,
1238
Scott Baker0caeaf02014-06-19 11:12:55 -07001239 NetworkParameter: NetworkParameterSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001240
1241 Site: SiteSerializer,
1242
Scott Baker0caeaf02014-06-19 11:12:55 -07001243 SliceRole: SliceRoleSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001244
1245 Tag: TagSerializer,
1246
1247 Invoice: InvoiceSerializer,
1248
Scott Baker0caeaf02014-06-19 11:12:55 -07001249 SlicePrivilege: SlicePrivilegeSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001250
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001251 PlanetStackRole: PlanetStackRoleSerializer,
1252
Scott Baker0caeaf02014-06-19 11:12:55 -07001253 NetworkSliver: NetworkSliverSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001254
Scott Baker0caeaf02014-06-19 11:12:55 -07001255 NetworkDeployments: NetworkDeploymentsSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001256
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001257 Flavor: FlavorSerializer,
1258
1259 Project: ProjectSerializer,
1260
Sapan Bhatiadea39432014-06-13 03:10:36 -04001261 Slice: SliceSerializer,
1262
1263 Network: NetworkSerializer,
1264
1265 Service: ServiceSerializer,
1266
Scott Baker0caeaf02014-06-19 11:12:55 -07001267 ServiceClass: ServiceClassSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001268
Scott Baker645dc9d2014-11-17 22:32:19 -08001269 PlanetStack: PlanetStackSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001270
1271 Charge: ChargeSerializer,
1272
1273 Role: RoleSerializer,
1274
Scott Baker0caeaf02014-06-19 11:12:55 -07001275 UsableObject: UsableObjectSerializer,
1276
1277 SiteRole: SiteRoleSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001278
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001279 SliceCredential: SliceCredentialSerializer,
1280
Sapan Bhatiadea39432014-06-13 03:10:36 -04001281 Sliver: SliverSerializer,
1282
1283 Node: NodeSerializer,
1284
Scott Baker0caeaf02014-06-19 11:12:55 -07001285 DashboardView: DashboardViewSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001286
Scott Baker0caeaf02014-06-19 11:12:55 -07001287 ReservedResource: ReservedResourceSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001288
Scott Baker645dc9d2014-11-17 22:32:19 -08001289 Payment: PaymentSerializer,
1290
Scott Baker0caeaf02014-06-19 11:12:55 -07001291 NetworkSlice: NetworkSliceSerializer,
1292
1293 UserDashboardView: UserDashboardViewSerializer,
1294
Scott Baker645dc9d2014-11-17 22:32:19 -08001295 SiteDeployment: SiteDeploymentSerializer,
1296
Scott Baker0caeaf02014-06-19 11:12:55 -07001297 PlanetStackPrivilege: PlanetStackPrivilegeSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001298
1299 User: UserSerializer,
1300
1301 Deployment: DeploymentSerializer,
1302
1303 Reservation: ReservationSerializer,
1304
Scott Baker0caeaf02014-06-19 11:12:55 -07001305 SitePrivilege: SitePrivilegeSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001306
Scott Baker645dc9d2014-11-17 22:32:19 -08001307 SliceDeployment: SliceDeploymentSerializer,
Scott Baker0caeaf02014-06-19 11:12:55 -07001308
Scott Baker645dc9d2014-11-17 22:32:19 -08001309 UserDeployment: UserDeploymentSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001310
1311 Account: AccountSerializer,
1312
Scott Baker0caeaf02014-06-19 11:12:55 -07001313 NetworkParameterType: NetworkParameterTypeSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001314
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001315 SiteCredential: SiteCredentialSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001316
Scott Baker0caeaf02014-06-19 11:12:55 -07001317 DeploymentPrivilege: DeploymentPrivilegeSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001318
Scott Baker645dc9d2014-11-17 22:32:19 -08001319 ImageDeployment: ImageDeploymentSerializer,
1320
Scott Baker0caeaf02014-06-19 11:12:55 -07001321 DeploymentRole: DeploymentRoleSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001322
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001323 UserCredential: UserCredentialSerializer,
1324
Scott Baker0caeaf02014-06-19 11:12:55 -07001325 SliceTag: SliceTagSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001326
Scott Baker0caeaf02014-06-19 11:12:55 -07001327 NetworkTemplate: NetworkTemplateSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001328
1329 Router: RouterSerializer,
1330
Scott Baker0caeaf02014-06-19 11:12:55 -07001331 ServiceResource: ServiceResourceSerializer,
Sapan Bhatiadea39432014-06-13 03:10:36 -04001332
1333 None: None,
1334 }
1335
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001336class PlanetStackRetrieveUpdateDestroyAPIView(generics.RetrieveUpdateDestroyAPIView):
1337
1338 # To handle fine-grained field permissions, we have to check can_update
1339 # the object has been updated but before it has been saved.
1340
1341 def update(self, request, *args, **kwargs):
1342 partial = kwargs.pop('partial', False)
1343 self.object = self.get_object_or_none()
1344
1345 serializer = self.get_serializer(self.object, data=request.DATA,
1346 files=request.FILES, partial=partial)
1347
1348 if not serializer.is_valid():
1349 print "UpdateModelMixin: not serializer.is_valid"
1350 print serializer.errors
1351 return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
1352
1353 try:
1354 self.pre_save(serializer.object)
1355 except ValidationError as err:
1356 # full_clean on model instance may be called in pre_save,
1357 # so we have to handle eventual errors.
1358 return Response(err.message_dict, status=status.HTTP_400_BAD_REQUEST)
1359
1360 if serializer.object is not None:
1361 if not serializer.object.can_update(request.user):
1362 return Response(status=status.HTTP_400_BAD_REQUEST)
1363
1364 if self.object is None:
1365 self.object = serializer.save(force_insert=True)
1366 self.post_save(self.object, created=True)
1367 return Response(serializer.data, status=status.HTTP_201_CREATED)
1368
1369 self.object = serializer.save(force_update=True)
1370 self.post_save(self.object, created=False)
1371 return Response(serializer.data, status=status.HTTP_200_OK)
1372
1373 def destroy(self, request, *args, **kwargs):
1374 obj = self.get_object()
1375 if obj.can_update(request.user):
Scott Baker08898c12014-10-29 23:41:11 -07001376 return super(generics.RetrieveUpdateDestroyAPIView, self).destroy(request, *args, **kwargs)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001377 else:
1378 return Response(status=status.HTTP_400_BAD_REQUEST)
1379
1380
Sapan Bhatiadea39432014-06-13 03:10:36 -04001381# Based on core/views/*.py
1382
1383
Scott Baker0caeaf02014-06-19 11:12:55 -07001384class ServiceAttributeList(generics.ListCreateAPIView):
1385 queryset = ServiceAttribute.objects.select_related().all()
1386 serializer_class = ServiceAttributeSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001387 id_serializer_class = ServiceAttributeIdSerializer
1388 filter_backends = (filters.DjangoFilterBackend,)
1389 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','value','service',)
1390
1391 def get_serializer_class(self):
1392 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1393 if (no_hyperlinks):
1394 return self.id_serializer_class
1395 else:
1396 return self.serializer_class
1397
Scott Baker0caeaf02014-06-19 11:12:55 -07001398 def get_queryset(self):
1399 return ServiceAttribute.select_by_user(self.request.user)
Sapan Bhatiadea39432014-06-13 03:10:36 -04001400
Scott Baker0caeaf02014-06-19 11:12:55 -07001401 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08001402 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
1403 if not (serializer.is_valid()):
1404 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
1405 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07001406 obj.caller = request.user
1407 if obj.can_update(request.user):
1408 return super(ServiceAttributeList, self).create(request, *args, **kwargs)
1409 else:
Scott Baker08898c12014-10-29 23:41:11 -07001410 raise Exception("failed obj.can_update")
1411
1412 ret = super(ServiceAttributeList, self).create(request, *args, **kwargs)
1413 if (ret.status_code%100 != 200):
1414 raise Exception(ret.data)
1415
1416 return ret
1417
Scott Baker0caeaf02014-06-19 11:12:55 -07001418
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001419class ServiceAttributeDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001420 queryset = ServiceAttribute.objects.select_related().all()
1421 serializer_class = ServiceAttributeSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001422 id_serializer_class = ServiceAttributeIdSerializer
1423
1424 def get_serializer_class(self):
1425 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1426 if (no_hyperlinks):
1427 return self.id_serializer_class
1428 else:
1429 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07001430
1431 def get_queryset(self):
1432 return ServiceAttribute.select_by_user(self.request.user)
1433
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001434 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07001435
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001436 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04001437
Scott Bakerf3816ac2014-11-12 01:13:53 -08001438"""
1439 XXX smbaker: my intent was to create a view that would return 'new' objects
1440 filled with defaults. I solved it another way, so this code may soon be
1441 abandoned.
1442
1443class ServiceAttributeNew(GenericAPIView):
1444 serializer_class = ServiceAttributeSerializer
1445 id_serializer_class = ServiceAttributeIdSerializer
1446
1447 def get(self, request, *args, **kwargs):
1448 return self.makenew(request, *args, **kwargs)
1449
1450 def get_serializer_class(self):
1451 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1452 if (no_hyperlinks):
1453 return self.id_serializer_class
1454 else:
1455 return self.serializer_class
1456
1457 def makenew(self, request, *args, **kwargs):
1458 obj = ServiceAttribute()
1459 serializer = self.get_serializer(obj)
1460 return Response(serializer.data)
1461"""
1462
Sapan Bhatiadea39432014-06-13 03:10:36 -04001463
1464
1465class ImageList(generics.ListCreateAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001466 queryset = Image.objects.select_related().all()
Sapan Bhatiadea39432014-06-13 03:10:36 -04001467 serializer_class = ImageSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001468 id_serializer_class = ImageIdSerializer
1469 filter_backends = (filters.DjangoFilterBackend,)
1470 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','disk_format','container_format','path',)
1471
1472 def get_serializer_class(self):
1473 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1474 if (no_hyperlinks):
1475 return self.id_serializer_class
1476 else:
1477 return self.serializer_class
1478
Scott Baker0caeaf02014-06-19 11:12:55 -07001479 def get_queryset(self):
1480 return Image.select_by_user(self.request.user)
1481
1482 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08001483 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
1484 if not (serializer.is_valid()):
1485 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
1486 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07001487 obj.caller = request.user
1488 if obj.can_update(request.user):
1489 return super(ImageList, self).create(request, *args, **kwargs)
1490 else:
Scott Baker08898c12014-10-29 23:41:11 -07001491 raise Exception("failed obj.can_update")
1492
1493 ret = super(ImageList, self).create(request, *args, **kwargs)
1494 if (ret.status_code%100 != 200):
1495 raise Exception(ret.data)
1496
1497 return ret
1498
Sapan Bhatiadea39432014-06-13 03:10:36 -04001499
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001500class ImageDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001501 queryset = Image.objects.select_related().all()
Sapan Bhatiadea39432014-06-13 03:10:36 -04001502 serializer_class = ImageSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001503 id_serializer_class = ImageIdSerializer
1504
1505 def get_serializer_class(self):
1506 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1507 if (no_hyperlinks):
1508 return self.id_serializer_class
1509 else:
1510 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07001511
1512 def get_queryset(self):
1513 return Image.select_by_user(self.request.user)
1514
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001515 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07001516
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001517 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04001518
Scott Bakerf3816ac2014-11-12 01:13:53 -08001519"""
1520 XXX smbaker: my intent was to create a view that would return 'new' objects
1521 filled with defaults. I solved it another way, so this code may soon be
1522 abandoned.
1523
1524class ImageNew(GenericAPIView):
1525 serializer_class = ImageSerializer
1526 id_serializer_class = ImageIdSerializer
1527
1528 def get(self, request, *args, **kwargs):
1529 return self.makenew(request, *args, **kwargs)
1530
1531 def get_serializer_class(self):
1532 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1533 if (no_hyperlinks):
1534 return self.id_serializer_class
1535 else:
1536 return self.serializer_class
1537
1538 def makenew(self, request, *args, **kwargs):
1539 obj = Image()
1540 serializer = self.get_serializer(obj)
1541 return Response(serializer.data)
1542"""
1543
Sapan Bhatiadea39432014-06-13 03:10:36 -04001544
1545
Scott Baker0caeaf02014-06-19 11:12:55 -07001546class NetworkParameterList(generics.ListCreateAPIView):
1547 queryset = NetworkParameter.objects.select_related().all()
1548 serializer_class = NetworkParameterSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001549 id_serializer_class = NetworkParameterIdSerializer
1550 filter_backends = (filters.DjangoFilterBackend,)
1551 filter_fields = ('id','created','updated','enacted','backend_status','deleted','parameter','value','content_type','object_id',)
1552
1553 def get_serializer_class(self):
1554 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1555 if (no_hyperlinks):
1556 return self.id_serializer_class
1557 else:
1558 return self.serializer_class
1559
Scott Baker0caeaf02014-06-19 11:12:55 -07001560 def get_queryset(self):
1561 return NetworkParameter.select_by_user(self.request.user)
Sapan Bhatiadea39432014-06-13 03:10:36 -04001562
Scott Baker0caeaf02014-06-19 11:12:55 -07001563 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08001564 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
1565 if not (serializer.is_valid()):
1566 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
1567 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07001568 obj.caller = request.user
1569 if obj.can_update(request.user):
1570 return super(NetworkParameterList, self).create(request, *args, **kwargs)
1571 else:
Scott Baker08898c12014-10-29 23:41:11 -07001572 raise Exception("failed obj.can_update")
1573
1574 ret = super(NetworkParameterList, self).create(request, *args, **kwargs)
1575 if (ret.status_code%100 != 200):
1576 raise Exception(ret.data)
1577
1578 return ret
1579
Scott Baker0caeaf02014-06-19 11:12:55 -07001580
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001581class NetworkParameterDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001582 queryset = NetworkParameter.objects.select_related().all()
1583 serializer_class = NetworkParameterSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001584 id_serializer_class = NetworkParameterIdSerializer
1585
1586 def get_serializer_class(self):
1587 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1588 if (no_hyperlinks):
1589 return self.id_serializer_class
1590 else:
1591 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07001592
1593 def get_queryset(self):
1594 return NetworkParameter.select_by_user(self.request.user)
1595
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001596 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07001597
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001598 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04001599
Scott Bakerf3816ac2014-11-12 01:13:53 -08001600"""
1601 XXX smbaker: my intent was to create a view that would return 'new' objects
1602 filled with defaults. I solved it another way, so this code may soon be
1603 abandoned.
1604
1605class NetworkParameterNew(GenericAPIView):
1606 serializer_class = NetworkParameterSerializer
1607 id_serializer_class = NetworkParameterIdSerializer
1608
1609 def get(self, request, *args, **kwargs):
1610 return self.makenew(request, *args, **kwargs)
1611
1612 def get_serializer_class(self):
1613 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1614 if (no_hyperlinks):
1615 return self.id_serializer_class
1616 else:
1617 return self.serializer_class
1618
1619 def makenew(self, request, *args, **kwargs):
1620 obj = NetworkParameter()
1621 serializer = self.get_serializer(obj)
1622 return Response(serializer.data)
1623"""
1624
Sapan Bhatiadea39432014-06-13 03:10:36 -04001625
1626
1627class SiteList(generics.ListCreateAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001628 queryset = Site.objects.select_related().all()
Sapan Bhatiadea39432014-06-13 03:10:36 -04001629 serializer_class = SiteSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001630 id_serializer_class = SiteIdSerializer
1631 filter_backends = (filters.DjangoFilterBackend,)
1632 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','site_url','enabled','location','longitude','latitude','login_base','is_public','abbreviated_name',)
1633
1634 def get_serializer_class(self):
1635 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1636 if (no_hyperlinks):
1637 return self.id_serializer_class
1638 else:
1639 return self.serializer_class
1640
Scott Baker0caeaf02014-06-19 11:12:55 -07001641 def get_queryset(self):
1642 return Site.select_by_user(self.request.user)
1643
1644 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08001645 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
1646 if not (serializer.is_valid()):
1647 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
1648 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07001649 obj.caller = request.user
1650 if obj.can_update(request.user):
1651 return super(SiteList, self).create(request, *args, **kwargs)
1652 else:
Scott Baker08898c12014-10-29 23:41:11 -07001653 raise Exception("failed obj.can_update")
1654
1655 ret = super(SiteList, self).create(request, *args, **kwargs)
1656 if (ret.status_code%100 != 200):
1657 raise Exception(ret.data)
1658
1659 return ret
1660
Sapan Bhatiadea39432014-06-13 03:10:36 -04001661
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001662class SiteDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001663 queryset = Site.objects.select_related().all()
Sapan Bhatiadea39432014-06-13 03:10:36 -04001664 serializer_class = SiteSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001665 id_serializer_class = SiteIdSerializer
1666
1667 def get_serializer_class(self):
1668 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1669 if (no_hyperlinks):
1670 return self.id_serializer_class
1671 else:
1672 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07001673
1674 def get_queryset(self):
1675 return Site.select_by_user(self.request.user)
Sapan Bhatiadea39432014-06-13 03:10:36 -04001676
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001677 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04001678
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001679 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07001680
Scott Bakerf3816ac2014-11-12 01:13:53 -08001681"""
1682 XXX smbaker: my intent was to create a view that would return 'new' objects
1683 filled with defaults. I solved it another way, so this code may soon be
1684 abandoned.
1685
1686class SiteNew(GenericAPIView):
1687 serializer_class = SiteSerializer
1688 id_serializer_class = SiteIdSerializer
1689
1690 def get(self, request, *args, **kwargs):
1691 return self.makenew(request, *args, **kwargs)
1692
1693 def get_serializer_class(self):
1694 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1695 if (no_hyperlinks):
1696 return self.id_serializer_class
1697 else:
1698 return self.serializer_class
1699
1700 def makenew(self, request, *args, **kwargs):
1701 obj = Site()
1702 serializer = self.get_serializer(obj)
1703 return Response(serializer.data)
1704"""
1705
Scott Baker0caeaf02014-06-19 11:12:55 -07001706
1707
1708class SliceRoleList(generics.ListCreateAPIView):
1709 queryset = SliceRole.objects.select_related().all()
1710 serializer_class = SliceRoleSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001711 id_serializer_class = SliceRoleIdSerializer
1712 filter_backends = (filters.DjangoFilterBackend,)
1713 filter_fields = ('id','created','updated','enacted','backend_status','deleted','role',)
1714
1715 def get_serializer_class(self):
1716 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1717 if (no_hyperlinks):
1718 return self.id_serializer_class
1719 else:
1720 return self.serializer_class
1721
Scott Baker0caeaf02014-06-19 11:12:55 -07001722 def get_queryset(self):
1723 return SliceRole.select_by_user(self.request.user)
1724
1725 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08001726 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
1727 if not (serializer.is_valid()):
1728 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
1729 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07001730 obj.caller = request.user
1731 if obj.can_update(request.user):
1732 return super(SliceRoleList, self).create(request, *args, **kwargs)
1733 else:
Scott Baker08898c12014-10-29 23:41:11 -07001734 raise Exception("failed obj.can_update")
1735
1736 ret = super(SliceRoleList, self).create(request, *args, **kwargs)
1737 if (ret.status_code%100 != 200):
1738 raise Exception(ret.data)
1739
1740 return ret
1741
Scott Baker0caeaf02014-06-19 11:12:55 -07001742
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001743class SliceRoleDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001744 queryset = SliceRole.objects.select_related().all()
1745 serializer_class = SliceRoleSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001746 id_serializer_class = SliceRoleIdSerializer
1747
1748 def get_serializer_class(self):
1749 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1750 if (no_hyperlinks):
1751 return self.id_serializer_class
1752 else:
1753 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07001754
1755 def get_queryset(self):
1756 return SliceRole.select_by_user(self.request.user)
1757
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001758 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07001759
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001760 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04001761
Scott Bakerf3816ac2014-11-12 01:13:53 -08001762"""
1763 XXX smbaker: my intent was to create a view that would return 'new' objects
1764 filled with defaults. I solved it another way, so this code may soon be
1765 abandoned.
1766
1767class SliceRoleNew(GenericAPIView):
1768 serializer_class = SliceRoleSerializer
1769 id_serializer_class = SliceRoleIdSerializer
1770
1771 def get(self, request, *args, **kwargs):
1772 return self.makenew(request, *args, **kwargs)
1773
1774 def get_serializer_class(self):
1775 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1776 if (no_hyperlinks):
1777 return self.id_serializer_class
1778 else:
1779 return self.serializer_class
1780
1781 def makenew(self, request, *args, **kwargs):
1782 obj = SliceRole()
1783 serializer = self.get_serializer(obj)
1784 return Response(serializer.data)
1785"""
1786
Sapan Bhatiadea39432014-06-13 03:10:36 -04001787
1788
1789class TagList(generics.ListCreateAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001790 queryset = Tag.objects.select_related().all()
Sapan Bhatiadea39432014-06-13 03:10:36 -04001791 serializer_class = TagSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001792 id_serializer_class = TagIdSerializer
1793 filter_backends = (filters.DjangoFilterBackend,)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001794 filter_fields = ('id','created','updated','enacted','backend_status','deleted','service','name','value','content_type','object_id',)
Scott Baker46b58542014-08-11 17:26:12 -07001795
1796 def get_serializer_class(self):
1797 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1798 if (no_hyperlinks):
1799 return self.id_serializer_class
1800 else:
1801 return self.serializer_class
1802
Scott Baker0caeaf02014-06-19 11:12:55 -07001803 def get_queryset(self):
1804 return Tag.select_by_user(self.request.user)
1805
1806 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08001807 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
1808 if not (serializer.is_valid()):
1809 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
1810 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07001811 obj.caller = request.user
1812 if obj.can_update(request.user):
1813 return super(TagList, self).create(request, *args, **kwargs)
1814 else:
Scott Baker08898c12014-10-29 23:41:11 -07001815 raise Exception("failed obj.can_update")
1816
1817 ret = super(TagList, self).create(request, *args, **kwargs)
1818 if (ret.status_code%100 != 200):
1819 raise Exception(ret.data)
1820
1821 return ret
1822
Sapan Bhatiadea39432014-06-13 03:10:36 -04001823
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001824class TagDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001825 queryset = Tag.objects.select_related().all()
Sapan Bhatiadea39432014-06-13 03:10:36 -04001826 serializer_class = TagSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001827 id_serializer_class = TagIdSerializer
1828
1829 def get_serializer_class(self):
1830 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1831 if (no_hyperlinks):
1832 return self.id_serializer_class
1833 else:
1834 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07001835
1836 def get_queryset(self):
1837 return Tag.select_by_user(self.request.user)
1838
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001839 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07001840
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001841 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04001842
Scott Bakerf3816ac2014-11-12 01:13:53 -08001843"""
1844 XXX smbaker: my intent was to create a view that would return 'new' objects
1845 filled with defaults. I solved it another way, so this code may soon be
1846 abandoned.
1847
1848class TagNew(GenericAPIView):
1849 serializer_class = TagSerializer
1850 id_serializer_class = TagIdSerializer
1851
1852 def get(self, request, *args, **kwargs):
1853 return self.makenew(request, *args, **kwargs)
1854
1855 def get_serializer_class(self):
1856 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1857 if (no_hyperlinks):
1858 return self.id_serializer_class
1859 else:
1860 return self.serializer_class
1861
1862 def makenew(self, request, *args, **kwargs):
1863 obj = Tag()
1864 serializer = self.get_serializer(obj)
1865 return Response(serializer.data)
1866"""
1867
Sapan Bhatiadea39432014-06-13 03:10:36 -04001868
1869
1870class InvoiceList(generics.ListCreateAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001871 queryset = Invoice.objects.select_related().all()
Sapan Bhatiadea39432014-06-13 03:10:36 -04001872 serializer_class = InvoiceSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001873 id_serializer_class = InvoiceIdSerializer
1874 filter_backends = (filters.DjangoFilterBackend,)
1875 filter_fields = ('id','created','updated','enacted','backend_status','deleted','date','account',)
1876
1877 def get_serializer_class(self):
1878 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1879 if (no_hyperlinks):
1880 return self.id_serializer_class
1881 else:
1882 return self.serializer_class
1883
Scott Baker0caeaf02014-06-19 11:12:55 -07001884 def get_queryset(self):
1885 return Invoice.select_by_user(self.request.user)
1886
1887 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08001888 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
1889 if not (serializer.is_valid()):
1890 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
1891 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07001892 obj.caller = request.user
1893 if obj.can_update(request.user):
1894 return super(InvoiceList, self).create(request, *args, **kwargs)
1895 else:
Scott Baker08898c12014-10-29 23:41:11 -07001896 raise Exception("failed obj.can_update")
1897
1898 ret = super(InvoiceList, self).create(request, *args, **kwargs)
1899 if (ret.status_code%100 != 200):
1900 raise Exception(ret.data)
1901
1902 return ret
1903
Sapan Bhatiadea39432014-06-13 03:10:36 -04001904
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001905class InvoiceDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001906 queryset = Invoice.objects.select_related().all()
Sapan Bhatiadea39432014-06-13 03:10:36 -04001907 serializer_class = InvoiceSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001908 id_serializer_class = InvoiceIdSerializer
1909
1910 def get_serializer_class(self):
1911 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1912 if (no_hyperlinks):
1913 return self.id_serializer_class
1914 else:
1915 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07001916
1917 def get_queryset(self):
1918 return Invoice.select_by_user(self.request.user)
1919
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001920 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07001921
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001922 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04001923
Scott Bakerf3816ac2014-11-12 01:13:53 -08001924"""
1925 XXX smbaker: my intent was to create a view that would return 'new' objects
1926 filled with defaults. I solved it another way, so this code may soon be
1927 abandoned.
1928
1929class InvoiceNew(GenericAPIView):
1930 serializer_class = InvoiceSerializer
1931 id_serializer_class = InvoiceIdSerializer
1932
1933 def get(self, request, *args, **kwargs):
1934 return self.makenew(request, *args, **kwargs)
1935
1936 def get_serializer_class(self):
1937 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1938 if (no_hyperlinks):
1939 return self.id_serializer_class
1940 else:
1941 return self.serializer_class
1942
1943 def makenew(self, request, *args, **kwargs):
1944 obj = Invoice()
1945 serializer = self.get_serializer(obj)
1946 return Response(serializer.data)
1947"""
1948
Sapan Bhatiadea39432014-06-13 03:10:36 -04001949
1950
Scott Baker0caeaf02014-06-19 11:12:55 -07001951class SlicePrivilegeList(generics.ListCreateAPIView):
1952 queryset = SlicePrivilege.objects.select_related().all()
1953 serializer_class = SlicePrivilegeSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001954 id_serializer_class = SlicePrivilegeIdSerializer
1955 filter_backends = (filters.DjangoFilterBackend,)
1956 filter_fields = ('id','created','updated','enacted','backend_status','deleted','user','slice','role',)
1957
1958 def get_serializer_class(self):
1959 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1960 if (no_hyperlinks):
1961 return self.id_serializer_class
1962 else:
1963 return self.serializer_class
1964
Scott Baker0caeaf02014-06-19 11:12:55 -07001965 def get_queryset(self):
1966 return SlicePrivilege.select_by_user(self.request.user)
Sapan Bhatiadea39432014-06-13 03:10:36 -04001967
Scott Baker0caeaf02014-06-19 11:12:55 -07001968 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08001969 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
1970 if not (serializer.is_valid()):
1971 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
1972 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07001973 obj.caller = request.user
1974 if obj.can_update(request.user):
1975 return super(SlicePrivilegeList, self).create(request, *args, **kwargs)
1976 else:
Scott Baker08898c12014-10-29 23:41:11 -07001977 raise Exception("failed obj.can_update")
1978
1979 ret = super(SlicePrivilegeList, self).create(request, *args, **kwargs)
1980 if (ret.status_code%100 != 200):
1981 raise Exception(ret.data)
1982
1983 return ret
1984
Scott Baker0caeaf02014-06-19 11:12:55 -07001985
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07001986class SlicePrivilegeDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07001987 queryset = SlicePrivilege.objects.select_related().all()
1988 serializer_class = SlicePrivilegeSerializer
Scott Baker46b58542014-08-11 17:26:12 -07001989 id_serializer_class = SlicePrivilegeIdSerializer
1990
1991 def get_serializer_class(self):
1992 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
1993 if (no_hyperlinks):
1994 return self.id_serializer_class
1995 else:
1996 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07001997
1998 def get_queryset(self):
1999 return SlicePrivilege.select_by_user(self.request.user)
2000
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002001 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2002
2003 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2004
Scott Bakerf3816ac2014-11-12 01:13:53 -08002005"""
2006 XXX smbaker: my intent was to create a view that would return 'new' objects
2007 filled with defaults. I solved it another way, so this code may soon be
2008 abandoned.
2009
2010class SlicePrivilegeNew(GenericAPIView):
2011 serializer_class = SlicePrivilegeSerializer
2012 id_serializer_class = SlicePrivilegeIdSerializer
2013
2014 def get(self, request, *args, **kwargs):
2015 return self.makenew(request, *args, **kwargs)
2016
2017 def get_serializer_class(self):
2018 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2019 if (no_hyperlinks):
2020 return self.id_serializer_class
2021 else:
2022 return self.serializer_class
2023
2024 def makenew(self, request, *args, **kwargs):
2025 obj = SlicePrivilege()
2026 serializer = self.get_serializer(obj)
2027 return Response(serializer.data)
2028"""
2029
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002030
2031
2032class PlanetStackRoleList(generics.ListCreateAPIView):
2033 queryset = PlanetStackRole.objects.select_related().all()
2034 serializer_class = PlanetStackRoleSerializer
2035 id_serializer_class = PlanetStackRoleIdSerializer
2036 filter_backends = (filters.DjangoFilterBackend,)
2037 filter_fields = ('id','created','updated','enacted','backend_status','deleted','role',)
2038
2039 def get_serializer_class(self):
2040 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2041 if (no_hyperlinks):
2042 return self.id_serializer_class
2043 else:
2044 return self.serializer_class
2045
2046 def get_queryset(self):
2047 return PlanetStackRole.select_by_user(self.request.user)
2048
2049 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002050 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2051 if not (serializer.is_valid()):
2052 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2053 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002054 obj.caller = request.user
Scott Baker0caeaf02014-06-19 11:12:55 -07002055 if obj.can_update(request.user):
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002056 return super(PlanetStackRoleList, self).create(request, *args, **kwargs)
Scott Baker0caeaf02014-06-19 11:12:55 -07002057 else:
Scott Baker08898c12014-10-29 23:41:11 -07002058 raise Exception("failed obj.can_update")
2059
2060 ret = super(PlanetStackRoleList, self).create(request, *args, **kwargs)
2061 if (ret.status_code%100 != 200):
2062 raise Exception(ret.data)
2063
2064 return ret
2065
Scott Baker0caeaf02014-06-19 11:12:55 -07002066
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002067class PlanetStackRoleDetail(PlanetStackRetrieveUpdateDestroyAPIView):
2068 queryset = PlanetStackRole.objects.select_related().all()
2069 serializer_class = PlanetStackRoleSerializer
2070 id_serializer_class = PlanetStackRoleIdSerializer
2071
2072 def get_serializer_class(self):
2073 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2074 if (no_hyperlinks):
2075 return self.id_serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07002076 else:
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002077 return self.serializer_class
2078
2079 def get_queryset(self):
2080 return PlanetStackRole.select_by_user(self.request.user)
2081
2082 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2083
2084 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04002085
Scott Bakerf3816ac2014-11-12 01:13:53 -08002086"""
2087 XXX smbaker: my intent was to create a view that would return 'new' objects
2088 filled with defaults. I solved it another way, so this code may soon be
2089 abandoned.
2090
2091class PlanetStackRoleNew(GenericAPIView):
2092 serializer_class = PlanetStackRoleSerializer
2093 id_serializer_class = PlanetStackRoleIdSerializer
2094
2095 def get(self, request, *args, **kwargs):
2096 return self.makenew(request, *args, **kwargs)
2097
2098 def get_serializer_class(self):
2099 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2100 if (no_hyperlinks):
2101 return self.id_serializer_class
2102 else:
2103 return self.serializer_class
2104
2105 def makenew(self, request, *args, **kwargs):
2106 obj = PlanetStackRole()
2107 serializer = self.get_serializer(obj)
2108 return Response(serializer.data)
2109"""
2110
Sapan Bhatiadea39432014-06-13 03:10:36 -04002111
2112
Scott Baker0caeaf02014-06-19 11:12:55 -07002113class NetworkSliverList(generics.ListCreateAPIView):
2114 queryset = NetworkSliver.objects.select_related().all()
2115 serializer_class = NetworkSliverSerializer
Scott Baker46b58542014-08-11 17:26:12 -07002116 id_serializer_class = NetworkSliverIdSerializer
2117 filter_backends = (filters.DjangoFilterBackend,)
2118 filter_fields = ('id','created','updated','enacted','backend_status','deleted','network','sliver','ip','port_id',)
2119
2120 def get_serializer_class(self):
2121 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2122 if (no_hyperlinks):
2123 return self.id_serializer_class
2124 else:
2125 return self.serializer_class
2126
Scott Baker0caeaf02014-06-19 11:12:55 -07002127 def get_queryset(self):
2128 return NetworkSliver.select_by_user(self.request.user)
Sapan Bhatiadea39432014-06-13 03:10:36 -04002129
Scott Baker0caeaf02014-06-19 11:12:55 -07002130 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002131 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2132 if not (serializer.is_valid()):
2133 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2134 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07002135 obj.caller = request.user
2136 if obj.can_update(request.user):
2137 return super(NetworkSliverList, self).create(request, *args, **kwargs)
2138 else:
Scott Baker08898c12014-10-29 23:41:11 -07002139 raise Exception("failed obj.can_update")
2140
2141 ret = super(NetworkSliverList, self).create(request, *args, **kwargs)
2142 if (ret.status_code%100 != 200):
2143 raise Exception(ret.data)
2144
2145 return ret
2146
Scott Baker0caeaf02014-06-19 11:12:55 -07002147
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002148class NetworkSliverDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07002149 queryset = NetworkSliver.objects.select_related().all()
2150 serializer_class = NetworkSliverSerializer
Scott Baker46b58542014-08-11 17:26:12 -07002151 id_serializer_class = NetworkSliverIdSerializer
2152
2153 def get_serializer_class(self):
2154 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2155 if (no_hyperlinks):
2156 return self.id_serializer_class
2157 else:
2158 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07002159
2160 def get_queryset(self):
2161 return NetworkSliver.select_by_user(self.request.user)
2162
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002163 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07002164
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002165 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04002166
Scott Bakerf3816ac2014-11-12 01:13:53 -08002167"""
2168 XXX smbaker: my intent was to create a view that would return 'new' objects
2169 filled with defaults. I solved it another way, so this code may soon be
2170 abandoned.
2171
2172class NetworkSliverNew(GenericAPIView):
2173 serializer_class = NetworkSliverSerializer
2174 id_serializer_class = NetworkSliverIdSerializer
2175
2176 def get(self, request, *args, **kwargs):
2177 return self.makenew(request, *args, **kwargs)
2178
2179 def get_serializer_class(self):
2180 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2181 if (no_hyperlinks):
2182 return self.id_serializer_class
2183 else:
2184 return self.serializer_class
2185
2186 def makenew(self, request, *args, **kwargs):
2187 obj = NetworkSliver()
2188 serializer = self.get_serializer(obj)
2189 return Response(serializer.data)
2190"""
2191
Sapan Bhatiadea39432014-06-13 03:10:36 -04002192
2193
Scott Baker0caeaf02014-06-19 11:12:55 -07002194class NetworkDeploymentsList(generics.ListCreateAPIView):
2195 queryset = NetworkDeployments.objects.select_related().all()
2196 serializer_class = NetworkDeploymentsSerializer
Scott Baker46b58542014-08-11 17:26:12 -07002197 id_serializer_class = NetworkDeploymentsIdSerializer
2198 filter_backends = (filters.DjangoFilterBackend,)
2199 filter_fields = ('id','created','updated','enacted','backend_status','deleted','network','deployment','net_id','router_id','subnet_id','subnet',)
2200
2201 def get_serializer_class(self):
2202 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2203 if (no_hyperlinks):
2204 return self.id_serializer_class
2205 else:
2206 return self.serializer_class
2207
Scott Baker0caeaf02014-06-19 11:12:55 -07002208 def get_queryset(self):
2209 return NetworkDeployments.select_by_user(self.request.user)
Sapan Bhatiadea39432014-06-13 03:10:36 -04002210
Scott Baker0caeaf02014-06-19 11:12:55 -07002211 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002212 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2213 if not (serializer.is_valid()):
2214 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2215 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07002216 obj.caller = request.user
2217 if obj.can_update(request.user):
2218 return super(NetworkDeploymentsList, self).create(request, *args, **kwargs)
2219 else:
Scott Baker08898c12014-10-29 23:41:11 -07002220 raise Exception("failed obj.can_update")
2221
2222 ret = super(NetworkDeploymentsList, self).create(request, *args, **kwargs)
2223 if (ret.status_code%100 != 200):
2224 raise Exception(ret.data)
2225
2226 return ret
2227
Scott Baker0caeaf02014-06-19 11:12:55 -07002228
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002229class NetworkDeploymentsDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07002230 queryset = NetworkDeployments.objects.select_related().all()
2231 serializer_class = NetworkDeploymentsSerializer
Scott Baker46b58542014-08-11 17:26:12 -07002232 id_serializer_class = NetworkDeploymentsIdSerializer
2233
2234 def get_serializer_class(self):
2235 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2236 if (no_hyperlinks):
2237 return self.id_serializer_class
2238 else:
2239 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07002240
2241 def get_queryset(self):
2242 return NetworkDeployments.select_by_user(self.request.user)
2243
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002244 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07002245
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002246 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04002247
Scott Bakerf3816ac2014-11-12 01:13:53 -08002248"""
2249 XXX smbaker: my intent was to create a view that would return 'new' objects
2250 filled with defaults. I solved it another way, so this code may soon be
2251 abandoned.
2252
2253class NetworkDeploymentsNew(GenericAPIView):
2254 serializer_class = NetworkDeploymentsSerializer
2255 id_serializer_class = NetworkDeploymentsIdSerializer
2256
2257 def get(self, request, *args, **kwargs):
2258 return self.makenew(request, *args, **kwargs)
2259
2260 def get_serializer_class(self):
2261 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2262 if (no_hyperlinks):
2263 return self.id_serializer_class
2264 else:
2265 return self.serializer_class
2266
2267 def makenew(self, request, *args, **kwargs):
2268 obj = NetworkDeployments()
2269 serializer = self.get_serializer(obj)
2270 return Response(serializer.data)
2271"""
2272
Sapan Bhatiadea39432014-06-13 03:10:36 -04002273
2274
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002275class FlavorList(generics.ListCreateAPIView):
2276 queryset = Flavor.objects.select_related().all()
2277 serializer_class = FlavorSerializer
2278 id_serializer_class = FlavorIdSerializer
Scott Baker46b58542014-08-11 17:26:12 -07002279 filter_backends = (filters.DjangoFilterBackend,)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002280 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','description','flavor','order','default',)
Scott Baker46b58542014-08-11 17:26:12 -07002281
2282 def get_serializer_class(self):
2283 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2284 if (no_hyperlinks):
2285 return self.id_serializer_class
2286 else:
2287 return self.serializer_class
2288
Scott Baker0caeaf02014-06-19 11:12:55 -07002289 def get_queryset(self):
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002290 return Flavor.select_by_user(self.request.user)
Scott Baker0caeaf02014-06-19 11:12:55 -07002291
2292 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002293 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2294 if not (serializer.is_valid()):
2295 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2296 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07002297 obj.caller = request.user
2298 if obj.can_update(request.user):
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002299 return super(FlavorList, self).create(request, *args, **kwargs)
Scott Baker0caeaf02014-06-19 11:12:55 -07002300 else:
Scott Baker08898c12014-10-29 23:41:11 -07002301 raise Exception("failed obj.can_update")
2302
2303 ret = super(FlavorList, self).create(request, *args, **kwargs)
2304 if (ret.status_code%100 != 200):
2305 raise Exception(ret.data)
2306
2307 return ret
2308
Sapan Bhatiadea39432014-06-13 03:10:36 -04002309
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002310class FlavorDetail(PlanetStackRetrieveUpdateDestroyAPIView):
2311 queryset = Flavor.objects.select_related().all()
2312 serializer_class = FlavorSerializer
2313 id_serializer_class = FlavorIdSerializer
Scott Baker46b58542014-08-11 17:26:12 -07002314
2315 def get_serializer_class(self):
2316 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2317 if (no_hyperlinks):
2318 return self.id_serializer_class
2319 else:
2320 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07002321
2322 def get_queryset(self):
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002323 return Flavor.select_by_user(self.request.user)
Scott Baker0caeaf02014-06-19 11:12:55 -07002324
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002325 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07002326
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002327 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04002328
Scott Bakerf3816ac2014-11-12 01:13:53 -08002329"""
2330 XXX smbaker: my intent was to create a view that would return 'new' objects
2331 filled with defaults. I solved it another way, so this code may soon be
2332 abandoned.
2333
2334class FlavorNew(GenericAPIView):
2335 serializer_class = FlavorSerializer
2336 id_serializer_class = FlavorIdSerializer
2337
2338 def get(self, request, *args, **kwargs):
2339 return self.makenew(request, *args, **kwargs)
2340
2341 def get_serializer_class(self):
2342 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2343 if (no_hyperlinks):
2344 return self.id_serializer_class
2345 else:
2346 return self.serializer_class
2347
2348 def makenew(self, request, *args, **kwargs):
2349 obj = Flavor()
2350 serializer = self.get_serializer(obj)
2351 return Response(serializer.data)
2352"""
2353
Sapan Bhatiadea39432014-06-13 03:10:36 -04002354
2355
Scott Baker0caeaf02014-06-19 11:12:55 -07002356class ProjectList(generics.ListCreateAPIView):
2357 queryset = Project.objects.select_related().all()
2358 serializer_class = ProjectSerializer
Scott Baker46b58542014-08-11 17:26:12 -07002359 id_serializer_class = ProjectIdSerializer
2360 filter_backends = (filters.DjangoFilterBackend,)
2361 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name',)
2362
2363 def get_serializer_class(self):
2364 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2365 if (no_hyperlinks):
2366 return self.id_serializer_class
2367 else:
2368 return self.serializer_class
2369
Scott Baker0caeaf02014-06-19 11:12:55 -07002370 def get_queryset(self):
2371 return Project.select_by_user(self.request.user)
Sapan Bhatiadea39432014-06-13 03:10:36 -04002372
Scott Baker0caeaf02014-06-19 11:12:55 -07002373 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002374 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2375 if not (serializer.is_valid()):
2376 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2377 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07002378 obj.caller = request.user
2379 if obj.can_update(request.user):
2380 return super(ProjectList, self).create(request, *args, **kwargs)
2381 else:
Scott Baker08898c12014-10-29 23:41:11 -07002382 raise Exception("failed obj.can_update")
2383
2384 ret = super(ProjectList, self).create(request, *args, **kwargs)
2385 if (ret.status_code%100 != 200):
2386 raise Exception(ret.data)
2387
2388 return ret
2389
Scott Baker0caeaf02014-06-19 11:12:55 -07002390
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002391class ProjectDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07002392 queryset = Project.objects.select_related().all()
2393 serializer_class = ProjectSerializer
Scott Baker46b58542014-08-11 17:26:12 -07002394 id_serializer_class = ProjectIdSerializer
2395
2396 def get_serializer_class(self):
2397 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2398 if (no_hyperlinks):
2399 return self.id_serializer_class
2400 else:
2401 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07002402
2403 def get_queryset(self):
2404 return Project.select_by_user(self.request.user)
2405
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002406 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2407
2408 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2409
Scott Bakerf3816ac2014-11-12 01:13:53 -08002410"""
2411 XXX smbaker: my intent was to create a view that would return 'new' objects
2412 filled with defaults. I solved it another way, so this code may soon be
2413 abandoned.
2414
2415class ProjectNew(GenericAPIView):
2416 serializer_class = ProjectSerializer
2417 id_serializer_class = ProjectIdSerializer
2418
2419 def get(self, request, *args, **kwargs):
2420 return self.makenew(request, *args, **kwargs)
2421
2422 def get_serializer_class(self):
2423 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2424 if (no_hyperlinks):
2425 return self.id_serializer_class
2426 else:
2427 return self.serializer_class
2428
2429 def makenew(self, request, *args, **kwargs):
2430 obj = Project()
2431 serializer = self.get_serializer(obj)
2432 return Response(serializer.data)
2433"""
2434
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002435
2436
2437class SliceList(generics.ListCreateAPIView):
2438 queryset = Slice.objects.select_related().all()
2439 serializer_class = SliceSerializer
2440 id_serializer_class = SliceIdSerializer
2441 filter_backends = (filters.DjangoFilterBackend,)
2442 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','imagePreference','service','network','mountDataSets','serviceClass','creator','networks','availableNetworks','networks','networks',)
2443
2444 def get_serializer_class(self):
2445 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2446 if (no_hyperlinks):
2447 return self.id_serializer_class
2448 else:
2449 return self.serializer_class
2450
2451 def get_queryset(self):
2452 return Slice.select_by_user(self.request.user)
2453
2454 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002455 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2456 if not (serializer.is_valid()):
2457 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2458 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002459 obj.caller = request.user
Scott Baker0caeaf02014-06-19 11:12:55 -07002460 if obj.can_update(request.user):
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002461 return super(SliceList, self).create(request, *args, **kwargs)
Scott Baker0caeaf02014-06-19 11:12:55 -07002462 else:
Scott Baker08898c12014-10-29 23:41:11 -07002463 raise Exception("failed obj.can_update")
2464
2465 ret = super(SliceList, self).create(request, *args, **kwargs)
2466 if (ret.status_code%100 != 200):
2467 raise Exception(ret.data)
2468
2469 return ret
2470
Scott Baker0caeaf02014-06-19 11:12:55 -07002471
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002472class SliceDetail(PlanetStackRetrieveUpdateDestroyAPIView):
2473 queryset = Slice.objects.select_related().all()
2474 serializer_class = SliceSerializer
2475 id_serializer_class = SliceIdSerializer
2476
2477 def get_serializer_class(self):
2478 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2479 if (no_hyperlinks):
2480 return self.id_serializer_class
2481 else:
2482 return self.serializer_class
2483
2484 def get_queryset(self):
2485 return Slice.select_by_user(self.request.user)
2486
2487 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2488
2489 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2490
Scott Bakerf3816ac2014-11-12 01:13:53 -08002491"""
2492 XXX smbaker: my intent was to create a view that would return 'new' objects
2493 filled with defaults. I solved it another way, so this code may soon be
2494 abandoned.
2495
2496class SliceNew(GenericAPIView):
2497 serializer_class = SliceSerializer
2498 id_serializer_class = SliceIdSerializer
2499
2500 def get(self, request, *args, **kwargs):
2501 return self.makenew(request, *args, **kwargs)
2502
2503 def get_serializer_class(self):
2504 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2505 if (no_hyperlinks):
2506 return self.id_serializer_class
2507 else:
2508 return self.serializer_class
2509
2510 def makenew(self, request, *args, **kwargs):
2511 obj = Slice()
2512 serializer = self.get_serializer(obj)
2513 return Response(serializer.data)
2514"""
2515
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002516
2517
2518class NetworkList(generics.ListCreateAPIView):
2519 queryset = Network.objects.select_related().all()
2520 serializer_class = NetworkSerializer
2521 id_serializer_class = NetworkIdSerializer
2522 filter_backends = (filters.DjangoFilterBackend,)
Scott Baker645dc9d2014-11-17 22:32:19 -08002523 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','template','subnet','ports','labels','owner','guaranteedBandwidth','permitAllSlices','topologyParameters','controllerUrl','controllerParameters','network_id','router_id','subnet_id','routers','availableRouters','routers','routers',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002524
2525 def get_serializer_class(self):
2526 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2527 if (no_hyperlinks):
2528 return self.id_serializer_class
2529 else:
2530 return self.serializer_class
2531
2532 def get_queryset(self):
2533 return Network.select_by_user(self.request.user)
2534
2535 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002536 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2537 if not (serializer.is_valid()):
2538 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2539 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002540 obj.caller = request.user
Scott Baker0caeaf02014-06-19 11:12:55 -07002541 if obj.can_update(request.user):
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002542 return super(NetworkList, self).create(request, *args, **kwargs)
Scott Baker0caeaf02014-06-19 11:12:55 -07002543 else:
Scott Baker08898c12014-10-29 23:41:11 -07002544 raise Exception("failed obj.can_update")
2545
2546 ret = super(NetworkList, self).create(request, *args, **kwargs)
2547 if (ret.status_code%100 != 200):
2548 raise Exception(ret.data)
2549
2550 return ret
2551
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002552
2553class NetworkDetail(PlanetStackRetrieveUpdateDestroyAPIView):
2554 queryset = Network.objects.select_related().all()
2555 serializer_class = NetworkSerializer
2556 id_serializer_class = NetworkIdSerializer
2557
2558 def get_serializer_class(self):
2559 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2560 if (no_hyperlinks):
2561 return self.id_serializer_class
2562 else:
2563 return self.serializer_class
2564
2565 def get_queryset(self):
2566 return Network.select_by_user(self.request.user)
2567
2568 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2569
2570 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2571
Scott Bakerf3816ac2014-11-12 01:13:53 -08002572"""
2573 XXX smbaker: my intent was to create a view that would return 'new' objects
2574 filled with defaults. I solved it another way, so this code may soon be
2575 abandoned.
2576
2577class NetworkNew(GenericAPIView):
2578 serializer_class = NetworkSerializer
2579 id_serializer_class = NetworkIdSerializer
2580
2581 def get(self, request, *args, **kwargs):
2582 return self.makenew(request, *args, **kwargs)
2583
2584 def get_serializer_class(self):
2585 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2586 if (no_hyperlinks):
2587 return self.id_serializer_class
2588 else:
2589 return self.serializer_class
2590
2591 def makenew(self, request, *args, **kwargs):
2592 obj = Network()
2593 serializer = self.get_serializer(obj)
2594 return Response(serializer.data)
2595"""
2596
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002597
2598
2599class ServiceList(generics.ListCreateAPIView):
2600 queryset = Service.objects.select_related().all()
2601 serializer_class = ServiceSerializer
2602 id_serializer_class = ServiceIdSerializer
2603 filter_backends = (filters.DjangoFilterBackend,)
2604 filter_fields = ('id','created','updated','enacted','backend_status','deleted','description','enabled','name','versionNumber','published',)
2605
2606 def get_serializer_class(self):
2607 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2608 if (no_hyperlinks):
2609 return self.id_serializer_class
2610 else:
2611 return self.serializer_class
2612
2613 def get_queryset(self):
2614 return Service.select_by_user(self.request.user)
2615
2616 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002617 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2618 if not (serializer.is_valid()):
2619 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2620 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002621 obj.caller = request.user
2622 if obj.can_update(request.user):
2623 return super(ServiceList, self).create(request, *args, **kwargs)
2624 else:
Scott Baker08898c12014-10-29 23:41:11 -07002625 raise Exception("failed obj.can_update")
2626
2627 ret = super(ServiceList, self).create(request, *args, **kwargs)
2628 if (ret.status_code%100 != 200):
2629 raise Exception(ret.data)
2630
2631 return ret
2632
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002633
2634class ServiceDetail(PlanetStackRetrieveUpdateDestroyAPIView):
2635 queryset = Service.objects.select_related().all()
2636 serializer_class = ServiceSerializer
2637 id_serializer_class = ServiceIdSerializer
2638
2639 def get_serializer_class(self):
2640 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2641 if (no_hyperlinks):
2642 return self.id_serializer_class
2643 else:
2644 return self.serializer_class
2645
2646 def get_queryset(self):
2647 return Service.select_by_user(self.request.user)
2648
2649 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2650
2651 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2652
Scott Bakerf3816ac2014-11-12 01:13:53 -08002653"""
2654 XXX smbaker: my intent was to create a view that would return 'new' objects
2655 filled with defaults. I solved it another way, so this code may soon be
2656 abandoned.
2657
2658class ServiceNew(GenericAPIView):
2659 serializer_class = ServiceSerializer
2660 id_serializer_class = ServiceIdSerializer
2661
2662 def get(self, request, *args, **kwargs):
2663 return self.makenew(request, *args, **kwargs)
2664
2665 def get_serializer_class(self):
2666 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2667 if (no_hyperlinks):
2668 return self.id_serializer_class
2669 else:
2670 return self.serializer_class
2671
2672 def makenew(self, request, *args, **kwargs):
2673 obj = Service()
2674 serializer = self.get_serializer(obj)
2675 return Response(serializer.data)
2676"""
2677
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002678
2679
2680class ServiceClassList(generics.ListCreateAPIView):
2681 queryset = ServiceClass.objects.select_related().all()
2682 serializer_class = ServiceClassSerializer
2683 id_serializer_class = ServiceClassIdSerializer
2684 filter_backends = (filters.DjangoFilterBackend,)
2685 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','description','commitment','membershipFee','membershipFeeMonths','upgradeRequiresApproval',)
2686
2687 def get_serializer_class(self):
2688 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2689 if (no_hyperlinks):
2690 return self.id_serializer_class
2691 else:
2692 return self.serializer_class
2693
2694 def get_queryset(self):
2695 return ServiceClass.select_by_user(self.request.user)
2696
2697 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002698 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2699 if not (serializer.is_valid()):
2700 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2701 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002702 obj.caller = request.user
2703 if obj.can_update(request.user):
2704 return super(ServiceClassList, self).create(request, *args, **kwargs)
2705 else:
Scott Baker08898c12014-10-29 23:41:11 -07002706 raise Exception("failed obj.can_update")
2707
2708 ret = super(ServiceClassList, self).create(request, *args, **kwargs)
2709 if (ret.status_code%100 != 200):
2710 raise Exception(ret.data)
2711
2712 return ret
2713
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002714
2715class ServiceClassDetail(PlanetStackRetrieveUpdateDestroyAPIView):
2716 queryset = ServiceClass.objects.select_related().all()
2717 serializer_class = ServiceClassSerializer
2718 id_serializer_class = ServiceClassIdSerializer
2719
2720 def get_serializer_class(self):
2721 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2722 if (no_hyperlinks):
2723 return self.id_serializer_class
2724 else:
2725 return self.serializer_class
2726
2727 def get_queryset(self):
2728 return ServiceClass.select_by_user(self.request.user)
2729
2730 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2731
2732 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2733
Scott Bakerf3816ac2014-11-12 01:13:53 -08002734"""
2735 XXX smbaker: my intent was to create a view that would return 'new' objects
2736 filled with defaults. I solved it another way, so this code may soon be
2737 abandoned.
2738
2739class ServiceClassNew(GenericAPIView):
2740 serializer_class = ServiceClassSerializer
2741 id_serializer_class = ServiceClassIdSerializer
2742
2743 def get(self, request, *args, **kwargs):
2744 return self.makenew(request, *args, **kwargs)
2745
2746 def get_serializer_class(self):
2747 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2748 if (no_hyperlinks):
2749 return self.id_serializer_class
2750 else:
2751 return self.serializer_class
2752
2753 def makenew(self, request, *args, **kwargs):
2754 obj = ServiceClass()
2755 serializer = self.get_serializer(obj)
2756 return Response(serializer.data)
2757"""
2758
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002759
2760
Scott Baker645dc9d2014-11-17 22:32:19 -08002761class PlanetStackList(generics.ListCreateAPIView):
2762 queryset = PlanetStack.objects.select_related().all()
2763 serializer_class = PlanetStackSerializer
2764 id_serializer_class = PlanetStackIdSerializer
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002765 filter_backends = (filters.DjangoFilterBackend,)
Scott Baker645dc9d2014-11-17 22:32:19 -08002766 filter_fields = ('id','created','updated','enacted','backend_status','deleted','description',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002767
2768 def get_serializer_class(self):
2769 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2770 if (no_hyperlinks):
2771 return self.id_serializer_class
2772 else:
2773 return self.serializer_class
2774
2775 def get_queryset(self):
Scott Baker645dc9d2014-11-17 22:32:19 -08002776 return PlanetStack.select_by_user(self.request.user)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002777
2778 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002779 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2780 if not (serializer.is_valid()):
2781 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2782 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002783 obj.caller = request.user
2784 if obj.can_update(request.user):
Scott Baker645dc9d2014-11-17 22:32:19 -08002785 return super(PlanetStackList, self).create(request, *args, **kwargs)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002786 else:
Scott Baker08898c12014-10-29 23:41:11 -07002787 raise Exception("failed obj.can_update")
2788
Scott Baker645dc9d2014-11-17 22:32:19 -08002789 ret = super(PlanetStackList, self).create(request, *args, **kwargs)
Scott Baker08898c12014-10-29 23:41:11 -07002790 if (ret.status_code%100 != 200):
2791 raise Exception(ret.data)
2792
2793 return ret
2794
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002795
Scott Baker645dc9d2014-11-17 22:32:19 -08002796class PlanetStackDetail(PlanetStackRetrieveUpdateDestroyAPIView):
2797 queryset = PlanetStack.objects.select_related().all()
2798 serializer_class = PlanetStackSerializer
2799 id_serializer_class = PlanetStackIdSerializer
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002800
2801 def get_serializer_class(self):
2802 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2803 if (no_hyperlinks):
2804 return self.id_serializer_class
2805 else:
2806 return self.serializer_class
2807
2808 def get_queryset(self):
Scott Baker645dc9d2014-11-17 22:32:19 -08002809 return PlanetStack.select_by_user(self.request.user)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002810
2811 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2812
2813 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2814
Scott Bakerf3816ac2014-11-12 01:13:53 -08002815"""
2816 XXX smbaker: my intent was to create a view that would return 'new' objects
2817 filled with defaults. I solved it another way, so this code may soon be
2818 abandoned.
2819
Scott Baker645dc9d2014-11-17 22:32:19 -08002820class PlanetStackNew(GenericAPIView):
2821 serializer_class = PlanetStackSerializer
2822 id_serializer_class = PlanetStackIdSerializer
Scott Bakerf3816ac2014-11-12 01:13:53 -08002823
2824 def get(self, request, *args, **kwargs):
2825 return self.makenew(request, *args, **kwargs)
2826
2827 def get_serializer_class(self):
2828 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2829 if (no_hyperlinks):
2830 return self.id_serializer_class
2831 else:
2832 return self.serializer_class
2833
2834 def makenew(self, request, *args, **kwargs):
Scott Baker645dc9d2014-11-17 22:32:19 -08002835 obj = PlanetStack()
Scott Bakerf3816ac2014-11-12 01:13:53 -08002836 serializer = self.get_serializer(obj)
2837 return Response(serializer.data)
2838"""
2839
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002840
2841
2842class ChargeList(generics.ListCreateAPIView):
2843 queryset = Charge.objects.select_related().all()
2844 serializer_class = ChargeSerializer
2845 id_serializer_class = ChargeIdSerializer
2846 filter_backends = (filters.DjangoFilterBackend,)
2847 filter_fields = ('id','created','updated','enacted','backend_status','deleted','account','slice','kind','state','date','object','amount','coreHours','invoice',)
2848
2849 def get_serializer_class(self):
2850 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2851 if (no_hyperlinks):
2852 return self.id_serializer_class
2853 else:
2854 return self.serializer_class
2855
2856 def get_queryset(self):
2857 return Charge.select_by_user(self.request.user)
2858
2859 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002860 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2861 if not (serializer.is_valid()):
2862 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2863 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002864 obj.caller = request.user
2865 if obj.can_update(request.user):
2866 return super(ChargeList, self).create(request, *args, **kwargs)
2867 else:
Scott Baker08898c12014-10-29 23:41:11 -07002868 raise Exception("failed obj.can_update")
2869
2870 ret = super(ChargeList, self).create(request, *args, **kwargs)
2871 if (ret.status_code%100 != 200):
2872 raise Exception(ret.data)
2873
2874 return ret
2875
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002876
2877class ChargeDetail(PlanetStackRetrieveUpdateDestroyAPIView):
2878 queryset = Charge.objects.select_related().all()
2879 serializer_class = ChargeSerializer
2880 id_serializer_class = ChargeIdSerializer
2881
2882 def get_serializer_class(self):
2883 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2884 if (no_hyperlinks):
2885 return self.id_serializer_class
2886 else:
2887 return self.serializer_class
2888
2889 def get_queryset(self):
2890 return Charge.select_by_user(self.request.user)
2891
2892 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2893
2894 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2895
Scott Bakerf3816ac2014-11-12 01:13:53 -08002896"""
2897 XXX smbaker: my intent was to create a view that would return 'new' objects
2898 filled with defaults. I solved it another way, so this code may soon be
2899 abandoned.
2900
2901class ChargeNew(GenericAPIView):
2902 serializer_class = ChargeSerializer
2903 id_serializer_class = ChargeIdSerializer
2904
2905 def get(self, request, *args, **kwargs):
2906 return self.makenew(request, *args, **kwargs)
2907
2908 def get_serializer_class(self):
2909 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2910 if (no_hyperlinks):
2911 return self.id_serializer_class
2912 else:
2913 return self.serializer_class
2914
2915 def makenew(self, request, *args, **kwargs):
2916 obj = Charge()
2917 serializer = self.get_serializer(obj)
2918 return Response(serializer.data)
2919"""
2920
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002921
2922
2923class RoleList(generics.ListCreateAPIView):
2924 queryset = Role.objects.select_related().all()
2925 serializer_class = RoleSerializer
2926 id_serializer_class = RoleIdSerializer
2927 filter_backends = (filters.DjangoFilterBackend,)
2928 filter_fields = ('id','created','updated','enacted','backend_status','deleted','role_type','role','description','content_type',)
2929
2930 def get_serializer_class(self):
2931 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2932 if (no_hyperlinks):
2933 return self.id_serializer_class
2934 else:
2935 return self.serializer_class
2936
2937 def get_queryset(self):
2938 return Role.select_by_user(self.request.user)
2939
2940 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08002941 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
2942 if not (serializer.is_valid()):
2943 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
2944 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002945 obj.caller = request.user
2946 if obj.can_update(request.user):
2947 return super(RoleList, self).create(request, *args, **kwargs)
2948 else:
Scott Baker08898c12014-10-29 23:41:11 -07002949 raise Exception("failed obj.can_update")
2950
2951 ret = super(RoleList, self).create(request, *args, **kwargs)
2952 if (ret.status_code%100 != 200):
2953 raise Exception(ret.data)
2954
2955 return ret
2956
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07002957
2958class RoleDetail(PlanetStackRetrieveUpdateDestroyAPIView):
2959 queryset = Role.objects.select_related().all()
2960 serializer_class = RoleSerializer
2961 id_serializer_class = RoleIdSerializer
2962
2963 def get_serializer_class(self):
2964 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2965 if (no_hyperlinks):
2966 return self.id_serializer_class
2967 else:
2968 return self.serializer_class
2969
2970 def get_queryset(self):
2971 return Role.select_by_user(self.request.user)
2972
2973 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2974
2975 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
2976
Scott Bakerf3816ac2014-11-12 01:13:53 -08002977"""
2978 XXX smbaker: my intent was to create a view that would return 'new' objects
2979 filled with defaults. I solved it another way, so this code may soon be
2980 abandoned.
2981
2982class RoleNew(GenericAPIView):
2983 serializer_class = RoleSerializer
2984 id_serializer_class = RoleIdSerializer
2985
2986 def get(self, request, *args, **kwargs):
2987 return self.makenew(request, *args, **kwargs)
2988
2989 def get_serializer_class(self):
2990 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
2991 if (no_hyperlinks):
2992 return self.id_serializer_class
2993 else:
2994 return self.serializer_class
2995
2996 def makenew(self, request, *args, **kwargs):
2997 obj = Role()
2998 serializer = self.get_serializer(obj)
2999 return Response(serializer.data)
3000"""
3001
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003002
3003
3004class UsableObjectList(generics.ListCreateAPIView):
3005 queryset = UsableObject.objects.select_related().all()
3006 serializer_class = UsableObjectSerializer
3007 id_serializer_class = UsableObjectIdSerializer
3008 filter_backends = (filters.DjangoFilterBackend,)
3009 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name',)
3010
3011 def get_serializer_class(self):
3012 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3013 if (no_hyperlinks):
3014 return self.id_serializer_class
3015 else:
3016 return self.serializer_class
3017
3018 def get_queryset(self):
3019 return UsableObject.select_by_user(self.request.user)
3020
3021 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003022 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3023 if not (serializer.is_valid()):
3024 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3025 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003026 obj.caller = request.user
3027 if obj.can_update(request.user):
3028 return super(UsableObjectList, self).create(request, *args, **kwargs)
3029 else:
Scott Baker08898c12014-10-29 23:41:11 -07003030 raise Exception("failed obj.can_update")
3031
3032 ret = super(UsableObjectList, self).create(request, *args, **kwargs)
3033 if (ret.status_code%100 != 200):
3034 raise Exception(ret.data)
3035
3036 return ret
3037
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003038
3039class UsableObjectDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3040 queryset = UsableObject.objects.select_related().all()
3041 serializer_class = UsableObjectSerializer
3042 id_serializer_class = UsableObjectIdSerializer
3043
3044 def get_serializer_class(self):
3045 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3046 if (no_hyperlinks):
3047 return self.id_serializer_class
3048 else:
3049 return self.serializer_class
3050
3051 def get_queryset(self):
3052 return UsableObject.select_by_user(self.request.user)
3053
3054 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3055
3056 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3057
Scott Bakerf3816ac2014-11-12 01:13:53 -08003058"""
3059 XXX smbaker: my intent was to create a view that would return 'new' objects
3060 filled with defaults. I solved it another way, so this code may soon be
3061 abandoned.
3062
3063class UsableObjectNew(GenericAPIView):
3064 serializer_class = UsableObjectSerializer
3065 id_serializer_class = UsableObjectIdSerializer
3066
3067 def get(self, request, *args, **kwargs):
3068 return self.makenew(request, *args, **kwargs)
3069
3070 def get_serializer_class(self):
3071 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3072 if (no_hyperlinks):
3073 return self.id_serializer_class
3074 else:
3075 return self.serializer_class
3076
3077 def makenew(self, request, *args, **kwargs):
3078 obj = UsableObject()
3079 serializer = self.get_serializer(obj)
3080 return Response(serializer.data)
3081"""
3082
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003083
3084
3085class SiteRoleList(generics.ListCreateAPIView):
3086 queryset = SiteRole.objects.select_related().all()
3087 serializer_class = SiteRoleSerializer
3088 id_serializer_class = SiteRoleIdSerializer
3089 filter_backends = (filters.DjangoFilterBackend,)
3090 filter_fields = ('id','created','updated','enacted','backend_status','deleted','role',)
3091
3092 def get_serializer_class(self):
3093 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3094 if (no_hyperlinks):
3095 return self.id_serializer_class
3096 else:
3097 return self.serializer_class
3098
3099 def get_queryset(self):
3100 return SiteRole.select_by_user(self.request.user)
3101
3102 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003103 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3104 if not (serializer.is_valid()):
3105 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3106 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003107 obj.caller = request.user
3108 if obj.can_update(request.user):
3109 return super(SiteRoleList, self).create(request, *args, **kwargs)
3110 else:
Scott Baker08898c12014-10-29 23:41:11 -07003111 raise Exception("failed obj.can_update")
3112
3113 ret = super(SiteRoleList, self).create(request, *args, **kwargs)
3114 if (ret.status_code%100 != 200):
3115 raise Exception(ret.data)
3116
3117 return ret
3118
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003119
3120class SiteRoleDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3121 queryset = SiteRole.objects.select_related().all()
3122 serializer_class = SiteRoleSerializer
3123 id_serializer_class = SiteRoleIdSerializer
3124
3125 def get_serializer_class(self):
3126 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3127 if (no_hyperlinks):
3128 return self.id_serializer_class
3129 else:
3130 return self.serializer_class
3131
3132 def get_queryset(self):
3133 return SiteRole.select_by_user(self.request.user)
3134
3135 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3136
3137 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3138
Scott Bakerf3816ac2014-11-12 01:13:53 -08003139"""
3140 XXX smbaker: my intent was to create a view that would return 'new' objects
3141 filled with defaults. I solved it another way, so this code may soon be
3142 abandoned.
3143
3144class SiteRoleNew(GenericAPIView):
3145 serializer_class = SiteRoleSerializer
3146 id_serializer_class = SiteRoleIdSerializer
3147
3148 def get(self, request, *args, **kwargs):
3149 return self.makenew(request, *args, **kwargs)
3150
3151 def get_serializer_class(self):
3152 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3153 if (no_hyperlinks):
3154 return self.id_serializer_class
3155 else:
3156 return self.serializer_class
3157
3158 def makenew(self, request, *args, **kwargs):
3159 obj = SiteRole()
3160 serializer = self.get_serializer(obj)
3161 return Response(serializer.data)
3162"""
3163
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003164
3165
3166class SliceCredentialList(generics.ListCreateAPIView):
3167 queryset = SliceCredential.objects.select_related().all()
3168 serializer_class = SliceCredentialSerializer
3169 id_serializer_class = SliceCredentialIdSerializer
3170 filter_backends = (filters.DjangoFilterBackend,)
3171 filter_fields = ('id','created','updated','enacted','backend_status','deleted','slice','name','key_id','enc_value',)
3172
3173 def get_serializer_class(self):
3174 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3175 if (no_hyperlinks):
3176 return self.id_serializer_class
3177 else:
3178 return self.serializer_class
3179
3180 def get_queryset(self):
3181 return SliceCredential.select_by_user(self.request.user)
3182
3183 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003184 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3185 if not (serializer.is_valid()):
3186 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3187 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003188 obj.caller = request.user
3189 if obj.can_update(request.user):
3190 return super(SliceCredentialList, self).create(request, *args, **kwargs)
3191 else:
Scott Baker08898c12014-10-29 23:41:11 -07003192 raise Exception("failed obj.can_update")
3193
3194 ret = super(SliceCredentialList, self).create(request, *args, **kwargs)
3195 if (ret.status_code%100 != 200):
3196 raise Exception(ret.data)
3197
3198 return ret
3199
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003200
3201class SliceCredentialDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3202 queryset = SliceCredential.objects.select_related().all()
3203 serializer_class = SliceCredentialSerializer
3204 id_serializer_class = SliceCredentialIdSerializer
3205
3206 def get_serializer_class(self):
3207 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3208 if (no_hyperlinks):
3209 return self.id_serializer_class
3210 else:
3211 return self.serializer_class
3212
3213 def get_queryset(self):
3214 return SliceCredential.select_by_user(self.request.user)
3215
3216 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3217
3218 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3219
Scott Bakerf3816ac2014-11-12 01:13:53 -08003220"""
3221 XXX smbaker: my intent was to create a view that would return 'new' objects
3222 filled with defaults. I solved it another way, so this code may soon be
3223 abandoned.
3224
3225class SliceCredentialNew(GenericAPIView):
3226 serializer_class = SliceCredentialSerializer
3227 id_serializer_class = SliceCredentialIdSerializer
3228
3229 def get(self, request, *args, **kwargs):
3230 return self.makenew(request, *args, **kwargs)
3231
3232 def get_serializer_class(self):
3233 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3234 if (no_hyperlinks):
3235 return self.id_serializer_class
3236 else:
3237 return self.serializer_class
3238
3239 def makenew(self, request, *args, **kwargs):
3240 obj = SliceCredential()
3241 serializer = self.get_serializer(obj)
3242 return Response(serializer.data)
3243"""
3244
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003245
3246
3247class SliverList(generics.ListCreateAPIView):
3248 queryset = Sliver.objects.select_related().all()
3249 serializer_class = SliverSerializer
3250 id_serializer_class = SliverIdSerializer
3251 filter_backends = (filters.DjangoFilterBackend,)
3252 filter_fields = ('id','created','updated','enacted','backend_status','deleted','instance_id','name','instance_name','ip','image','creator','slice','node','deploymentNetwork','numberCores','flavor','userData','networks','networks',)
3253
3254 def get_serializer_class(self):
3255 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3256 if (no_hyperlinks):
3257 return self.id_serializer_class
3258 else:
3259 return self.serializer_class
3260
3261 def get_queryset(self):
3262 return Sliver.select_by_user(self.request.user)
3263
3264 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003265 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3266 if not (serializer.is_valid()):
3267 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3268 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003269 obj.caller = request.user
3270 if obj.can_update(request.user):
3271 return super(SliverList, self).create(request, *args, **kwargs)
3272 else:
Scott Baker08898c12014-10-29 23:41:11 -07003273 raise Exception("failed obj.can_update")
3274
3275 ret = super(SliverList, self).create(request, *args, **kwargs)
3276 if (ret.status_code%100 != 200):
3277 raise Exception(ret.data)
3278
3279 return ret
3280
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003281
3282class SliverDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3283 queryset = Sliver.objects.select_related().all()
3284 serializer_class = SliverSerializer
3285 id_serializer_class = SliverIdSerializer
3286
3287 def get_serializer_class(self):
3288 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3289 if (no_hyperlinks):
3290 return self.id_serializer_class
3291 else:
3292 return self.serializer_class
3293
3294 def get_queryset(self):
3295 return Sliver.select_by_user(self.request.user)
3296
3297 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3298
3299 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3300
Scott Bakerf3816ac2014-11-12 01:13:53 -08003301"""
3302 XXX smbaker: my intent was to create a view that would return 'new' objects
3303 filled with defaults. I solved it another way, so this code may soon be
3304 abandoned.
3305
3306class SliverNew(GenericAPIView):
3307 serializer_class = SliverSerializer
3308 id_serializer_class = SliverIdSerializer
3309
3310 def get(self, request, *args, **kwargs):
3311 return self.makenew(request, *args, **kwargs)
3312
3313 def get_serializer_class(self):
3314 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3315 if (no_hyperlinks):
3316 return self.id_serializer_class
3317 else:
3318 return self.serializer_class
3319
3320 def makenew(self, request, *args, **kwargs):
3321 obj = Sliver()
3322 serializer = self.get_serializer(obj)
3323 return Response(serializer.data)
3324"""
3325
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003326
3327
3328class NodeList(generics.ListCreateAPIView):
3329 queryset = Node.objects.select_related().all()
3330 serializer_class = NodeSerializer
3331 id_serializer_class = NodeIdSerializer
3332 filter_backends = (filters.DjangoFilterBackend,)
3333 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','site','deployment',)
3334
3335 def get_serializer_class(self):
3336 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3337 if (no_hyperlinks):
3338 return self.id_serializer_class
3339 else:
3340 return self.serializer_class
3341
3342 def get_queryset(self):
3343 return Node.select_by_user(self.request.user)
3344
3345 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003346 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3347 if not (serializer.is_valid()):
3348 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3349 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003350 obj.caller = request.user
3351 if obj.can_update(request.user):
3352 return super(NodeList, self).create(request, *args, **kwargs)
3353 else:
Scott Baker08898c12014-10-29 23:41:11 -07003354 raise Exception("failed obj.can_update")
3355
3356 ret = super(NodeList, self).create(request, *args, **kwargs)
3357 if (ret.status_code%100 != 200):
3358 raise Exception(ret.data)
3359
3360 return ret
3361
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003362
3363class NodeDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3364 queryset = Node.objects.select_related().all()
3365 serializer_class = NodeSerializer
3366 id_serializer_class = NodeIdSerializer
3367
3368 def get_serializer_class(self):
3369 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3370 if (no_hyperlinks):
3371 return self.id_serializer_class
3372 else:
3373 return self.serializer_class
3374
3375 def get_queryset(self):
3376 return Node.select_by_user(self.request.user)
3377
3378 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3379
3380 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3381
Scott Bakerf3816ac2014-11-12 01:13:53 -08003382"""
3383 XXX smbaker: my intent was to create a view that would return 'new' objects
3384 filled with defaults. I solved it another way, so this code may soon be
3385 abandoned.
3386
3387class NodeNew(GenericAPIView):
3388 serializer_class = NodeSerializer
3389 id_serializer_class = NodeIdSerializer
3390
3391 def get(self, request, *args, **kwargs):
3392 return self.makenew(request, *args, **kwargs)
3393
3394 def get_serializer_class(self):
3395 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3396 if (no_hyperlinks):
3397 return self.id_serializer_class
3398 else:
3399 return self.serializer_class
3400
3401 def makenew(self, request, *args, **kwargs):
3402 obj = Node()
3403 serializer = self.get_serializer(obj)
3404 return Response(serializer.data)
3405"""
3406
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003407
3408
3409class DashboardViewList(generics.ListCreateAPIView):
3410 queryset = DashboardView.objects.select_related().all()
3411 serializer_class = DashboardViewSerializer
3412 id_serializer_class = DashboardViewIdSerializer
3413 filter_backends = (filters.DjangoFilterBackend,)
3414 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','url',)
3415
3416 def get_serializer_class(self):
3417 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3418 if (no_hyperlinks):
3419 return self.id_serializer_class
3420 else:
3421 return self.serializer_class
3422
3423 def get_queryset(self):
3424 return DashboardView.select_by_user(self.request.user)
3425
3426 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003427 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3428 if not (serializer.is_valid()):
3429 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3430 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003431 obj.caller = request.user
3432 if obj.can_update(request.user):
3433 return super(DashboardViewList, self).create(request, *args, **kwargs)
3434 else:
Scott Baker08898c12014-10-29 23:41:11 -07003435 raise Exception("failed obj.can_update")
3436
3437 ret = super(DashboardViewList, self).create(request, *args, **kwargs)
3438 if (ret.status_code%100 != 200):
3439 raise Exception(ret.data)
3440
3441 return ret
3442
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003443
3444class DashboardViewDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3445 queryset = DashboardView.objects.select_related().all()
3446 serializer_class = DashboardViewSerializer
3447 id_serializer_class = DashboardViewIdSerializer
3448
3449 def get_serializer_class(self):
3450 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3451 if (no_hyperlinks):
3452 return self.id_serializer_class
3453 else:
3454 return self.serializer_class
3455
3456 def get_queryset(self):
3457 return DashboardView.select_by_user(self.request.user)
3458
3459 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3460
3461 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3462
Scott Bakerf3816ac2014-11-12 01:13:53 -08003463"""
3464 XXX smbaker: my intent was to create a view that would return 'new' objects
3465 filled with defaults. I solved it another way, so this code may soon be
3466 abandoned.
3467
3468class DashboardViewNew(GenericAPIView):
3469 serializer_class = DashboardViewSerializer
3470 id_serializer_class = DashboardViewIdSerializer
3471
3472 def get(self, request, *args, **kwargs):
3473 return self.makenew(request, *args, **kwargs)
3474
3475 def get_serializer_class(self):
3476 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3477 if (no_hyperlinks):
3478 return self.id_serializer_class
3479 else:
3480 return self.serializer_class
3481
3482 def makenew(self, request, *args, **kwargs):
3483 obj = DashboardView()
3484 serializer = self.get_serializer(obj)
3485 return Response(serializer.data)
3486"""
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003487
3488
Scott Bakerf3816ac2014-11-12 01:13:53 -08003489
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003490class ReservedResourceList(generics.ListCreateAPIView):
3491 queryset = ReservedResource.objects.select_related().all()
3492 serializer_class = ReservedResourceSerializer
3493 id_serializer_class = ReservedResourceIdSerializer
3494 filter_backends = (filters.DjangoFilterBackend,)
3495 filter_fields = ('id','created','updated','enacted','backend_status','deleted','sliver','resource','quantity','reservationSet',)
3496
3497 def get_serializer_class(self):
3498 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3499 if (no_hyperlinks):
3500 return self.id_serializer_class
3501 else:
3502 return self.serializer_class
3503
3504 def get_queryset(self):
3505 return ReservedResource.select_by_user(self.request.user)
3506
3507 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003508 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3509 if not (serializer.is_valid()):
3510 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3511 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003512 obj.caller = request.user
3513 if obj.can_update(request.user):
3514 return super(ReservedResourceList, self).create(request, *args, **kwargs)
3515 else:
Scott Baker08898c12014-10-29 23:41:11 -07003516 raise Exception("failed obj.can_update")
3517
3518 ret = super(ReservedResourceList, self).create(request, *args, **kwargs)
3519 if (ret.status_code%100 != 200):
3520 raise Exception(ret.data)
3521
3522 return ret
3523
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003524
3525class ReservedResourceDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3526 queryset = ReservedResource.objects.select_related().all()
3527 serializer_class = ReservedResourceSerializer
3528 id_serializer_class = ReservedResourceIdSerializer
3529
3530 def get_serializer_class(self):
3531 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3532 if (no_hyperlinks):
3533 return self.id_serializer_class
3534 else:
3535 return self.serializer_class
3536
3537 def get_queryset(self):
3538 return ReservedResource.select_by_user(self.request.user)
3539
3540 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3541
3542 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3543
Scott Bakerf3816ac2014-11-12 01:13:53 -08003544"""
3545 XXX smbaker: my intent was to create a view that would return 'new' objects
3546 filled with defaults. I solved it another way, so this code may soon be
3547 abandoned.
3548
3549class ReservedResourceNew(GenericAPIView):
3550 serializer_class = ReservedResourceSerializer
3551 id_serializer_class = ReservedResourceIdSerializer
3552
3553 def get(self, request, *args, **kwargs):
3554 return self.makenew(request, *args, **kwargs)
3555
3556 def get_serializer_class(self):
3557 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3558 if (no_hyperlinks):
3559 return self.id_serializer_class
3560 else:
3561 return self.serializer_class
3562
3563 def makenew(self, request, *args, **kwargs):
3564 obj = ReservedResource()
3565 serializer = self.get_serializer(obj)
3566 return Response(serializer.data)
3567"""
3568
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003569
3570
Scott Baker645dc9d2014-11-17 22:32:19 -08003571class PaymentList(generics.ListCreateAPIView):
3572 queryset = Payment.objects.select_related().all()
3573 serializer_class = PaymentSerializer
3574 id_serializer_class = PaymentIdSerializer
3575 filter_backends = (filters.DjangoFilterBackend,)
3576 filter_fields = ('id','created','updated','enacted','backend_status','deleted','account','amount','date',)
3577
3578 def get_serializer_class(self):
3579 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3580 if (no_hyperlinks):
3581 return self.id_serializer_class
3582 else:
3583 return self.serializer_class
3584
3585 def get_queryset(self):
3586 return Payment.select_by_user(self.request.user)
3587
3588 def create(self, request, *args, **kwargs):
3589 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3590 if not (serializer.is_valid()):
3591 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3592 obj = serializer.object
3593 obj.caller = request.user
3594 if obj.can_update(request.user):
3595 return super(PaymentList, self).create(request, *args, **kwargs)
3596 else:
3597 raise Exception("failed obj.can_update")
3598
3599 ret = super(PaymentList, self).create(request, *args, **kwargs)
3600 if (ret.status_code%100 != 200):
3601 raise Exception(ret.data)
3602
3603 return ret
3604
3605
3606class PaymentDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3607 queryset = Payment.objects.select_related().all()
3608 serializer_class = PaymentSerializer
3609 id_serializer_class = PaymentIdSerializer
3610
3611 def get_serializer_class(self):
3612 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3613 if (no_hyperlinks):
3614 return self.id_serializer_class
3615 else:
3616 return self.serializer_class
3617
3618 def get_queryset(self):
3619 return Payment.select_by_user(self.request.user)
3620
3621 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3622
3623 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3624
3625"""
3626 XXX smbaker: my intent was to create a view that would return 'new' objects
3627 filled with defaults. I solved it another way, so this code may soon be
3628 abandoned.
3629
3630class PaymentNew(GenericAPIView):
3631 serializer_class = PaymentSerializer
3632 id_serializer_class = PaymentIdSerializer
3633
3634 def get(self, request, *args, **kwargs):
3635 return self.makenew(request, *args, **kwargs)
3636
3637 def get_serializer_class(self):
3638 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3639 if (no_hyperlinks):
3640 return self.id_serializer_class
3641 else:
3642 return self.serializer_class
3643
3644 def makenew(self, request, *args, **kwargs):
3645 obj = Payment()
3646 serializer = self.get_serializer(obj)
3647 return Response(serializer.data)
3648"""
3649
3650
3651
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003652class NetworkSliceList(generics.ListCreateAPIView):
3653 queryset = NetworkSlice.objects.select_related().all()
3654 serializer_class = NetworkSliceSerializer
3655 id_serializer_class = NetworkSliceIdSerializer
3656 filter_backends = (filters.DjangoFilterBackend,)
3657 filter_fields = ('id','created','updated','enacted','backend_status','deleted','network','slice',)
3658
3659 def get_serializer_class(self):
3660 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3661 if (no_hyperlinks):
3662 return self.id_serializer_class
3663 else:
3664 return self.serializer_class
3665
3666 def get_queryset(self):
3667 return NetworkSlice.select_by_user(self.request.user)
3668
3669 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003670 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3671 if not (serializer.is_valid()):
3672 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3673 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003674 obj.caller = request.user
3675 if obj.can_update(request.user):
3676 return super(NetworkSliceList, self).create(request, *args, **kwargs)
3677 else:
Scott Baker08898c12014-10-29 23:41:11 -07003678 raise Exception("failed obj.can_update")
3679
3680 ret = super(NetworkSliceList, self).create(request, *args, **kwargs)
3681 if (ret.status_code%100 != 200):
3682 raise Exception(ret.data)
3683
3684 return ret
3685
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003686
3687class NetworkSliceDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3688 queryset = NetworkSlice.objects.select_related().all()
3689 serializer_class = NetworkSliceSerializer
3690 id_serializer_class = NetworkSliceIdSerializer
3691
3692 def get_serializer_class(self):
3693 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3694 if (no_hyperlinks):
3695 return self.id_serializer_class
3696 else:
3697 return self.serializer_class
3698
3699 def get_queryset(self):
3700 return NetworkSlice.select_by_user(self.request.user)
3701
3702 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3703
3704 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3705
Scott Bakerf3816ac2014-11-12 01:13:53 -08003706"""
3707 XXX smbaker: my intent was to create a view that would return 'new' objects
3708 filled with defaults. I solved it another way, so this code may soon be
3709 abandoned.
3710
3711class NetworkSliceNew(GenericAPIView):
3712 serializer_class = NetworkSliceSerializer
3713 id_serializer_class = NetworkSliceIdSerializer
3714
3715 def get(self, request, *args, **kwargs):
3716 return self.makenew(request, *args, **kwargs)
3717
3718 def get_serializer_class(self):
3719 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3720 if (no_hyperlinks):
3721 return self.id_serializer_class
3722 else:
3723 return self.serializer_class
3724
3725 def makenew(self, request, *args, **kwargs):
3726 obj = NetworkSlice()
3727 serializer = self.get_serializer(obj)
3728 return Response(serializer.data)
3729"""
3730
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003731
3732
3733class UserDashboardViewList(generics.ListCreateAPIView):
3734 queryset = UserDashboardView.objects.select_related().all()
3735 serializer_class = UserDashboardViewSerializer
3736 id_serializer_class = UserDashboardViewIdSerializer
3737 filter_backends = (filters.DjangoFilterBackend,)
3738 filter_fields = ('id','created','updated','enacted','backend_status','deleted','user','dashboardView','order',)
3739
3740 def get_serializer_class(self):
3741 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3742 if (no_hyperlinks):
3743 return self.id_serializer_class
3744 else:
3745 return self.serializer_class
3746
3747 def get_queryset(self):
3748 return UserDashboardView.select_by_user(self.request.user)
3749
3750 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003751 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3752 if not (serializer.is_valid()):
3753 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3754 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003755 obj.caller = request.user
3756 if obj.can_update(request.user):
3757 return super(UserDashboardViewList, self).create(request, *args, **kwargs)
3758 else:
Scott Baker08898c12014-10-29 23:41:11 -07003759 raise Exception("failed obj.can_update")
3760
3761 ret = super(UserDashboardViewList, self).create(request, *args, **kwargs)
3762 if (ret.status_code%100 != 200):
3763 raise Exception(ret.data)
3764
3765 return ret
3766
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003767
3768class UserDashboardViewDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3769 queryset = UserDashboardView.objects.select_related().all()
3770 serializer_class = UserDashboardViewSerializer
3771 id_serializer_class = UserDashboardViewIdSerializer
3772
3773 def get_serializer_class(self):
3774 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3775 if (no_hyperlinks):
3776 return self.id_serializer_class
3777 else:
3778 return self.serializer_class
3779
3780 def get_queryset(self):
3781 return UserDashboardView.select_by_user(self.request.user)
3782
3783 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3784
3785 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3786
Scott Bakerf3816ac2014-11-12 01:13:53 -08003787"""
3788 XXX smbaker: my intent was to create a view that would return 'new' objects
3789 filled with defaults. I solved it another way, so this code may soon be
3790 abandoned.
3791
3792class UserDashboardViewNew(GenericAPIView):
3793 serializer_class = UserDashboardViewSerializer
3794 id_serializer_class = UserDashboardViewIdSerializer
3795
3796 def get(self, request, *args, **kwargs):
3797 return self.makenew(request, *args, **kwargs)
3798
3799 def get_serializer_class(self):
3800 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3801 if (no_hyperlinks):
3802 return self.id_serializer_class
3803 else:
3804 return self.serializer_class
3805
3806 def makenew(self, request, *args, **kwargs):
3807 obj = UserDashboardView()
3808 serializer = self.get_serializer(obj)
3809 return Response(serializer.data)
3810"""
3811
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003812
3813
Scott Baker645dc9d2014-11-17 22:32:19 -08003814class SiteDeploymentList(generics.ListCreateAPIView):
3815 queryset = SiteDeployment.objects.select_related().all()
3816 serializer_class = SiteDeploymentSerializer
3817 id_serializer_class = SiteDeploymentIdSerializer
3818 filter_backends = (filters.DjangoFilterBackend,)
3819 filter_fields = ('id','created','updated','enacted','backend_status','deleted','site','deployment','tenant_id',)
3820
3821 def get_serializer_class(self):
3822 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3823 if (no_hyperlinks):
3824 return self.id_serializer_class
3825 else:
3826 return self.serializer_class
3827
3828 def get_queryset(self):
3829 return SiteDeployment.select_by_user(self.request.user)
3830
3831 def create(self, request, *args, **kwargs):
3832 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3833 if not (serializer.is_valid()):
3834 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3835 obj = serializer.object
3836 obj.caller = request.user
3837 if obj.can_update(request.user):
3838 return super(SiteDeploymentList, self).create(request, *args, **kwargs)
3839 else:
3840 raise Exception("failed obj.can_update")
3841
3842 ret = super(SiteDeploymentList, self).create(request, *args, **kwargs)
3843 if (ret.status_code%100 != 200):
3844 raise Exception(ret.data)
3845
3846 return ret
3847
3848
3849class SiteDeploymentDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3850 queryset = SiteDeployment.objects.select_related().all()
3851 serializer_class = SiteDeploymentSerializer
3852 id_serializer_class = SiteDeploymentIdSerializer
3853
3854 def get_serializer_class(self):
3855 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3856 if (no_hyperlinks):
3857 return self.id_serializer_class
3858 else:
3859 return self.serializer_class
3860
3861 def get_queryset(self):
3862 return SiteDeployment.select_by_user(self.request.user)
3863
3864 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3865
3866 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3867
3868"""
3869 XXX smbaker: my intent was to create a view that would return 'new' objects
3870 filled with defaults. I solved it another way, so this code may soon be
3871 abandoned.
3872
3873class SiteDeploymentNew(GenericAPIView):
3874 serializer_class = SiteDeploymentSerializer
3875 id_serializer_class = SiteDeploymentIdSerializer
3876
3877 def get(self, request, *args, **kwargs):
3878 return self.makenew(request, *args, **kwargs)
3879
3880 def get_serializer_class(self):
3881 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3882 if (no_hyperlinks):
3883 return self.id_serializer_class
3884 else:
3885 return self.serializer_class
3886
3887 def makenew(self, request, *args, **kwargs):
3888 obj = SiteDeployment()
3889 serializer = self.get_serializer(obj)
3890 return Response(serializer.data)
3891"""
3892
3893
3894
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003895class PlanetStackPrivilegeList(generics.ListCreateAPIView):
3896 queryset = PlanetStackPrivilege.objects.select_related().all()
3897 serializer_class = PlanetStackPrivilegeSerializer
3898 id_serializer_class = PlanetStackPrivilegeIdSerializer
3899 filter_backends = (filters.DjangoFilterBackend,)
3900 filter_fields = ('id','created','updated','enacted','backend_status','deleted','user','planetstack','role',)
3901
3902 def get_serializer_class(self):
3903 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3904 if (no_hyperlinks):
3905 return self.id_serializer_class
3906 else:
3907 return self.serializer_class
3908
3909 def get_queryset(self):
3910 return PlanetStackPrivilege.select_by_user(self.request.user)
3911
3912 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003913 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3914 if not (serializer.is_valid()):
3915 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3916 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003917 obj.caller = request.user
3918 if obj.can_update(request.user):
3919 return super(PlanetStackPrivilegeList, self).create(request, *args, **kwargs)
3920 else:
Scott Baker08898c12014-10-29 23:41:11 -07003921 raise Exception("failed obj.can_update")
3922
3923 ret = super(PlanetStackPrivilegeList, self).create(request, *args, **kwargs)
3924 if (ret.status_code%100 != 200):
3925 raise Exception(ret.data)
3926
3927 return ret
3928
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003929
3930class PlanetStackPrivilegeDetail(PlanetStackRetrieveUpdateDestroyAPIView):
3931 queryset = PlanetStackPrivilege.objects.select_related().all()
3932 serializer_class = PlanetStackPrivilegeSerializer
3933 id_serializer_class = PlanetStackPrivilegeIdSerializer
3934
3935 def get_serializer_class(self):
3936 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3937 if (no_hyperlinks):
3938 return self.id_serializer_class
3939 else:
3940 return self.serializer_class
3941
3942 def get_queryset(self):
3943 return PlanetStackPrivilege.select_by_user(self.request.user)
3944
3945 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3946
3947 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
3948
Scott Bakerf3816ac2014-11-12 01:13:53 -08003949"""
3950 XXX smbaker: my intent was to create a view that would return 'new' objects
3951 filled with defaults. I solved it another way, so this code may soon be
3952 abandoned.
3953
3954class PlanetStackPrivilegeNew(GenericAPIView):
3955 serializer_class = PlanetStackPrivilegeSerializer
3956 id_serializer_class = PlanetStackPrivilegeIdSerializer
3957
3958 def get(self, request, *args, **kwargs):
3959 return self.makenew(request, *args, **kwargs)
3960
3961 def get_serializer_class(self):
3962 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3963 if (no_hyperlinks):
3964 return self.id_serializer_class
3965 else:
3966 return self.serializer_class
3967
3968 def makenew(self, request, *args, **kwargs):
3969 obj = PlanetStackPrivilege()
3970 serializer = self.get_serializer(obj)
3971 return Response(serializer.data)
3972"""
3973
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003974
3975
3976class UserList(generics.ListCreateAPIView):
3977 queryset = User.objects.select_related().all()
3978 serializer_class = UserSerializer
3979 id_serializer_class = UserIdSerializer
3980 filter_backends = (filters.DjangoFilterBackend,)
3981 filter_fields = ('id','password','last_login','email','username','firstname','lastname','phone','user_url','site','public_key','is_active','is_admin','is_staff','is_readonly','created','updated','enacted','backend_status','deleted','timezone',)
3982
3983 def get_serializer_class(self):
3984 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
3985 if (no_hyperlinks):
3986 return self.id_serializer_class
3987 else:
3988 return self.serializer_class
3989
3990 def get_queryset(self):
3991 return User.select_by_user(self.request.user)
3992
3993 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08003994 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
3995 if not (serializer.is_valid()):
3996 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
3997 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07003998 obj.caller = request.user
3999 if obj.can_update(request.user):
4000 return super(UserList, self).create(request, *args, **kwargs)
4001 else:
Scott Baker08898c12014-10-29 23:41:11 -07004002 raise Exception("failed obj.can_update")
4003
4004 ret = super(UserList, self).create(request, *args, **kwargs)
4005 if (ret.status_code%100 != 200):
4006 raise Exception(ret.data)
4007
4008 return ret
4009
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004010
4011class UserDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4012 queryset = User.objects.select_related().all()
4013 serializer_class = UserSerializer
4014 id_serializer_class = UserIdSerializer
4015
4016 def get_serializer_class(self):
4017 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4018 if (no_hyperlinks):
4019 return self.id_serializer_class
4020 else:
4021 return self.serializer_class
4022
4023 def get_queryset(self):
4024 return User.select_by_user(self.request.user)
4025
4026 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4027
4028 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4029
Scott Bakerf3816ac2014-11-12 01:13:53 -08004030"""
4031 XXX smbaker: my intent was to create a view that would return 'new' objects
4032 filled with defaults. I solved it another way, so this code may soon be
4033 abandoned.
4034
4035class UserNew(GenericAPIView):
4036 serializer_class = UserSerializer
4037 id_serializer_class = UserIdSerializer
4038
4039 def get(self, request, *args, **kwargs):
4040 return self.makenew(request, *args, **kwargs)
4041
4042 def get_serializer_class(self):
4043 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4044 if (no_hyperlinks):
4045 return self.id_serializer_class
4046 else:
4047 return self.serializer_class
4048
4049 def makenew(self, request, *args, **kwargs):
4050 obj = User()
4051 serializer = self.get_serializer(obj)
4052 return Response(serializer.data)
4053"""
4054
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004055
4056
4057class DeploymentList(generics.ListCreateAPIView):
4058 queryset = Deployment.objects.select_related().all()
4059 serializer_class = DeploymentSerializer
4060 id_serializer_class = DeploymentIdSerializer
4061 filter_backends = (filters.DjangoFilterBackend,)
4062 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','admin_user','admin_password','admin_tenant','auth_url','backend_type','availability_zone','accessControl','sites','sites','flavors','flavors',)
4063
4064 def get_serializer_class(self):
4065 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4066 if (no_hyperlinks):
4067 return self.id_serializer_class
4068 else:
4069 return self.serializer_class
4070
4071 def get_queryset(self):
4072 return Deployment.select_by_user(self.request.user)
4073
4074 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004075 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4076 if not (serializer.is_valid()):
4077 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4078 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004079 obj.caller = request.user
4080 if obj.can_update(request.user):
4081 return super(DeploymentList, self).create(request, *args, **kwargs)
4082 else:
Scott Baker08898c12014-10-29 23:41:11 -07004083 raise Exception("failed obj.can_update")
4084
4085 ret = super(DeploymentList, self).create(request, *args, **kwargs)
4086 if (ret.status_code%100 != 200):
4087 raise Exception(ret.data)
4088
4089 return ret
4090
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004091
4092class DeploymentDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4093 queryset = Deployment.objects.select_related().all()
4094 serializer_class = DeploymentSerializer
4095 id_serializer_class = DeploymentIdSerializer
4096
4097 def get_serializer_class(self):
4098 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4099 if (no_hyperlinks):
4100 return self.id_serializer_class
4101 else:
4102 return self.serializer_class
4103
4104 def get_queryset(self):
4105 return Deployment.select_by_user(self.request.user)
4106
4107 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4108
4109 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4110
Scott Bakerf3816ac2014-11-12 01:13:53 -08004111"""
4112 XXX smbaker: my intent was to create a view that would return 'new' objects
4113 filled with defaults. I solved it another way, so this code may soon be
4114 abandoned.
4115
4116class DeploymentNew(GenericAPIView):
4117 serializer_class = DeploymentSerializer
4118 id_serializer_class = DeploymentIdSerializer
4119
4120 def get(self, request, *args, **kwargs):
4121 return self.makenew(request, *args, **kwargs)
4122
4123 def get_serializer_class(self):
4124 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4125 if (no_hyperlinks):
4126 return self.id_serializer_class
4127 else:
4128 return self.serializer_class
4129
4130 def makenew(self, request, *args, **kwargs):
4131 obj = Deployment()
4132 serializer = self.get_serializer(obj)
4133 return Response(serializer.data)
4134"""
4135
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004136
4137
4138class ReservationList(generics.ListCreateAPIView):
4139 queryset = Reservation.objects.select_related().all()
4140 serializer_class = ReservationSerializer
4141 id_serializer_class = ReservationIdSerializer
4142 filter_backends = (filters.DjangoFilterBackend,)
4143 filter_fields = ('id','created','updated','enacted','backend_status','deleted','startTime','slice','duration',)
4144
4145 def get_serializer_class(self):
4146 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4147 if (no_hyperlinks):
4148 return self.id_serializer_class
4149 else:
4150 return self.serializer_class
4151
4152 def get_queryset(self):
4153 return Reservation.select_by_user(self.request.user)
4154
4155 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004156 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4157 if not (serializer.is_valid()):
4158 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4159 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004160 obj.caller = request.user
4161 if obj.can_update(request.user):
4162 return super(ReservationList, self).create(request, *args, **kwargs)
4163 else:
Scott Baker08898c12014-10-29 23:41:11 -07004164 raise Exception("failed obj.can_update")
4165
4166 ret = super(ReservationList, self).create(request, *args, **kwargs)
4167 if (ret.status_code%100 != 200):
4168 raise Exception(ret.data)
4169
4170 return ret
4171
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004172
4173class ReservationDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4174 queryset = Reservation.objects.select_related().all()
4175 serializer_class = ReservationSerializer
4176 id_serializer_class = ReservationIdSerializer
4177
4178 def get_serializer_class(self):
4179 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4180 if (no_hyperlinks):
4181 return self.id_serializer_class
4182 else:
4183 return self.serializer_class
4184
4185 def get_queryset(self):
4186 return Reservation.select_by_user(self.request.user)
4187
4188 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4189
4190 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4191
Scott Bakerf3816ac2014-11-12 01:13:53 -08004192"""
4193 XXX smbaker: my intent was to create a view that would return 'new' objects
4194 filled with defaults. I solved it another way, so this code may soon be
4195 abandoned.
4196
4197class ReservationNew(GenericAPIView):
4198 serializer_class = ReservationSerializer
4199 id_serializer_class = ReservationIdSerializer
4200
4201 def get(self, request, *args, **kwargs):
4202 return self.makenew(request, *args, **kwargs)
4203
4204 def get_serializer_class(self):
4205 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4206 if (no_hyperlinks):
4207 return self.id_serializer_class
4208 else:
4209 return self.serializer_class
4210
4211 def makenew(self, request, *args, **kwargs):
4212 obj = Reservation()
4213 serializer = self.get_serializer(obj)
4214 return Response(serializer.data)
4215"""
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004216
4217
Scott Bakerf3816ac2014-11-12 01:13:53 -08004218
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004219class SitePrivilegeList(generics.ListCreateAPIView):
4220 queryset = SitePrivilege.objects.select_related().all()
4221 serializer_class = SitePrivilegeSerializer
4222 id_serializer_class = SitePrivilegeIdSerializer
4223 filter_backends = (filters.DjangoFilterBackend,)
4224 filter_fields = ('id','created','updated','enacted','backend_status','deleted','user','site','role',)
4225
4226 def get_serializer_class(self):
4227 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4228 if (no_hyperlinks):
4229 return self.id_serializer_class
4230 else:
4231 return self.serializer_class
4232
4233 def get_queryset(self):
4234 return SitePrivilege.select_by_user(self.request.user)
4235
4236 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004237 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4238 if not (serializer.is_valid()):
4239 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4240 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004241 obj.caller = request.user
4242 if obj.can_update(request.user):
4243 return super(SitePrivilegeList, self).create(request, *args, **kwargs)
4244 else:
Scott Baker08898c12014-10-29 23:41:11 -07004245 raise Exception("failed obj.can_update")
4246
4247 ret = super(SitePrivilegeList, self).create(request, *args, **kwargs)
4248 if (ret.status_code%100 != 200):
4249 raise Exception(ret.data)
4250
4251 return ret
4252
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004253
4254class SitePrivilegeDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4255 queryset = SitePrivilege.objects.select_related().all()
4256 serializer_class = SitePrivilegeSerializer
4257 id_serializer_class = SitePrivilegeIdSerializer
4258
4259 def get_serializer_class(self):
4260 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4261 if (no_hyperlinks):
4262 return self.id_serializer_class
4263 else:
4264 return self.serializer_class
4265
4266 def get_queryset(self):
4267 return SitePrivilege.select_by_user(self.request.user)
4268
4269 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4270
4271 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4272
Scott Bakerf3816ac2014-11-12 01:13:53 -08004273"""
4274 XXX smbaker: my intent was to create a view that would return 'new' objects
4275 filled with defaults. I solved it another way, so this code may soon be
4276 abandoned.
4277
4278class SitePrivilegeNew(GenericAPIView):
4279 serializer_class = SitePrivilegeSerializer
4280 id_serializer_class = SitePrivilegeIdSerializer
4281
4282 def get(self, request, *args, **kwargs):
4283 return self.makenew(request, *args, **kwargs)
4284
4285 def get_serializer_class(self):
4286 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4287 if (no_hyperlinks):
4288 return self.id_serializer_class
4289 else:
4290 return self.serializer_class
4291
4292 def makenew(self, request, *args, **kwargs):
4293 obj = SitePrivilege()
4294 serializer = self.get_serializer(obj)
4295 return Response(serializer.data)
4296"""
4297
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004298
4299
Scott Baker645dc9d2014-11-17 22:32:19 -08004300class SliceDeploymentList(generics.ListCreateAPIView):
4301 queryset = SliceDeployment.objects.select_related().all()
4302 serializer_class = SliceDeploymentSerializer
4303 id_serializer_class = SliceDeploymentIdSerializer
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004304 filter_backends = (filters.DjangoFilterBackend,)
Scott Baker645dc9d2014-11-17 22:32:19 -08004305 filter_fields = ('id','created','updated','enacted','backend_status','deleted','slice','deployment','tenant_id','network_id','router_id','subnet_id',)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004306
4307 def get_serializer_class(self):
4308 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4309 if (no_hyperlinks):
4310 return self.id_serializer_class
4311 else:
4312 return self.serializer_class
4313
4314 def get_queryset(self):
Scott Baker645dc9d2014-11-17 22:32:19 -08004315 return SliceDeployment.select_by_user(self.request.user)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004316
4317 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004318 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4319 if not (serializer.is_valid()):
4320 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4321 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004322 obj.caller = request.user
4323 if obj.can_update(request.user):
Scott Baker645dc9d2014-11-17 22:32:19 -08004324 return super(SliceDeploymentList, self).create(request, *args, **kwargs)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004325 else:
Scott Baker08898c12014-10-29 23:41:11 -07004326 raise Exception("failed obj.can_update")
4327
Scott Baker645dc9d2014-11-17 22:32:19 -08004328 ret = super(SliceDeploymentList, self).create(request, *args, **kwargs)
Scott Baker08898c12014-10-29 23:41:11 -07004329 if (ret.status_code%100 != 200):
4330 raise Exception(ret.data)
4331
4332 return ret
4333
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004334
Scott Baker645dc9d2014-11-17 22:32:19 -08004335class SliceDeploymentDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4336 queryset = SliceDeployment.objects.select_related().all()
4337 serializer_class = SliceDeploymentSerializer
4338 id_serializer_class = SliceDeploymentIdSerializer
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004339
4340 def get_serializer_class(self):
4341 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4342 if (no_hyperlinks):
4343 return self.id_serializer_class
4344 else:
4345 return self.serializer_class
4346
4347 def get_queryset(self):
Scott Baker645dc9d2014-11-17 22:32:19 -08004348 return SliceDeployment.select_by_user(self.request.user)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004349
4350 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4351
4352 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4353
Scott Bakerf3816ac2014-11-12 01:13:53 -08004354"""
4355 XXX smbaker: my intent was to create a view that would return 'new' objects
4356 filled with defaults. I solved it another way, so this code may soon be
4357 abandoned.
4358
Scott Baker645dc9d2014-11-17 22:32:19 -08004359class SliceDeploymentNew(GenericAPIView):
4360 serializer_class = SliceDeploymentSerializer
4361 id_serializer_class = SliceDeploymentIdSerializer
Scott Bakerf3816ac2014-11-12 01:13:53 -08004362
4363 def get(self, request, *args, **kwargs):
4364 return self.makenew(request, *args, **kwargs)
4365
4366 def get_serializer_class(self):
4367 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4368 if (no_hyperlinks):
4369 return self.id_serializer_class
4370 else:
4371 return self.serializer_class
4372
4373 def makenew(self, request, *args, **kwargs):
Scott Baker645dc9d2014-11-17 22:32:19 -08004374 obj = SliceDeployment()
Scott Bakerf3816ac2014-11-12 01:13:53 -08004375 serializer = self.get_serializer(obj)
4376 return Response(serializer.data)
4377"""
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004378
4379
Scott Bakerf3816ac2014-11-12 01:13:53 -08004380
Scott Baker645dc9d2014-11-17 22:32:19 -08004381class UserDeploymentList(generics.ListCreateAPIView):
4382 queryset = UserDeployment.objects.select_related().all()
4383 serializer_class = UserDeploymentSerializer
4384 id_serializer_class = UserDeploymentIdSerializer
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004385 filter_backends = (filters.DjangoFilterBackend,)
4386 filter_fields = ('id','created','updated','enacted','backend_status','deleted','user','deployment','kuser_id',)
4387
4388 def get_serializer_class(self):
4389 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4390 if (no_hyperlinks):
4391 return self.id_serializer_class
4392 else:
4393 return self.serializer_class
4394
4395 def get_queryset(self):
Scott Baker645dc9d2014-11-17 22:32:19 -08004396 return UserDeployment.select_by_user(self.request.user)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004397
4398 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004399 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4400 if not (serializer.is_valid()):
4401 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4402 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004403 obj.caller = request.user
4404 if obj.can_update(request.user):
Scott Baker645dc9d2014-11-17 22:32:19 -08004405 return super(UserDeploymentList, self).create(request, *args, **kwargs)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004406 else:
Scott Baker08898c12014-10-29 23:41:11 -07004407 raise Exception("failed obj.can_update")
4408
Scott Baker645dc9d2014-11-17 22:32:19 -08004409 ret = super(UserDeploymentList, self).create(request, *args, **kwargs)
Scott Baker08898c12014-10-29 23:41:11 -07004410 if (ret.status_code%100 != 200):
4411 raise Exception(ret.data)
4412
4413 return ret
4414
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004415
Scott Baker645dc9d2014-11-17 22:32:19 -08004416class UserDeploymentDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4417 queryset = UserDeployment.objects.select_related().all()
4418 serializer_class = UserDeploymentSerializer
4419 id_serializer_class = UserDeploymentIdSerializer
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004420
4421 def get_serializer_class(self):
4422 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4423 if (no_hyperlinks):
4424 return self.id_serializer_class
4425 else:
4426 return self.serializer_class
4427
4428 def get_queryset(self):
Scott Baker645dc9d2014-11-17 22:32:19 -08004429 return UserDeployment.select_by_user(self.request.user)
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004430
4431 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4432
4433 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4434
Scott Bakerf3816ac2014-11-12 01:13:53 -08004435"""
4436 XXX smbaker: my intent was to create a view that would return 'new' objects
4437 filled with defaults. I solved it another way, so this code may soon be
4438 abandoned.
4439
Scott Baker645dc9d2014-11-17 22:32:19 -08004440class UserDeploymentNew(GenericAPIView):
4441 serializer_class = UserDeploymentSerializer
4442 id_serializer_class = UserDeploymentIdSerializer
Scott Bakerf3816ac2014-11-12 01:13:53 -08004443
4444 def get(self, request, *args, **kwargs):
4445 return self.makenew(request, *args, **kwargs)
4446
4447 def get_serializer_class(self):
4448 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4449 if (no_hyperlinks):
4450 return self.id_serializer_class
4451 else:
4452 return self.serializer_class
4453
4454 def makenew(self, request, *args, **kwargs):
Scott Baker645dc9d2014-11-17 22:32:19 -08004455 obj = UserDeployment()
Scott Bakerf3816ac2014-11-12 01:13:53 -08004456 serializer = self.get_serializer(obj)
4457 return Response(serializer.data)
4458"""
4459
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004460
4461
4462class AccountList(generics.ListCreateAPIView):
4463 queryset = Account.objects.select_related().all()
4464 serializer_class = AccountSerializer
4465 id_serializer_class = AccountIdSerializer
4466 filter_backends = (filters.DjangoFilterBackend,)
4467 filter_fields = ('id','created','updated','enacted','backend_status','deleted','site',)
4468
4469 def get_serializer_class(self):
4470 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4471 if (no_hyperlinks):
4472 return self.id_serializer_class
4473 else:
4474 return self.serializer_class
4475
4476 def get_queryset(self):
4477 return Account.select_by_user(self.request.user)
4478
4479 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004480 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4481 if not (serializer.is_valid()):
4482 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4483 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004484 obj.caller = request.user
4485 if obj.can_update(request.user):
4486 return super(AccountList, self).create(request, *args, **kwargs)
4487 else:
Scott Baker08898c12014-10-29 23:41:11 -07004488 raise Exception("failed obj.can_update")
4489
4490 ret = super(AccountList, self).create(request, *args, **kwargs)
4491 if (ret.status_code%100 != 200):
4492 raise Exception(ret.data)
4493
4494 return ret
4495
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004496
4497class AccountDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4498 queryset = Account.objects.select_related().all()
4499 serializer_class = AccountSerializer
4500 id_serializer_class = AccountIdSerializer
4501
4502 def get_serializer_class(self):
4503 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4504 if (no_hyperlinks):
4505 return self.id_serializer_class
4506 else:
4507 return self.serializer_class
4508
4509 def get_queryset(self):
4510 return Account.select_by_user(self.request.user)
4511
4512 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4513
4514 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4515
Scott Bakerf3816ac2014-11-12 01:13:53 -08004516"""
4517 XXX smbaker: my intent was to create a view that would return 'new' objects
4518 filled with defaults. I solved it another way, so this code may soon be
4519 abandoned.
4520
4521class AccountNew(GenericAPIView):
4522 serializer_class = AccountSerializer
4523 id_serializer_class = AccountIdSerializer
4524
4525 def get(self, request, *args, **kwargs):
4526 return self.makenew(request, *args, **kwargs)
4527
4528 def get_serializer_class(self):
4529 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4530 if (no_hyperlinks):
4531 return self.id_serializer_class
4532 else:
4533 return self.serializer_class
4534
4535 def makenew(self, request, *args, **kwargs):
4536 obj = Account()
4537 serializer = self.get_serializer(obj)
4538 return Response(serializer.data)
4539"""
4540
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004541
4542
4543class NetworkParameterTypeList(generics.ListCreateAPIView):
4544 queryset = NetworkParameterType.objects.select_related().all()
4545 serializer_class = NetworkParameterTypeSerializer
4546 id_serializer_class = NetworkParameterTypeIdSerializer
4547 filter_backends = (filters.DjangoFilterBackend,)
4548 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','description',)
4549
4550 def get_serializer_class(self):
4551 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4552 if (no_hyperlinks):
4553 return self.id_serializer_class
4554 else:
4555 return self.serializer_class
4556
4557 def get_queryset(self):
4558 return NetworkParameterType.select_by_user(self.request.user)
4559
4560 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004561 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4562 if not (serializer.is_valid()):
4563 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4564 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004565 obj.caller = request.user
4566 if obj.can_update(request.user):
4567 return super(NetworkParameterTypeList, self).create(request, *args, **kwargs)
4568 else:
Scott Baker08898c12014-10-29 23:41:11 -07004569 raise Exception("failed obj.can_update")
4570
4571 ret = super(NetworkParameterTypeList, self).create(request, *args, **kwargs)
4572 if (ret.status_code%100 != 200):
4573 raise Exception(ret.data)
4574
4575 return ret
4576
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004577
4578class NetworkParameterTypeDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4579 queryset = NetworkParameterType.objects.select_related().all()
4580 serializer_class = NetworkParameterTypeSerializer
4581 id_serializer_class = NetworkParameterTypeIdSerializer
4582
4583 def get_serializer_class(self):
4584 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4585 if (no_hyperlinks):
4586 return self.id_serializer_class
4587 else:
4588 return self.serializer_class
4589
4590 def get_queryset(self):
4591 return NetworkParameterType.select_by_user(self.request.user)
4592
4593 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4594
4595 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4596
Scott Bakerf3816ac2014-11-12 01:13:53 -08004597"""
4598 XXX smbaker: my intent was to create a view that would return 'new' objects
4599 filled with defaults. I solved it another way, so this code may soon be
4600 abandoned.
4601
4602class NetworkParameterTypeNew(GenericAPIView):
4603 serializer_class = NetworkParameterTypeSerializer
4604 id_serializer_class = NetworkParameterTypeIdSerializer
4605
4606 def get(self, request, *args, **kwargs):
4607 return self.makenew(request, *args, **kwargs)
4608
4609 def get_serializer_class(self):
4610 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4611 if (no_hyperlinks):
4612 return self.id_serializer_class
4613 else:
4614 return self.serializer_class
4615
4616 def makenew(self, request, *args, **kwargs):
4617 obj = NetworkParameterType()
4618 serializer = self.get_serializer(obj)
4619 return Response(serializer.data)
4620"""
4621
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004622
4623
4624class SiteCredentialList(generics.ListCreateAPIView):
4625 queryset = SiteCredential.objects.select_related().all()
4626 serializer_class = SiteCredentialSerializer
4627 id_serializer_class = SiteCredentialIdSerializer
4628 filter_backends = (filters.DjangoFilterBackend,)
4629 filter_fields = ('id','created','updated','enacted','backend_status','deleted','site','name','key_id','enc_value',)
4630
4631 def get_serializer_class(self):
4632 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4633 if (no_hyperlinks):
4634 return self.id_serializer_class
4635 else:
4636 return self.serializer_class
4637
4638 def get_queryset(self):
4639 return SiteCredential.select_by_user(self.request.user)
4640
4641 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004642 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4643 if not (serializer.is_valid()):
4644 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4645 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004646 obj.caller = request.user
4647 if obj.can_update(request.user):
4648 return super(SiteCredentialList, self).create(request, *args, **kwargs)
4649 else:
Scott Baker08898c12014-10-29 23:41:11 -07004650 raise Exception("failed obj.can_update")
4651
4652 ret = super(SiteCredentialList, self).create(request, *args, **kwargs)
4653 if (ret.status_code%100 != 200):
4654 raise Exception(ret.data)
4655
4656 return ret
4657
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004658
4659class SiteCredentialDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4660 queryset = SiteCredential.objects.select_related().all()
4661 serializer_class = SiteCredentialSerializer
4662 id_serializer_class = SiteCredentialIdSerializer
4663
4664 def get_serializer_class(self):
4665 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4666 if (no_hyperlinks):
4667 return self.id_serializer_class
4668 else:
4669 return self.serializer_class
4670
4671 def get_queryset(self):
4672 return SiteCredential.select_by_user(self.request.user)
4673
4674 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4675
4676 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4677
Scott Bakerf3816ac2014-11-12 01:13:53 -08004678"""
4679 XXX smbaker: my intent was to create a view that would return 'new' objects
4680 filled with defaults. I solved it another way, so this code may soon be
4681 abandoned.
4682
4683class SiteCredentialNew(GenericAPIView):
4684 serializer_class = SiteCredentialSerializer
4685 id_serializer_class = SiteCredentialIdSerializer
4686
4687 def get(self, request, *args, **kwargs):
4688 return self.makenew(request, *args, **kwargs)
4689
4690 def get_serializer_class(self):
4691 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4692 if (no_hyperlinks):
4693 return self.id_serializer_class
4694 else:
4695 return self.serializer_class
4696
4697 def makenew(self, request, *args, **kwargs):
4698 obj = SiteCredential()
4699 serializer = self.get_serializer(obj)
4700 return Response(serializer.data)
4701"""
4702
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004703
4704
4705class DeploymentPrivilegeList(generics.ListCreateAPIView):
4706 queryset = DeploymentPrivilege.objects.select_related().all()
4707 serializer_class = DeploymentPrivilegeSerializer
4708 id_serializer_class = DeploymentPrivilegeIdSerializer
4709 filter_backends = (filters.DjangoFilterBackend,)
4710 filter_fields = ('id','created','updated','enacted','backend_status','deleted','user','deployment','role',)
4711
4712 def get_serializer_class(self):
4713 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4714 if (no_hyperlinks):
4715 return self.id_serializer_class
4716 else:
4717 return self.serializer_class
4718
4719 def get_queryset(self):
4720 return DeploymentPrivilege.select_by_user(self.request.user)
4721
4722 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004723 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4724 if not (serializer.is_valid()):
4725 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4726 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004727 obj.caller = request.user
4728 if obj.can_update(request.user):
4729 return super(DeploymentPrivilegeList, self).create(request, *args, **kwargs)
4730 else:
Scott Baker08898c12014-10-29 23:41:11 -07004731 raise Exception("failed obj.can_update")
4732
4733 ret = super(DeploymentPrivilegeList, self).create(request, *args, **kwargs)
4734 if (ret.status_code%100 != 200):
4735 raise Exception(ret.data)
4736
4737 return ret
4738
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004739
4740class DeploymentPrivilegeDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4741 queryset = DeploymentPrivilege.objects.select_related().all()
4742 serializer_class = DeploymentPrivilegeSerializer
4743 id_serializer_class = DeploymentPrivilegeIdSerializer
4744
4745 def get_serializer_class(self):
4746 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4747 if (no_hyperlinks):
4748 return self.id_serializer_class
4749 else:
4750 return self.serializer_class
4751
4752 def get_queryset(self):
4753 return DeploymentPrivilege.select_by_user(self.request.user)
4754
4755 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4756
4757 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4758
Scott Bakerf3816ac2014-11-12 01:13:53 -08004759"""
4760 XXX smbaker: my intent was to create a view that would return 'new' objects
4761 filled with defaults. I solved it another way, so this code may soon be
4762 abandoned.
4763
4764class DeploymentPrivilegeNew(GenericAPIView):
4765 serializer_class = DeploymentPrivilegeSerializer
4766 id_serializer_class = DeploymentPrivilegeIdSerializer
4767
4768 def get(self, request, *args, **kwargs):
4769 return self.makenew(request, *args, **kwargs)
4770
4771 def get_serializer_class(self):
4772 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4773 if (no_hyperlinks):
4774 return self.id_serializer_class
4775 else:
4776 return self.serializer_class
4777
4778 def makenew(self, request, *args, **kwargs):
4779 obj = DeploymentPrivilege()
4780 serializer = self.get_serializer(obj)
4781 return Response(serializer.data)
4782"""
4783
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004784
4785
Scott Baker645dc9d2014-11-17 22:32:19 -08004786class ImageDeploymentList(generics.ListCreateAPIView):
4787 queryset = ImageDeployment.objects.select_related().all()
4788 serializer_class = ImageDeploymentSerializer
4789 id_serializer_class = ImageDeploymentIdSerializer
4790 filter_backends = (filters.DjangoFilterBackend,)
4791 filter_fields = ('id','created','updated','enacted','backend_status','deleted','image','deployment','glance_image_id',)
4792
4793 def get_serializer_class(self):
4794 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4795 if (no_hyperlinks):
4796 return self.id_serializer_class
4797 else:
4798 return self.serializer_class
4799
4800 def get_queryset(self):
4801 return ImageDeployment.select_by_user(self.request.user)
4802
4803 def create(self, request, *args, **kwargs):
4804 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4805 if not (serializer.is_valid()):
4806 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4807 obj = serializer.object
4808 obj.caller = request.user
4809 if obj.can_update(request.user):
4810 return super(ImageDeploymentList, self).create(request, *args, **kwargs)
4811 else:
4812 raise Exception("failed obj.can_update")
4813
4814 ret = super(ImageDeploymentList, self).create(request, *args, **kwargs)
4815 if (ret.status_code%100 != 200):
4816 raise Exception(ret.data)
4817
4818 return ret
4819
4820
4821class ImageDeploymentDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4822 queryset = ImageDeployment.objects.select_related().all()
4823 serializer_class = ImageDeploymentSerializer
4824 id_serializer_class = ImageDeploymentIdSerializer
4825
4826 def get_serializer_class(self):
4827 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4828 if (no_hyperlinks):
4829 return self.id_serializer_class
4830 else:
4831 return self.serializer_class
4832
4833 def get_queryset(self):
4834 return ImageDeployment.select_by_user(self.request.user)
4835
4836 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4837
4838 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4839
4840"""
4841 XXX smbaker: my intent was to create a view that would return 'new' objects
4842 filled with defaults. I solved it another way, so this code may soon be
4843 abandoned.
4844
4845class ImageDeploymentNew(GenericAPIView):
4846 serializer_class = ImageDeploymentSerializer
4847 id_serializer_class = ImageDeploymentIdSerializer
4848
4849 def get(self, request, *args, **kwargs):
4850 return self.makenew(request, *args, **kwargs)
4851
4852 def get_serializer_class(self):
4853 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4854 if (no_hyperlinks):
4855 return self.id_serializer_class
4856 else:
4857 return self.serializer_class
4858
4859 def makenew(self, request, *args, **kwargs):
4860 obj = ImageDeployment()
4861 serializer = self.get_serializer(obj)
4862 return Response(serializer.data)
4863"""
4864
4865
4866
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004867class DeploymentRoleList(generics.ListCreateAPIView):
4868 queryset = DeploymentRole.objects.select_related().all()
4869 serializer_class = DeploymentRoleSerializer
4870 id_serializer_class = DeploymentRoleIdSerializer
4871 filter_backends = (filters.DjangoFilterBackend,)
4872 filter_fields = ('id','created','updated','enacted','backend_status','deleted','role',)
4873
4874 def get_serializer_class(self):
4875 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4876 if (no_hyperlinks):
4877 return self.id_serializer_class
4878 else:
4879 return self.serializer_class
4880
4881 def get_queryset(self):
4882 return DeploymentRole.select_by_user(self.request.user)
4883
4884 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004885 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4886 if not (serializer.is_valid()):
4887 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4888 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004889 obj.caller = request.user
4890 if obj.can_update(request.user):
4891 return super(DeploymentRoleList, self).create(request, *args, **kwargs)
4892 else:
Scott Baker08898c12014-10-29 23:41:11 -07004893 raise Exception("failed obj.can_update")
4894
4895 ret = super(DeploymentRoleList, self).create(request, *args, **kwargs)
4896 if (ret.status_code%100 != 200):
4897 raise Exception(ret.data)
4898
4899 return ret
4900
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004901
4902class DeploymentRoleDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4903 queryset = DeploymentRole.objects.select_related().all()
4904 serializer_class = DeploymentRoleSerializer
4905 id_serializer_class = DeploymentRoleIdSerializer
4906
4907 def get_serializer_class(self):
4908 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4909 if (no_hyperlinks):
4910 return self.id_serializer_class
4911 else:
4912 return self.serializer_class
4913
4914 def get_queryset(self):
4915 return DeploymentRole.select_by_user(self.request.user)
4916
4917 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4918
4919 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4920
Scott Bakerf3816ac2014-11-12 01:13:53 -08004921"""
4922 XXX smbaker: my intent was to create a view that would return 'new' objects
4923 filled with defaults. I solved it another way, so this code may soon be
4924 abandoned.
4925
4926class DeploymentRoleNew(GenericAPIView):
4927 serializer_class = DeploymentRoleSerializer
4928 id_serializer_class = DeploymentRoleIdSerializer
4929
4930 def get(self, request, *args, **kwargs):
4931 return self.makenew(request, *args, **kwargs)
4932
4933 def get_serializer_class(self):
4934 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4935 if (no_hyperlinks):
4936 return self.id_serializer_class
4937 else:
4938 return self.serializer_class
4939
4940 def makenew(self, request, *args, **kwargs):
4941 obj = DeploymentRole()
4942 serializer = self.get_serializer(obj)
4943 return Response(serializer.data)
4944"""
4945
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004946
4947
4948class UserCredentialList(generics.ListCreateAPIView):
4949 queryset = UserCredential.objects.select_related().all()
4950 serializer_class = UserCredentialSerializer
4951 id_serializer_class = UserCredentialIdSerializer
4952 filter_backends = (filters.DjangoFilterBackend,)
4953 filter_fields = ('id','created','updated','enacted','backend_status','deleted','user','name','key_id','enc_value',)
4954
4955 def get_serializer_class(self):
4956 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4957 if (no_hyperlinks):
4958 return self.id_serializer_class
4959 else:
4960 return self.serializer_class
4961
4962 def get_queryset(self):
4963 return UserCredential.select_by_user(self.request.user)
4964
4965 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08004966 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
4967 if not (serializer.is_valid()):
4968 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
4969 obj = serializer.object
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004970 obj.caller = request.user
4971 if obj.can_update(request.user):
4972 return super(UserCredentialList, self).create(request, *args, **kwargs)
4973 else:
Scott Baker08898c12014-10-29 23:41:11 -07004974 raise Exception("failed obj.can_update")
4975
4976 ret = super(UserCredentialList, self).create(request, *args, **kwargs)
4977 if (ret.status_code%100 != 200):
4978 raise Exception(ret.data)
4979
4980 return ret
4981
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07004982
4983class UserCredentialDetail(PlanetStackRetrieveUpdateDestroyAPIView):
4984 queryset = UserCredential.objects.select_related().all()
4985 serializer_class = UserCredentialSerializer
4986 id_serializer_class = UserCredentialIdSerializer
4987
4988 def get_serializer_class(self):
4989 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
4990 if (no_hyperlinks):
4991 return self.id_serializer_class
4992 else:
4993 return self.serializer_class
4994
4995 def get_queryset(self):
4996 return UserCredential.select_by_user(self.request.user)
4997
4998 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
4999
5000 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
5001
Scott Bakerf3816ac2014-11-12 01:13:53 -08005002"""
5003 XXX smbaker: my intent was to create a view that would return 'new' objects
5004 filled with defaults. I solved it another way, so this code may soon be
5005 abandoned.
5006
5007class UserCredentialNew(GenericAPIView):
5008 serializer_class = UserCredentialSerializer
5009 id_serializer_class = UserCredentialIdSerializer
5010
5011 def get(self, request, *args, **kwargs):
5012 return self.makenew(request, *args, **kwargs)
5013
5014 def get_serializer_class(self):
5015 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5016 if (no_hyperlinks):
5017 return self.id_serializer_class
5018 else:
5019 return self.serializer_class
5020
5021 def makenew(self, request, *args, **kwargs):
5022 obj = UserCredential()
5023 serializer = self.get_serializer(obj)
5024 return Response(serializer.data)
5025"""
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005026
5027
Scott Bakerf3816ac2014-11-12 01:13:53 -08005028
Scott Baker0caeaf02014-06-19 11:12:55 -07005029class SliceTagList(generics.ListCreateAPIView):
5030 queryset = SliceTag.objects.select_related().all()
5031 serializer_class = SliceTagSerializer
Scott Baker46b58542014-08-11 17:26:12 -07005032 id_serializer_class = SliceTagIdSerializer
5033 filter_backends = (filters.DjangoFilterBackend,)
5034 filter_fields = ('id','created','updated','enacted','backend_status','deleted','slice','name','value',)
5035
5036 def get_serializer_class(self):
5037 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5038 if (no_hyperlinks):
5039 return self.id_serializer_class
5040 else:
5041 return self.serializer_class
5042
Scott Baker0caeaf02014-06-19 11:12:55 -07005043 def get_queryset(self):
5044 return SliceTag.select_by_user(self.request.user)
Sapan Bhatiadea39432014-06-13 03:10:36 -04005045
Scott Baker0caeaf02014-06-19 11:12:55 -07005046 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08005047 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
5048 if not (serializer.is_valid()):
5049 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
5050 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07005051 obj.caller = request.user
5052 if obj.can_update(request.user):
5053 return super(SliceTagList, self).create(request, *args, **kwargs)
5054 else:
Scott Baker08898c12014-10-29 23:41:11 -07005055 raise Exception("failed obj.can_update")
5056
5057 ret = super(SliceTagList, self).create(request, *args, **kwargs)
5058 if (ret.status_code%100 != 200):
5059 raise Exception(ret.data)
5060
5061 return ret
5062
Scott Baker0caeaf02014-06-19 11:12:55 -07005063
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005064class SliceTagDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07005065 queryset = SliceTag.objects.select_related().all()
5066 serializer_class = SliceTagSerializer
Scott Baker46b58542014-08-11 17:26:12 -07005067 id_serializer_class = SliceTagIdSerializer
5068
5069 def get_serializer_class(self):
5070 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5071 if (no_hyperlinks):
5072 return self.id_serializer_class
5073 else:
5074 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07005075
5076 def get_queryset(self):
5077 return SliceTag.select_by_user(self.request.user)
5078
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005079 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07005080
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005081 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04005082
Scott Bakerf3816ac2014-11-12 01:13:53 -08005083"""
5084 XXX smbaker: my intent was to create a view that would return 'new' objects
5085 filled with defaults. I solved it another way, so this code may soon be
5086 abandoned.
5087
5088class SliceTagNew(GenericAPIView):
5089 serializer_class = SliceTagSerializer
5090 id_serializer_class = SliceTagIdSerializer
5091
5092 def get(self, request, *args, **kwargs):
5093 return self.makenew(request, *args, **kwargs)
5094
5095 def get_serializer_class(self):
5096 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5097 if (no_hyperlinks):
5098 return self.id_serializer_class
5099 else:
5100 return self.serializer_class
5101
5102 def makenew(self, request, *args, **kwargs):
5103 obj = SliceTag()
5104 serializer = self.get_serializer(obj)
5105 return Response(serializer.data)
5106"""
5107
Sapan Bhatiadea39432014-06-13 03:10:36 -04005108
5109
Scott Baker0caeaf02014-06-19 11:12:55 -07005110class NetworkTemplateList(generics.ListCreateAPIView):
5111 queryset = NetworkTemplate.objects.select_related().all()
5112 serializer_class = NetworkTemplateSerializer
Scott Baker46b58542014-08-11 17:26:12 -07005113 id_serializer_class = NetworkTemplateIdSerializer
5114 filter_backends = (filters.DjangoFilterBackend,)
Scott Baker645dc9d2014-11-17 22:32:19 -08005115 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','description','guaranteedBandwidth','visibility','translation','sharedNetworkName','sharedNetworkId','topologyKind','controllerKind',)
Scott Baker46b58542014-08-11 17:26:12 -07005116
5117 def get_serializer_class(self):
5118 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5119 if (no_hyperlinks):
5120 return self.id_serializer_class
5121 else:
5122 return self.serializer_class
5123
Scott Baker0caeaf02014-06-19 11:12:55 -07005124 def get_queryset(self):
5125 return NetworkTemplate.select_by_user(self.request.user)
Sapan Bhatiadea39432014-06-13 03:10:36 -04005126
Scott Baker0caeaf02014-06-19 11:12:55 -07005127 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08005128 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
5129 if not (serializer.is_valid()):
5130 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
5131 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07005132 obj.caller = request.user
5133 if obj.can_update(request.user):
5134 return super(NetworkTemplateList, self).create(request, *args, **kwargs)
5135 else:
Scott Baker08898c12014-10-29 23:41:11 -07005136 raise Exception("failed obj.can_update")
5137
5138 ret = super(NetworkTemplateList, self).create(request, *args, **kwargs)
5139 if (ret.status_code%100 != 200):
5140 raise Exception(ret.data)
5141
5142 return ret
5143
Scott Baker0caeaf02014-06-19 11:12:55 -07005144
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005145class NetworkTemplateDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07005146 queryset = NetworkTemplate.objects.select_related().all()
5147 serializer_class = NetworkTemplateSerializer
Scott Baker46b58542014-08-11 17:26:12 -07005148 id_serializer_class = NetworkTemplateIdSerializer
5149
5150 def get_serializer_class(self):
5151 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5152 if (no_hyperlinks):
5153 return self.id_serializer_class
5154 else:
5155 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07005156
5157 def get_queryset(self):
5158 return NetworkTemplate.select_by_user(self.request.user)
5159
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005160 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07005161
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005162 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04005163
Scott Bakerf3816ac2014-11-12 01:13:53 -08005164"""
5165 XXX smbaker: my intent was to create a view that would return 'new' objects
5166 filled with defaults. I solved it another way, so this code may soon be
5167 abandoned.
5168
5169class NetworkTemplateNew(GenericAPIView):
5170 serializer_class = NetworkTemplateSerializer
5171 id_serializer_class = NetworkTemplateIdSerializer
5172
5173 def get(self, request, *args, **kwargs):
5174 return self.makenew(request, *args, **kwargs)
5175
5176 def get_serializer_class(self):
5177 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5178 if (no_hyperlinks):
5179 return self.id_serializer_class
5180 else:
5181 return self.serializer_class
5182
5183 def makenew(self, request, *args, **kwargs):
5184 obj = NetworkTemplate()
5185 serializer = self.get_serializer(obj)
5186 return Response(serializer.data)
5187"""
5188
Sapan Bhatiadea39432014-06-13 03:10:36 -04005189
5190
5191class RouterList(generics.ListCreateAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07005192 queryset = Router.objects.select_related().all()
Sapan Bhatiadea39432014-06-13 03:10:36 -04005193 serializer_class = RouterSerializer
Scott Baker46b58542014-08-11 17:26:12 -07005194 id_serializer_class = RouterIdSerializer
5195 filter_backends = (filters.DjangoFilterBackend,)
5196 filter_fields = ('id','created','updated','enacted','backend_status','deleted','name','owner',)
5197
5198 def get_serializer_class(self):
5199 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5200 if (no_hyperlinks):
5201 return self.id_serializer_class
5202 else:
5203 return self.serializer_class
5204
Scott Baker0caeaf02014-06-19 11:12:55 -07005205 def get_queryset(self):
5206 return Router.select_by_user(self.request.user)
5207
5208 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08005209 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
5210 if not (serializer.is_valid()):
5211 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
5212 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07005213 obj.caller = request.user
5214 if obj.can_update(request.user):
5215 return super(RouterList, self).create(request, *args, **kwargs)
5216 else:
Scott Baker08898c12014-10-29 23:41:11 -07005217 raise Exception("failed obj.can_update")
5218
5219 ret = super(RouterList, self).create(request, *args, **kwargs)
5220 if (ret.status_code%100 != 200):
5221 raise Exception(ret.data)
5222
5223 return ret
5224
Sapan Bhatiadea39432014-06-13 03:10:36 -04005225
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005226class RouterDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07005227 queryset = Router.objects.select_related().all()
Sapan Bhatiadea39432014-06-13 03:10:36 -04005228 serializer_class = RouterSerializer
Scott Baker46b58542014-08-11 17:26:12 -07005229 id_serializer_class = RouterIdSerializer
5230
5231 def get_serializer_class(self):
5232 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5233 if (no_hyperlinks):
5234 return self.id_serializer_class
5235 else:
5236 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07005237
5238 def get_queryset(self):
5239 return Router.select_by_user(self.request.user)
5240
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005241 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07005242
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005243 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04005244
Scott Bakerf3816ac2014-11-12 01:13:53 -08005245"""
5246 XXX smbaker: my intent was to create a view that would return 'new' objects
5247 filled with defaults. I solved it another way, so this code may soon be
5248 abandoned.
5249
5250class RouterNew(GenericAPIView):
5251 serializer_class = RouterSerializer
5252 id_serializer_class = RouterIdSerializer
5253
5254 def get(self, request, *args, **kwargs):
5255 return self.makenew(request, *args, **kwargs)
5256
5257 def get_serializer_class(self):
5258 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5259 if (no_hyperlinks):
5260 return self.id_serializer_class
5261 else:
5262 return self.serializer_class
5263
5264 def makenew(self, request, *args, **kwargs):
5265 obj = Router()
5266 serializer = self.get_serializer(obj)
5267 return Response(serializer.data)
5268"""
5269
Sapan Bhatiadea39432014-06-13 03:10:36 -04005270
5271
Scott Baker0caeaf02014-06-19 11:12:55 -07005272class ServiceResourceList(generics.ListCreateAPIView):
5273 queryset = ServiceResource.objects.select_related().all()
5274 serializer_class = ServiceResourceSerializer
Scott Baker46b58542014-08-11 17:26:12 -07005275 id_serializer_class = ServiceResourceIdSerializer
5276 filter_backends = (filters.DjangoFilterBackend,)
5277 filter_fields = ('id','created','updated','enacted','backend_status','deleted','serviceClass','name','maxUnitsDeployment','maxUnitsNode','maxDuration','bucketInRate','bucketMaxSize','cost','calendarReservable',)
5278
5279 def get_serializer_class(self):
5280 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5281 if (no_hyperlinks):
5282 return self.id_serializer_class
5283 else:
5284 return self.serializer_class
5285
Scott Baker0caeaf02014-06-19 11:12:55 -07005286 def get_queryset(self):
5287 return ServiceResource.select_by_user(self.request.user)
Sapan Bhatiadea39432014-06-13 03:10:36 -04005288
Scott Baker0caeaf02014-06-19 11:12:55 -07005289 def create(self, request, *args, **kwargs):
Scott Bakerf3816ac2014-11-12 01:13:53 -08005290 serializer = self.get_serializer(data=request.DATA, files=request.FILES)
5291 if not (serializer.is_valid()):
5292 raise Exception("failed serializer.is_valid: " + str(serializer.errors))
5293 obj = serializer.object
Scott Baker0caeaf02014-06-19 11:12:55 -07005294 obj.caller = request.user
5295 if obj.can_update(request.user):
5296 return super(ServiceResourceList, self).create(request, *args, **kwargs)
5297 else:
Scott Baker08898c12014-10-29 23:41:11 -07005298 raise Exception("failed obj.can_update")
5299
5300 ret = super(ServiceResourceList, self).create(request, *args, **kwargs)
5301 if (ret.status_code%100 != 200):
5302 raise Exception(ret.data)
5303
5304 return ret
5305
Scott Baker0caeaf02014-06-19 11:12:55 -07005306
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005307class ServiceResourceDetail(PlanetStackRetrieveUpdateDestroyAPIView):
Scott Baker0caeaf02014-06-19 11:12:55 -07005308 queryset = ServiceResource.objects.select_related().all()
5309 serializer_class = ServiceResourceSerializer
Scott Baker46b58542014-08-11 17:26:12 -07005310 id_serializer_class = ServiceResourceIdSerializer
5311
5312 def get_serializer_class(self):
5313 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5314 if (no_hyperlinks):
5315 return self.id_serializer_class
5316 else:
5317 return self.serializer_class
Scott Baker0caeaf02014-06-19 11:12:55 -07005318
5319 def get_queryset(self):
5320 return ServiceResource.select_by_user(self.request.user)
5321
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005322 # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Scott Baker0caeaf02014-06-19 11:12:55 -07005323
Scott Bakerdcb9b5d2014-10-07 00:10:17 -07005324 # destroy() is handled by PlanetStackRetrieveUpdateDestroyAPIView
Sapan Bhatiadea39432014-06-13 03:10:36 -04005325
Scott Bakerf3816ac2014-11-12 01:13:53 -08005326"""
5327 XXX smbaker: my intent was to create a view that would return 'new' objects
5328 filled with defaults. I solved it another way, so this code may soon be
5329 abandoned.
5330
5331class ServiceResourceNew(GenericAPIView):
5332 serializer_class = ServiceResourceSerializer
5333 id_serializer_class = ServiceResourceIdSerializer
5334
5335 def get(self, request, *args, **kwargs):
5336 return self.makenew(request, *args, **kwargs)
5337
5338 def get_serializer_class(self):
5339 no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
5340 if (no_hyperlinks):
5341 return self.id_serializer_class
5342 else:
5343 return self.serializer_class
5344
5345 def makenew(self, request, *args, **kwargs):
5346 obj = ServiceResource()
5347 serializer = self.get_serializer(obj)
5348 return Response(serializer.data)
5349"""
5350
Sapan Bhatiadea39432014-06-13 03:10:36 -04005351
5352