blob: 3fb726d19f85991b9b334ab4406a3d3a22d38002 [file] [log] [blame]
Tony Mack7130ac32013-03-22 21:58:00 -04001from django.forms import widgets
2from rest_framework import serializers
Siobhan Tully30fd4292013-05-10 08:59:56 -04003from core.models import *
Tony Mack7130ac32013-03-22 21:58:00 -04004
5
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04006class DeploymentSerializer(serializers.HyperlinkedModelSerializer):
7
8 # HyperlinkedModelSerializer doesn't include the id by default
9 id = serializers.Field()
10 sites = serializers.HyperlinkedRelatedField(view_name='site-detail')
11 class Meta:
12 model = Deployment
13 fields = ('id',
14 'url',
15 'name',
16 'sites'
17 )
18
19class ImageSerializer(serializers.HyperlinkedModelSerializer):
20 # HyperlinkedModelSerializer doesn't include the id by default
21 id = serializers.Field()
22 class Meta:
23 model = Image
24 fields = ('id',
25 'url',
26 'image_id',
27 'name',
28 'disk_format',
29 'container_format')
30
31class NodeSerializer(serializers.HyperlinkedModelSerializer):
32 # HyperlinkedModelSerializer doesn't include the id by default
33 id = serializers.Field()
34 class Meta:
35 model = Node
36 fields = ('id',
37 'url',
38 'name')
39
40class ProjectSerializer(serializers.HyperlinkedModelSerializer):
41 # HyperlinkedModelSerializer doesn't include the id by default
42 id = serializers.Field()
43 class Meta:
44 model = Project
45 fields = ('id',
46 'url',
47 'name')
48
49class ReservationSerializer(serializers.HyperlinkedModelSerializer):
50 # HyperlinkedModelSerializer doesn't include the id by default
51 id = serializers.Field()
52 class Meta:
53 model = Reservation
54 fields = ('id',
55 'url',
56 'startTime',
57 'slice',
58 'duration',
59 'endTime',
60 )
61
Tony Macka28f1cd2013-04-07 20:02:31 -040062class RoleSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -040063 # HyperlinkedModelSerializer doesn't include the id by default
64 id = serializers.Field()
Tony Macka28f1cd2013-04-07 20:02:31 -040065 class Meta:
66 model = Role
Tony Mack879d14a2013-04-09 09:34:19 -040067 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040068 'url',
69 'role',
70 'role_type')
Tony Macka28f1cd2013-04-07 20:02:31 -040071
Tony Mack5cc16ba2013-04-09 10:30:45 -040072
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040073class ServiceClassSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -040074 # HyperlinkedModelSerializer doesn't include the id by default
75 id = serializers.Field()
Tony Mack5cc16ba2013-04-09 10:30:45 -040076 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040077 model = ServiceClass
Tony Mack5cc16ba2013-04-09 10:30:45 -040078 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040079 'url',
80 'name',
81 'description',
82 'commitment',
83 'membershipFee',
84 'membershipFeeMonths',
85 'upgradeRequiresApproval',
86 'upgradeFrom',
87 )
88
89class ServiceResourceSerializer(serializers.HyperlinkedModelSerializer):
90 # HyperlinkedModelSerializer doesn't include the id by default
91 id = serializers.Field()
92 serviceClass = serializers.HyperlinkedRelatedField(view_name='serviceclass-detail')
93 class Meta:
94 model = ServiceResource
95 fields = ('id',
96 'url',
97 'name',
98 'serviceClass',
99 'maxUnitsDeployment',
100 'maxUnitsNode',
101 'maxDuration',
102 'bucketInRate',
103 'bucketMaxSize',
104 'cost',
105 'calendarReservable',
106 )
107
Tony Mack7130ac32013-03-22 21:58:00 -0400108class SliceSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -0400109 # HyperlinkedModelSerializer doesn't include the id by default
110 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -0400111 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
Tony Mack3a1af412013-04-09 22:36:27 -0400112 slivers = serializers.HyperlinkedRelatedField(view_name='sliver-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400113 class Meta:
114 model = Slice
Tony Mack879d14a2013-04-09 09:34:19 -0400115 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400116 'url',
Tony Mack3a1af412013-04-09 22:36:27 -0400117 'tenant_id',
118 'enabled',
Tony Mack7130ac32013-03-22 21:58:00 -0400119 'name',
Tony Mack3a1af412013-04-09 22:36:27 -0400120 'url',
Tony Mack7130ac32013-03-22 21:58:00 -0400121 'omf_friendly',
122 'description',
123 'slice_url',
Tony Mack3a1af412013-04-09 22:36:27 -0400124 'network_id',
125 'router_id',
Tony Mack1e7169e2013-05-07 11:09:57 -0400126 'subnet_id',
Scott Baker537d8232014-04-08 23:40:56 -0700127 'imagePreference',
Scott Baker4b0cedd2014-04-22 21:01:21 -0700128 'network',
129 'mountDataSets',
Tony Mack7130ac32013-03-22 21:58:00 -0400130 'site',
Tony Mack3a1af412013-04-09 22:36:27 -0400131 'slivers',
Tony Mack7130ac32013-03-22 21:58:00 -0400132 'updated',
133 'created')
134
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400135class SlicePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
Tony Mack29c287f2013-04-11 21:07:16 -0400136 id = serializers.Field()
137 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
138 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
139 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
140 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400141 model = SlicePrivilege
Tony Mack29c287f2013-04-11 21:07:16 -0400142 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400143 'url',
Tony Mack29c287f2013-04-11 21:07:16 -0400144 'user',
145 'slice',
146 'role')
147
Tony Mack7130ac32013-03-22 21:58:00 -0400148class SiteSerializer(serializers.HyperlinkedModelSerializer):
149
150 #Experimenting with whether to use ids, hyperlinks, or nested includes
151 #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
152 #slices = serializers.RelatedField(many=True, read_only=True)
153 #slices = SliceSerializer(many=True)
Tony Macka2dfb372013-04-09 11:02:32 -0400154 # HyperlinkedModelSerializer doesn't include the id by default
155 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -0400156 slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400157
158 class Meta:
159 model = Site
Tony Mack879d14a2013-04-09 09:34:19 -0400160 fields = ('id',
161 'url',
Tony Mack7130ac32013-03-22 21:58:00 -0400162 'name',
Tony Mack7130ac32013-03-22 21:58:00 -0400163 'slices',
164 'site_url',
165 'enabled',
166 'longitude',
167 'latitude',
168 'login_base',
Tony Macke87bffa2013-04-08 23:18:04 -0400169 'tenant_id',
Tony Mack7130ac32013-03-22 21:58:00 -0400170 'is_public',
171 'abbreviated_name',
172 'updated',
173 'created')
174
Tony Mack29c287f2013-04-11 21:07:16 -0400175class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
176 id = serializers.Field()
177 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
178 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
179 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
180 class Meta:
181 model = SitePrivilege
182 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400183 'url',
Tony Mack29c287f2013-04-11 21:07:16 -0400184 'user',
185 'site',
186 'role')
187
Tony Macka2dfb372013-04-09 11:02:32 -0400188class SliverSerializer(serializers.HyperlinkedModelSerializer):
189 # HyperlinkedModelSerializer doesn't include the id by default
190 id = serializers.Field()
Tony Mack29c287f2013-04-11 21:07:16 -0400191 image = serializers.HyperlinkedRelatedField(view_name='image-detail')
Tony Mack29c287f2013-04-11 21:07:16 -0400192 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400193 deploymentNetwork = serializers.HyperlinkedRelatedField(view_name='deployment-detail')
Tony Mack29c287f2013-04-11 21:07:16 -0400194 node = serializers.HyperlinkedRelatedField(view_name='node-detail')
195
Tony Mack7130ac32013-03-22 21:58:00 -0400196 #slice = serializers.PrimaryKeyRelatedField(read_only=True)
197
198 class Meta:
199 model = Sliver
200 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400201 'url',
Tony Mack29c287f2013-04-11 21:07:16 -0400202 'instance_id',
Tony Mack5d6598c2013-04-12 12:45:02 -0400203 'name',
Tony Mack79748612013-05-01 14:52:03 -0400204 'instance_name',
Tony Mackd90cdbf2013-04-16 22:48:40 -0400205 'ip',
Tony Mack29c287f2013-04-11 21:07:16 -0400206 'image',
Tony Mack7130ac32013-03-22 21:58:00 -0400207 'slice',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400208 'deploymentNetwork',
Tony Mack5d6598c2013-04-12 12:45:02 -0400209 'node')
Tony Mack7130ac32013-03-22 21:58:00 -0400210
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400211class UserSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -0400212 # HyperlinkedModelSerializer doesn't include the id by default
213 id = serializers.Field()
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400214 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
215 slice_privileges = serializers.HyperlinkedRelatedField(view_name='sliceprivilege-detail')
216 site_privileges = serializers.HyperlinkedRelatedField(view_name='siteprivilege-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400217 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400218 model = User
Tony Mack7130ac32013-03-22 21:58:00 -0400219 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400220 'url',
221 'kuser_id',
222 'firstname',
223 'lastname',
224 'email',
225 'password',
226 'phone',
227 'public_key',
228 'user_url',
229 'is_admin',
230 'slice_privileges',
231 'site_privileges')
232
233class TagSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -0400234 # HyperlinkedModelSerializer doesn't include the id by default
235 id = serializers.Field()
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400236 project = serializers.HyperlinkedRelatedField(view_name='project-detail')
237 #content_type = serializers.PrimaryKeyRelatedField(read_only=True)
238 content_type = serializers.RelatedField(source = "content_type")
239 content_object = serializers.RelatedField(source='content_object')
Tony Mack53310082013-04-09 09:26:12 -0400240 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400241 model = Tag
242 fields = ('id',
243 'url',
244 'project',
245 'value',
246 'content_type',
247 'object_id',
248 'content_object',
249 'name')
Tony Mack53310082013-04-09 09:26:12 -0400250
Tony Macka28f1cd2013-04-07 20:02:31 -0400251serializerLookUp = {
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400252 Deployment: DeploymentSerializer,
253 Image: ImageSerializer,
254 Node: NodeSerializer,
255 Project: ProjectSerializer,
256 Reservation: ReservationSerializer,
Tony Macka28f1cd2013-04-07 20:02:31 -0400257 Role: RoleSerializer,
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400258 ServiceClass: ServiceClassSerializer,
259 ServiceResource: ServiceResourceSerializer,
Tony Macka28f1cd2013-04-07 20:02:31 -0400260 Site: SiteSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400261 SitePrivilege: SitePrivilegeSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400262 Slice: SliceSerializer,
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400263 SlicePrivilege: SlicePrivilegeSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400264 Sliver: SliverSerializer,
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400265 Tag: TagSerializer,
266 User: UserSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400267 None: None,
268 }
Tony Mack53310082013-04-09 09:26:12 -0400269