blob: 5bbe7aa823d613c68d3acb11abfeb801478bf616 [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',
Tony Mack7130ac32013-03-22 21:58:00 -0400128 'site',
Tony Mack3a1af412013-04-09 22:36:27 -0400129 'slivers',
Tony Mack7130ac32013-03-22 21:58:00 -0400130 'updated',
131 'created')
132
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400133class SlicePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
Tony Mack29c287f2013-04-11 21:07:16 -0400134 id = serializers.Field()
135 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
136 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
137 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
138 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400139 model = SlicePrivilege
Tony Mack29c287f2013-04-11 21:07:16 -0400140 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400141 'url',
Tony Mack29c287f2013-04-11 21:07:16 -0400142 'user',
143 'slice',
144 'role')
145
Tony Mack7130ac32013-03-22 21:58:00 -0400146class SiteSerializer(serializers.HyperlinkedModelSerializer):
147
148 #Experimenting with whether to use ids, hyperlinks, or nested includes
149 #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
150 #slices = serializers.RelatedField(many=True, read_only=True)
151 #slices = SliceSerializer(many=True)
Tony Macka2dfb372013-04-09 11:02:32 -0400152 # HyperlinkedModelSerializer doesn't include the id by default
153 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -0400154 slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400155
156 class Meta:
157 model = Site
Tony Mack879d14a2013-04-09 09:34:19 -0400158 fields = ('id',
159 'url',
Tony Mack7130ac32013-03-22 21:58:00 -0400160 'name',
Tony Mack7130ac32013-03-22 21:58:00 -0400161 'slices',
162 'site_url',
163 'enabled',
164 'longitude',
165 'latitude',
166 'login_base',
Tony Macke87bffa2013-04-08 23:18:04 -0400167 'tenant_id',
Tony Mack7130ac32013-03-22 21:58:00 -0400168 'is_public',
169 'abbreviated_name',
170 'updated',
171 'created')
172
Tony Mack29c287f2013-04-11 21:07:16 -0400173class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
174 id = serializers.Field()
175 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
176 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
177 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
178 class Meta:
179 model = SitePrivilege
180 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400181 'url',
Tony Mack29c287f2013-04-11 21:07:16 -0400182 'user',
183 'site',
184 'role')
185
Tony Macka2dfb372013-04-09 11:02:32 -0400186class SliverSerializer(serializers.HyperlinkedModelSerializer):
187 # HyperlinkedModelSerializer doesn't include the id by default
188 id = serializers.Field()
Tony Mack29c287f2013-04-11 21:07:16 -0400189 image = serializers.HyperlinkedRelatedField(view_name='image-detail')
Tony Mack29c287f2013-04-11 21:07:16 -0400190 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400191 deploymentNetwork = serializers.HyperlinkedRelatedField(view_name='deployment-detail')
Tony Mack29c287f2013-04-11 21:07:16 -0400192 node = serializers.HyperlinkedRelatedField(view_name='node-detail')
193
Tony Mack7130ac32013-03-22 21:58:00 -0400194 #slice = serializers.PrimaryKeyRelatedField(read_only=True)
195
196 class Meta:
197 model = Sliver
198 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400199 'url',
Tony Mack29c287f2013-04-11 21:07:16 -0400200 'instance_id',
Tony Mack5d6598c2013-04-12 12:45:02 -0400201 'name',
Tony Mack79748612013-05-01 14:52:03 -0400202 'instance_name',
Tony Mackd90cdbf2013-04-16 22:48:40 -0400203 'ip',
Tony Mack29c287f2013-04-11 21:07:16 -0400204 'image',
Tony Mack7130ac32013-03-22 21:58:00 -0400205 'slice',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400206 'deploymentNetwork',
Tony Mack5d6598c2013-04-12 12:45:02 -0400207 'node')
Tony Mack7130ac32013-03-22 21:58:00 -0400208
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400209class UserSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -0400210 # HyperlinkedModelSerializer doesn't include the id by default
211 id = serializers.Field()
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400212 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
213 slice_privileges = serializers.HyperlinkedRelatedField(view_name='sliceprivilege-detail')
214 site_privileges = serializers.HyperlinkedRelatedField(view_name='siteprivilege-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400215 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400216 model = User
Tony Mack7130ac32013-03-22 21:58:00 -0400217 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400218 'url',
219 'kuser_id',
220 'firstname',
221 'lastname',
222 'email',
223 'password',
224 'phone',
225 'public_key',
226 'user_url',
227 'is_admin',
228 'slice_privileges',
229 'site_privileges')
230
231class TagSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -0400232 # HyperlinkedModelSerializer doesn't include the id by default
233 id = serializers.Field()
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400234 project = serializers.HyperlinkedRelatedField(view_name='project-detail')
235 #content_type = serializers.PrimaryKeyRelatedField(read_only=True)
236 content_type = serializers.RelatedField(source = "content_type")
237 content_object = serializers.RelatedField(source='content_object')
Tony Mack53310082013-04-09 09:26:12 -0400238 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400239 model = Tag
240 fields = ('id',
241 'url',
242 'project',
243 'value',
244 'content_type',
245 'object_id',
246 'content_object',
247 'name')
Tony Mack53310082013-04-09 09:26:12 -0400248
Tony Macka28f1cd2013-04-07 20:02:31 -0400249serializerLookUp = {
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400250 Deployment: DeploymentSerializer,
251 Image: ImageSerializer,
252 Node: NodeSerializer,
253 Project: ProjectSerializer,
254 Reservation: ReservationSerializer,
Tony Macka28f1cd2013-04-07 20:02:31 -0400255 Role: RoleSerializer,
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400256 ServiceClass: ServiceClassSerializer,
257 ServiceResource: ServiceResourceSerializer,
Tony Macka28f1cd2013-04-07 20:02:31 -0400258 Site: SiteSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400259 SitePrivilege: SitePrivilegeSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400260 Slice: SliceSerializer,
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400261 SlicePrivilege: SlicePrivilegeSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400262 Sliver: SliverSerializer,
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400263 Tag: TagSerializer,
264 User: UserSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400265 None: None,
266 }
Tony Mack53310082013-04-09 09:26:12 -0400267