blob: 3692d1d13e93be2f0acdf5022fa955698bfb408e [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()
9
Tony Macka28f1cd2013-04-07 20:02:31 -040010 class Meta:
11 model = Role
Tony Mack879d14a2013-04-09 09:34:19 -040012 fields = ('id',
13 'role_id',
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:
24 model = User
25 fields = ('id',
26 'user_id',
27 'firstname',
28 'lastname',
29 'email',
30 '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 Mack29c287f2013-04-11 21:07:16 -0400169 'flavor',
170 'image',
Tony Mack5d6598c2013-04-12 12:45:02 -0400171 'key',
Tony Mack7130ac32013-03-22 21:58:00 -0400172 'slice',
Tony Mack5d6598c2013-04-12 12:45:02 -0400173 'deploymentNetwork',
174 'node')
Tony Mack7130ac32013-03-22 21:58:00 -0400175
Tony Macka2dfb372013-04-09 11:02:32 -0400176class NodeSerializer(serializers.HyperlinkedModelSerializer):
177 # HyperlinkedModelSerializer doesn't include the id by default
178 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -0400179 class Meta:
180 model = Node
181 fields = ('id',
182 'name')
183
Tony Macka2dfb372013-04-09 11:02:32 -0400184class ImageSerializer(serializers.HyperlinkedModelSerializer):
185 # HyperlinkedModelSerializer doesn't include the id by default
186 id = serializers.Field()
Tony Mack53310082013-04-09 09:26:12 -0400187 class Meta:
188 model = Image
Tony Mack879d14a2013-04-09 09:34:19 -0400189 fields = ('id',
190 'image_id',
Tony Mack53310082013-04-09 09:26:12 -0400191 'name',
192 'disk_format',
193 'container_format')
194
Tony Macka2dfb372013-04-09 11:02:32 -0400195class FlavorSerializer(serializers.HyperlinkedModelSerializer):
196 # HyperlinkedModelSerializer doesn't include the id by default
197 id = serializers.Field()
Tony Mack53310082013-04-09 09:26:12 -0400198 class Meta:
199 model = Flavor
Tony Mack879d14a2013-04-09 09:34:19 -0400200 fields = ('id',
201 'flavor_id',
Tony Mack53310082013-04-09 09:26:12 -0400202 'name',
203 'memory_mb',
204 'disk_gb',
205 'vcpus')
Tony Mack7130ac32013-03-22 21:58:00 -0400206
Tony Macka28f1cd2013-04-07 20:02:31 -0400207serializerLookUp = {
208 Role: RoleSerializer,
Tony Macka2dfb372013-04-09 11:02:32 -0400209 User: UserSerializer,
Tony Macke4cee7a2013-04-09 12:45:32 -0400210 Key: KeySerializer,
Tony Macka28f1cd2013-04-07 20:02:31 -0400211 Site: SiteSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400212 SitePrivilege: SitePrivilegeSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400213 Slice: SliceSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400214 SliceMembership: SliceMembershipSerializer,
215 Subnet: SubnetSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400216 Node: NodeSerializer,
217 Sliver: SliverSerializer,
218 DeploymentNetwork: DeploymentNetworkSerializer,
Tony Mack53310082013-04-09 09:26:12 -0400219 Image: ImageSerializer,
220 Flavor: FlavorSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400221 None: None,
222 }
Tony Mack53310082013-04-09 09:26:12 -0400223