blob: 2b703579ab357dbe2b5ef41e7cda99852511d116 [file] [log] [blame]
Tony Mack7130ac32013-03-22 21:58:00 -04001from django.forms import widgets
2from rest_framework import serializers
Tony Mackf1c12242013-04-09 16:08:43 -04003from plstackapi.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',
Tony Macka28f1cd2013-04-07 20:02:31 -040013 'role_type')
14
Tony Mack5cc16ba2013-04-09 10:30:45 -040015
16class UserSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -040017 # HyperlinkedModelSerializer doesn't include the id by default
18 id = serializers.Field()
Tony Mack5cc16ba2013-04-09 10:30:45 -040019 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
20 slice_memberships = serializers.HyperlinkedRelatedField(view_name='slice-membership-detail')
21 site_privileges = serializers.HyperlinkedRelatedField(view_name='site-privilege-detail')
22 class Meta:
23 model = User
24 fields = ('id',
25 'user_id',
26 'firstname',
27 'lastname',
28 'email',
Tony Mack8484bdb2013-04-14 20:26:03 -040029 'password',
Tony Mack5cc16ba2013-04-09 10:30:45 -040030 'phone',
31 'user_url',
32 'is_admin',
33 'site',
34 'slice_memberships',
35 'site_privileges')
36
Tony Macke4cee7a2013-04-09 12:45:32 -040037class KeySerializer(serializers.HyperlinkedModelSerializer):
38 id = serializers.Field()
39 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
40 class Meta:
41 model = Key
42 fields = ('id',
43 'name',
44 'key',
45 'type',
46 'blacklisted',
47 'user')
48
Tony Mack5cc16ba2013-04-09 10:30:45 -040049
Tony Mack7130ac32013-03-22 21:58:00 -040050class SliceSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -040051 # HyperlinkedModelSerializer doesn't include the id by default
52 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -040053 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
Tony Mack3a1af412013-04-09 22:36:27 -040054 slivers = serializers.HyperlinkedRelatedField(view_name='sliver-detail')
Tony Mack771f4b92013-04-12 01:49:57 -040055 subnet= serializers.HyperlinkedRelatedField(view_name='subnet-detail')
Tony Mack7130ac32013-03-22 21:58:00 -040056 class Meta:
57 model = Slice
Tony Mack879d14a2013-04-09 09:34:19 -040058 fields = ('id',
Tony Mack3a1af412013-04-09 22:36:27 -040059 'tenant_id',
60 'enabled',
Tony Mack7130ac32013-03-22 21:58:00 -040061 'name',
Tony Mack3a1af412013-04-09 22:36:27 -040062 'url',
Tony Mack7130ac32013-03-22 21:58:00 -040063 'instantiation',
64 'omf_friendly',
65 'description',
66 'slice_url',
Tony Mack3a1af412013-04-09 22:36:27 -040067 'network_id',
68 'router_id',
Tony Mack7130ac32013-03-22 21:58:00 -040069 'site',
Tony Mack3a1af412013-04-09 22:36:27 -040070 'slivers',
Tony Mack771f4b92013-04-12 01:49:57 -040071 'subnet',
Tony Mack7130ac32013-03-22 21:58:00 -040072 'updated',
73 'created')
74
Tony Mack29c287f2013-04-11 21:07:16 -040075class SliceMembershipSerializer(serializers.HyperlinkedModelSerializer):
76 id = serializers.Field()
77 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
78 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
79 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
80 class Meta:
81 model = SitePrivilege
82 fields = ('id',
83 'user',
84 'slice',
85 'role')
86
87class SubnetSerializer(serializers.HyperlinkedModelSerializer):
88 id = serializers.Field()
89 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
90 class Meta:
91 model = Subnet
92 fields = ('id',
93 'subnet_id',
94 'cidr',
95 'ip_version',
96 'start',
97 'end',
98 'slice')
99
Tony Mack7130ac32013-03-22 21:58:00 -0400100class SiteSerializer(serializers.HyperlinkedModelSerializer):
101
102 #Experimenting with whether to use ids, hyperlinks, or nested includes
103 #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
104 #slices = serializers.RelatedField(many=True, read_only=True)
105 #slices = SliceSerializer(many=True)
Tony Macka2dfb372013-04-09 11:02:32 -0400106 # HyperlinkedModelSerializer doesn't include the id by default
107 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -0400108 slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400109
110 class Meta:
111 model = Site
Tony Mack879d14a2013-04-09 09:34:19 -0400112 fields = ('id',
113 'url',
Tony Mack7130ac32013-03-22 21:58:00 -0400114 'name',
Tony Mack7130ac32013-03-22 21:58:00 -0400115 'slices',
116 'site_url',
117 'enabled',
118 'longitude',
119 'latitude',
120 'login_base',
Tony Macke87bffa2013-04-08 23:18:04 -0400121 'tenant_id',
Tony Mack7130ac32013-03-22 21:58:00 -0400122 'is_public',
123 'abbreviated_name',
124 'updated',
125 'created')
126
Tony Mack29c287f2013-04-11 21:07:16 -0400127class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
128 id = serializers.Field()
129 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
130 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
131 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
132 class Meta:
133 model = SitePrivilege
134 fields = ('id',
135 'user',
136 'site',
137 'role')
138
Tony Mack7130ac32013-03-22 21:58:00 -0400139class DeploymentNetworkSerializer(serializers.HyperlinkedModelSerializer):
140
Tony Macka2dfb372013-04-09 11:02:32 -0400141 # HyperlinkedModelSerializer doesn't include the id by default
142 id = serializers.Field()
Tony Mack29c287f2013-04-11 21:07:16 -0400143 sites = serializers.HyperlinkedRelatedField(view_name='deploymentnetwork-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400144 class Meta:
145 model = DeploymentNetwork
Tony Mack879d14a2013-04-09 09:34:19 -0400146 fields = ('id',
147 'name',
Tony Mack7130ac32013-03-22 21:58:00 -0400148 'sites'
149 )
150
Tony Macka2dfb372013-04-09 11:02:32 -0400151class SliverSerializer(serializers.HyperlinkedModelSerializer):
152 # HyperlinkedModelSerializer doesn't include the id by default
153 id = serializers.Field()
Tony Mack29c287f2013-04-11 21:07:16 -0400154 flavor = serializers.HyperlinkedRelatedField(view_name='flavor-detail')
155 image = serializers.HyperlinkedRelatedField(view_name='image-detail')
156 key = serializers.HyperlinkedRelatedField(view_name='key-detail')
157 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
158 deployment_network = serializers.HyperlinkedRelatedField(view_name='deployment_network-detail')
159 node = serializers.HyperlinkedRelatedField(view_name='node-detail')
160
161
Tony Mack7130ac32013-03-22 21:58:00 -0400162 #slice = serializers.PrimaryKeyRelatedField(read_only=True)
163
164 class Meta:
165 model = Sliver
166 fields = ('id',
Tony Mack29c287f2013-04-11 21:07:16 -0400167 'instance_id',
Tony Mack5d6598c2013-04-12 12:45:02 -0400168 'name',
Tony Mackd90cdbf2013-04-16 22:48:40 -0400169 'ip',
Tony Mack29c287f2013-04-11 21:07:16 -0400170 'flavor',
171 'image',
Tony Mack5d6598c2013-04-12 12:45:02 -0400172 'key',
Tony Mack7130ac32013-03-22 21:58:00 -0400173 'slice',
Tony Mack5d6598c2013-04-12 12:45:02 -0400174 'deploymentNetwork',
175 'node')
Tony Mack7130ac32013-03-22 21:58:00 -0400176
Tony Macka2dfb372013-04-09 11:02:32 -0400177class NodeSerializer(serializers.HyperlinkedModelSerializer):
178 # HyperlinkedModelSerializer doesn't include the id by default
179 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -0400180 class Meta:
181 model = Node
182 fields = ('id',
183 'name')
184
Tony Macka2dfb372013-04-09 11:02:32 -0400185class ImageSerializer(serializers.HyperlinkedModelSerializer):
186 # HyperlinkedModelSerializer doesn't include the id by default
187 id = serializers.Field()
Tony Mack53310082013-04-09 09:26:12 -0400188 class Meta:
189 model = Image
Tony Mack879d14a2013-04-09 09:34:19 -0400190 fields = ('id',
191 'image_id',
Tony Mack53310082013-04-09 09:26:12 -0400192 'name',
193 'disk_format',
194 'container_format')
195
Tony Macka2dfb372013-04-09 11:02:32 -0400196class FlavorSerializer(serializers.HyperlinkedModelSerializer):
197 # HyperlinkedModelSerializer doesn't include the id by default
198 id = serializers.Field()
Tony Mack53310082013-04-09 09:26:12 -0400199 class Meta:
200 model = Flavor
Tony Mack879d14a2013-04-09 09:34:19 -0400201 fields = ('id',
202 'flavor_id',
Tony Mack53310082013-04-09 09:26:12 -0400203 'name',
204 'memory_mb',
205 'disk_gb',
206 'vcpus')
Tony Mack7130ac32013-03-22 21:58:00 -0400207
Tony Macka28f1cd2013-04-07 20:02:31 -0400208serializerLookUp = {
209 Role: RoleSerializer,
Tony Macka2dfb372013-04-09 11:02:32 -0400210 User: UserSerializer,
Tony Macke4cee7a2013-04-09 12:45:32 -0400211 Key: KeySerializer,
Tony Macka28f1cd2013-04-07 20:02:31 -0400212 Site: SiteSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400213 SitePrivilege: SitePrivilegeSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400214 Slice: SliceSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400215 SliceMembership: SliceMembershipSerializer,
216 Subnet: SubnetSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400217 Node: NodeSerializer,
218 Sliver: SliverSerializer,
219 DeploymentNetwork: DeploymentNetworkSerializer,
Tony Mack53310082013-04-09 09:26:12 -0400220 Image: ImageSerializer,
221 Flavor: FlavorSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400222 None: None,
223 }
Tony Mack53310082013-04-09 09:26:12 -0400224