blob: 00d71601d246ddb3bb4d4f8a67ca0a842a4777f0 [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
Tony Macka28f1cd2013-04-07 20:02:31 -04006class RoleSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -04007 # HyperlinkedModelSerializer doesn't include the id by default
8 id = serializers.Field()
Tony Macka28f1cd2013-04-07 20:02:31 -04009 class Meta:
10 model = Role
Tony Mack879d14a2013-04-09 09:34:19 -040011 fields = ('id',
12 'role_id',
Siobhan Tully47ae1b52013-05-10 15:53:14 -040013 'role',
Tony Macka28f1cd2013-04-07 20:02:31 -040014 'role_type')
15
Tony Mack5cc16ba2013-04-09 10:30:45 -040016
17class UserSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -040018 # HyperlinkedModelSerializer doesn't include the id by default
19 id = serializers.Field()
Tony Mack5cc16ba2013-04-09 10:30:45 -040020 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
21 slice_memberships = serializers.HyperlinkedRelatedField(view_name='slice-membership-detail')
22 site_privileges = serializers.HyperlinkedRelatedField(view_name='site-privilege-detail')
23 class Meta:
Siobhan Tully30fd4292013-05-10 08:59:56 -040024 model = User
Tony Mack5cc16ba2013-04-09 10:30:45 -040025 fields = ('id',
26 'user_id',
Siobhan Tully30fd4292013-05-10 08:59:56 -040027 'kuser_id',
Tony Mack5cc16ba2013-04-09 10:30:45 -040028 'firstname',
29 'lastname',
30 'email',
Tony Mackb0d97422013-06-10 09:57:45 -040031 'password',
32 'phone',
33 'public_key',
Tony Mack5cc16ba2013-04-09 10:30:45 -040034 'user_url',
35 'is_admin',
36 'site',
37 'slice_memberships',
38 'site_privileges')
39
Tony Mack7130ac32013-03-22 21:58:00 -040040class SliceSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -040041 # HyperlinkedModelSerializer doesn't include the id by default
42 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -040043 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
Tony Mack3a1af412013-04-09 22:36:27 -040044 slivers = serializers.HyperlinkedRelatedField(view_name='sliver-detail')
Tony Mack7130ac32013-03-22 21:58:00 -040045 class Meta:
46 model = Slice
Tony Mack879d14a2013-04-09 09:34:19 -040047 fields = ('id',
Tony Mack3a1af412013-04-09 22:36:27 -040048 'tenant_id',
49 'enabled',
Tony Mack7130ac32013-03-22 21:58:00 -040050 'name',
Tony Mack3a1af412013-04-09 22:36:27 -040051 'url',
Tony Mack7130ac32013-03-22 21:58:00 -040052 'omf_friendly',
53 'description',
54 'slice_url',
Tony Mack3a1af412013-04-09 22:36:27 -040055 'network_id',
56 'router_id',
Tony Mack1e7169e2013-05-07 11:09:57 -040057 'subnet_id',
Tony Mack7130ac32013-03-22 21:58:00 -040058 'site',
Tony Mack3a1af412013-04-09 22:36:27 -040059 'slivers',
Tony Mack7130ac32013-03-22 21:58:00 -040060 'updated',
61 'created')
62
Tony Mack29c287f2013-04-11 21:07:16 -040063class SliceMembershipSerializer(serializers.HyperlinkedModelSerializer):
64 id = serializers.Field()
65 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
66 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
67 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
68 class Meta:
69 model = SitePrivilege
70 fields = ('id',
71 'user',
72 'slice',
73 'role')
74
Tony Mack7130ac32013-03-22 21:58:00 -040075class SiteSerializer(serializers.HyperlinkedModelSerializer):
76
77 #Experimenting with whether to use ids, hyperlinks, or nested includes
78 #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
79 #slices = serializers.RelatedField(many=True, read_only=True)
80 #slices = SliceSerializer(many=True)
Tony Macka2dfb372013-04-09 11:02:32 -040081 # HyperlinkedModelSerializer doesn't include the id by default
82 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -040083 slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail')
Tony Mack7130ac32013-03-22 21:58:00 -040084
85 class Meta:
86 model = Site
Tony Mack879d14a2013-04-09 09:34:19 -040087 fields = ('id',
88 'url',
Tony Mack7130ac32013-03-22 21:58:00 -040089 'name',
Tony Mack7130ac32013-03-22 21:58:00 -040090 'slices',
91 'site_url',
92 'enabled',
93 'longitude',
94 'latitude',
95 'login_base',
Tony Macke87bffa2013-04-08 23:18:04 -040096 'tenant_id',
Tony Mack7130ac32013-03-22 21:58:00 -040097 'is_public',
98 'abbreviated_name',
99 'updated',
100 'created')
101
Tony Mack29c287f2013-04-11 21:07:16 -0400102class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
103 id = serializers.Field()
104 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
105 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
106 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
107 class Meta:
108 model = SitePrivilege
109 fields = ('id',
110 'user',
111 'site',
112 'role')
113
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400114class DeploymentSerializer(serializers.HyperlinkedModelSerializer):
Tony Mack7130ac32013-03-22 21:58:00 -0400115
Tony Macka2dfb372013-04-09 11:02:32 -0400116 # HyperlinkedModelSerializer doesn't include the id by default
117 id = serializers.Field()
Tony Mack29c287f2013-04-11 21:07:16 -0400118 sites = serializers.HyperlinkedRelatedField(view_name='deploymentnetwork-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400119 class Meta:
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400120 model = Deployment
Tony Mack879d14a2013-04-09 09:34:19 -0400121 fields = ('id',
122 'name',
Tony Mack7130ac32013-03-22 21:58:00 -0400123 'sites'
124 )
125
Tony Macka2dfb372013-04-09 11:02:32 -0400126class SliverSerializer(serializers.HyperlinkedModelSerializer):
127 # HyperlinkedModelSerializer doesn't include the id by default
128 id = serializers.Field()
Tony Mack29c287f2013-04-11 21:07:16 -0400129 image = serializers.HyperlinkedRelatedField(view_name='image-detail')
130 key = serializers.HyperlinkedRelatedField(view_name='key-detail')
131 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
132 deployment_network = serializers.HyperlinkedRelatedField(view_name='deployment_network-detail')
133 node = serializers.HyperlinkedRelatedField(view_name='node-detail')
134
135
Tony Mack7130ac32013-03-22 21:58:00 -0400136 #slice = serializers.PrimaryKeyRelatedField(read_only=True)
137
138 class Meta:
139 model = Sliver
140 fields = ('id',
Tony Mack29c287f2013-04-11 21:07:16 -0400141 'instance_id',
Tony Mack5d6598c2013-04-12 12:45:02 -0400142 'name',
Tony Mack79748612013-05-01 14:52:03 -0400143 'instance_name',
Tony Mackd90cdbf2013-04-16 22:48:40 -0400144 'ip',
Tony Mack29c287f2013-04-11 21:07:16 -0400145 'image',
Tony Mack5d6598c2013-04-12 12:45:02 -0400146 'key',
Tony Mack7130ac32013-03-22 21:58:00 -0400147 'slice',
Tony Mack5d6598c2013-04-12 12:45:02 -0400148 'deploymentNetwork',
149 'node')
Tony Mack7130ac32013-03-22 21:58:00 -0400150
Tony Macka2dfb372013-04-09 11:02:32 -0400151class NodeSerializer(serializers.HyperlinkedModelSerializer):
152 # HyperlinkedModelSerializer doesn't include the id by default
153 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -0400154 class Meta:
155 model = Node
156 fields = ('id',
157 'name')
158
Tony Macka2dfb372013-04-09 11:02:32 -0400159class ImageSerializer(serializers.HyperlinkedModelSerializer):
160 # HyperlinkedModelSerializer doesn't include the id by default
161 id = serializers.Field()
Tony Mack53310082013-04-09 09:26:12 -0400162 class Meta:
163 model = Image
Tony Mack879d14a2013-04-09 09:34:19 -0400164 fields = ('id',
165 'image_id',
Tony Mack53310082013-04-09 09:26:12 -0400166 'name',
167 'disk_format',
168 'container_format')
169
Tony Macka28f1cd2013-04-07 20:02:31 -0400170serializerLookUp = {
171 Role: RoleSerializer,
Siobhan Tully30fd4292013-05-10 08:59:56 -0400172 User: UserSerializer,
Tony Macka28f1cd2013-04-07 20:02:31 -0400173 Site: SiteSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400174 SitePrivilege: SitePrivilegeSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400175 Slice: SliceSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400176 SliceMembership: SliceMembershipSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400177 Node: NodeSerializer,
178 Sliver: SliverSerializer,
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400179 Deployment: DeploymentSerializer,
Tony Mack53310082013-04-09 09:26:12 -0400180 Image: ImageSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400181 None: None,
182 }
Tony Mack53310082013-04-09 09:26:12 -0400183