blob: b83157b8087431c82117744825425235103f34ae [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',
Tony Mack7130ac32013-03-22 21:58:00 -0400127 'site',
Tony Mack3a1af412013-04-09 22:36:27 -0400128 'slivers',
Tony Mack7130ac32013-03-22 21:58:00 -0400129 'updated',
130 'created')
131
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400132class SlicePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
Tony Mack29c287f2013-04-11 21:07:16 -0400133 id = serializers.Field()
134 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
135 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
136 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
137 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400138 model = SlicePrivilege
Tony Mack29c287f2013-04-11 21:07:16 -0400139 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400140 'url',
Tony Mack29c287f2013-04-11 21:07:16 -0400141 'user',
142 'slice',
143 'role')
144
Tony Mack7130ac32013-03-22 21:58:00 -0400145class SiteSerializer(serializers.HyperlinkedModelSerializer):
146
147 #Experimenting with whether to use ids, hyperlinks, or nested includes
148 #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
149 #slices = serializers.RelatedField(many=True, read_only=True)
150 #slices = SliceSerializer(many=True)
Tony Macka2dfb372013-04-09 11:02:32 -0400151 # HyperlinkedModelSerializer doesn't include the id by default
152 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -0400153 slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400154
155 class Meta:
156 model = Site
Tony Mack879d14a2013-04-09 09:34:19 -0400157 fields = ('id',
158 'url',
Tony Mack7130ac32013-03-22 21:58:00 -0400159 'name',
Tony Mack7130ac32013-03-22 21:58:00 -0400160 'slices',
161 'site_url',
162 'enabled',
163 'longitude',
164 'latitude',
165 'login_base',
Tony Macke87bffa2013-04-08 23:18:04 -0400166 'tenant_id',
Tony Mack7130ac32013-03-22 21:58:00 -0400167 'is_public',
168 'abbreviated_name',
169 'updated',
170 'created')
171
Tony Mack29c287f2013-04-11 21:07:16 -0400172class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
173 id = serializers.Field()
174 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
175 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
176 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
177 class Meta:
178 model = SitePrivilege
179 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400180 'url',
Tony Mack29c287f2013-04-11 21:07:16 -0400181 'user',
182 'site',
183 'role')
184
Tony Macka2dfb372013-04-09 11:02:32 -0400185class SliverSerializer(serializers.HyperlinkedModelSerializer):
186 # HyperlinkedModelSerializer doesn't include the id by default
187 id = serializers.Field()
Tony Mack29c287f2013-04-11 21:07:16 -0400188 image = serializers.HyperlinkedRelatedField(view_name='image-detail')
Tony Mack29c287f2013-04-11 21:07:16 -0400189 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400190 deploymentNetwork = serializers.HyperlinkedRelatedField(view_name='deployment-detail')
Tony Mack29c287f2013-04-11 21:07:16 -0400191 node = serializers.HyperlinkedRelatedField(view_name='node-detail')
192
Tony Mack7130ac32013-03-22 21:58:00 -0400193 #slice = serializers.PrimaryKeyRelatedField(read_only=True)
194
195 class Meta:
196 model = Sliver
197 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400198 'url',
Tony Mack29c287f2013-04-11 21:07:16 -0400199 'instance_id',
Tony Mack5d6598c2013-04-12 12:45:02 -0400200 'name',
Tony Mack79748612013-05-01 14:52:03 -0400201 'instance_name',
Tony Mackd90cdbf2013-04-16 22:48:40 -0400202 'ip',
Tony Mack29c287f2013-04-11 21:07:16 -0400203 'image',
Tony Mack7130ac32013-03-22 21:58:00 -0400204 'slice',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400205 'deploymentNetwork',
Tony Mack5d6598c2013-04-12 12:45:02 -0400206 'node')
Tony Mack7130ac32013-03-22 21:58:00 -0400207
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400208class UserSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -0400209 # HyperlinkedModelSerializer doesn't include the id by default
210 id = serializers.Field()
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400211 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
212 slice_privileges = serializers.HyperlinkedRelatedField(view_name='sliceprivilege-detail')
213 site_privileges = serializers.HyperlinkedRelatedField(view_name='siteprivilege-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400214 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400215 model = User
Tony Mack7130ac32013-03-22 21:58:00 -0400216 fields = ('id',
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400217 'url',
218 'kuser_id',
219 'firstname',
220 'lastname',
221 'email',
222 'password',
223 'phone',
224 'public_key',
225 'user_url',
226 'is_admin',
227 'slice_privileges',
228 'site_privileges')
229
230class TagSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -0400231 # HyperlinkedModelSerializer doesn't include the id by default
232 id = serializers.Field()
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400233 project = serializers.HyperlinkedRelatedField(view_name='project-detail')
234 #content_type = serializers.PrimaryKeyRelatedField(read_only=True)
235 content_type = serializers.RelatedField(source = "content_type")
236 content_object = serializers.RelatedField(source='content_object')
Tony Mack53310082013-04-09 09:26:12 -0400237 class Meta:
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400238 model = Tag
239 fields = ('id',
240 'url',
241 'project',
242 'value',
243 'content_type',
244 'object_id',
245 'content_object',
246 'name')
Tony Mack53310082013-04-09 09:26:12 -0400247
Tony Macka28f1cd2013-04-07 20:02:31 -0400248serializerLookUp = {
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400249 Deployment: DeploymentSerializer,
250 Image: ImageSerializer,
251 Node: NodeSerializer,
252 Project: ProjectSerializer,
253 Reservation: ReservationSerializer,
Tony Macka28f1cd2013-04-07 20:02:31 -0400254 Role: RoleSerializer,
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400255 ServiceClass: ServiceClassSerializer,
256 ServiceResource: ServiceResourceSerializer,
Tony Macka28f1cd2013-04-07 20:02:31 -0400257 Site: SiteSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400258 SitePrivilege: SitePrivilegeSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400259 Slice: SliceSerializer,
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400260 SlicePrivilege: SlicePrivilegeSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400261 Sliver: SliverSerializer,
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400262 Tag: TagSerializer,
263 User: UserSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400264 None: None,
265 }
Tony Mack53310082013-04-09 09:26:12 -0400266