blob: 94f5c3c7b7b20c2573c553331e2e877245a2492f [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',
Siobhan Tully47ae1b52013-05-10 15:53:14 -040012 'role',
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')
Siobhan Tully5d7dc8d2013-07-02 13:17:33 -040021 site_privileges = serializers.HyperlinkedRelatedField(view_name='siteprivilege-detail')
Tony Mack5cc16ba2013-04-09 10:30:45 -040022 class Meta:
Siobhan Tully30fd4292013-05-10 08:59:56 -040023 model = User
Tony Mack5cc16ba2013-04-09 10:30:45 -040024 fields = ('id',
Siobhan Tully30fd4292013-05-10 08:59:56 -040025 'kuser_id',
Tony Mack5cc16ba2013-04-09 10:30:45 -040026 'firstname',
27 'lastname',
28 'email',
Tony Mackb0d97422013-06-10 09:57:45 -040029 'password',
30 'phone',
31 'public_key',
Tony Mack5cc16ba2013-04-09 10:30:45 -040032 'user_url',
33 'is_admin',
34 'site',
35 'slice_memberships',
36 'site_privileges')
37
Tony Mack7130ac32013-03-22 21:58:00 -040038class SliceSerializer(serializers.HyperlinkedModelSerializer):
Tony Macka2dfb372013-04-09 11:02:32 -040039 # HyperlinkedModelSerializer doesn't include the id by default
40 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -040041 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
Tony Mack3a1af412013-04-09 22:36:27 -040042 slivers = serializers.HyperlinkedRelatedField(view_name='sliver-detail')
Tony Mack7130ac32013-03-22 21:58:00 -040043 class Meta:
44 model = Slice
Tony Mack879d14a2013-04-09 09:34:19 -040045 fields = ('id',
Tony Mack3a1af412013-04-09 22:36:27 -040046 'tenant_id',
47 'enabled',
Tony Mack7130ac32013-03-22 21:58:00 -040048 'name',
Tony Mack3a1af412013-04-09 22:36:27 -040049 'url',
Tony Mack7130ac32013-03-22 21:58:00 -040050 'omf_friendly',
51 'description',
52 'slice_url',
Tony Mack3a1af412013-04-09 22:36:27 -040053 'network_id',
54 'router_id',
Tony Mack1e7169e2013-05-07 11:09:57 -040055 'subnet_id',
Tony Mack7130ac32013-03-22 21:58:00 -040056 'site',
Tony Mack3a1af412013-04-09 22:36:27 -040057 'slivers',
Tony Mack7130ac32013-03-22 21:58:00 -040058 'updated',
59 'created')
60
Tony Mack29c287f2013-04-11 21:07:16 -040061class SliceMembershipSerializer(serializers.HyperlinkedModelSerializer):
62 id = serializers.Field()
63 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
64 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
65 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
66 class Meta:
Siobhan Tully5d7dc8d2013-07-02 13:17:33 -040067 model = SliceMembership
Tony Mack29c287f2013-04-11 21:07:16 -040068 fields = ('id',
69 'user',
70 'slice',
71 'role')
72
Tony Mack7130ac32013-03-22 21:58:00 -040073class SiteSerializer(serializers.HyperlinkedModelSerializer):
74
75 #Experimenting with whether to use ids, hyperlinks, or nested includes
76 #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
77 #slices = serializers.RelatedField(many=True, read_only=True)
78 #slices = SliceSerializer(many=True)
Tony Macka2dfb372013-04-09 11:02:32 -040079 # HyperlinkedModelSerializer doesn't include the id by default
80 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -040081 slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail')
Tony Mack7130ac32013-03-22 21:58:00 -040082
83 class Meta:
84 model = Site
Tony Mack879d14a2013-04-09 09:34:19 -040085 fields = ('id',
86 'url',
Tony Mack7130ac32013-03-22 21:58:00 -040087 'name',
Tony Mack7130ac32013-03-22 21:58:00 -040088 'slices',
89 'site_url',
90 'enabled',
91 'longitude',
92 'latitude',
93 'login_base',
Tony Macke87bffa2013-04-08 23:18:04 -040094 'tenant_id',
Tony Mack7130ac32013-03-22 21:58:00 -040095 'is_public',
96 'abbreviated_name',
97 'updated',
98 'created')
99
Tony Mack29c287f2013-04-11 21:07:16 -0400100class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
101 id = serializers.Field()
102 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
103 user = serializers.HyperlinkedRelatedField(view_name='user-detail')
104 role = serializers.HyperlinkedRelatedField(view_name='role-detail')
105 class Meta:
106 model = SitePrivilege
107 fields = ('id',
108 'user',
109 'site',
110 'role')
111
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400112class DeploymentSerializer(serializers.HyperlinkedModelSerializer):
Tony Mack7130ac32013-03-22 21:58:00 -0400113
Tony Macka2dfb372013-04-09 11:02:32 -0400114 # HyperlinkedModelSerializer doesn't include the id by default
115 id = serializers.Field()
Siobhan Tully5d7dc8d2013-07-02 13:17:33 -0400116 sites = serializers.HyperlinkedRelatedField(view_name='site-detail')
Tony Mack7130ac32013-03-22 21:58:00 -0400117 class Meta:
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400118 model = Deployment
Tony Mack879d14a2013-04-09 09:34:19 -0400119 fields = ('id',
120 'name',
Tony Mack7130ac32013-03-22 21:58:00 -0400121 'sites'
122 )
123
Tony Macka2dfb372013-04-09 11:02:32 -0400124class SliverSerializer(serializers.HyperlinkedModelSerializer):
125 # HyperlinkedModelSerializer doesn't include the id by default
126 id = serializers.Field()
Tony Mack29c287f2013-04-11 21:07:16 -0400127 image = serializers.HyperlinkedRelatedField(view_name='image-detail')
Tony Mack29c287f2013-04-11 21:07:16 -0400128 slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
Siobhan Tully5d7dc8d2013-07-02 13:17:33 -0400129 deployment = serializers.HyperlinkedRelatedField(view_name='deployment-detail')
Tony Mack29c287f2013-04-11 21:07:16 -0400130 node = serializers.HyperlinkedRelatedField(view_name='node-detail')
131
132
Tony Mack7130ac32013-03-22 21:58:00 -0400133 #slice = serializers.PrimaryKeyRelatedField(read_only=True)
134
135 class Meta:
136 model = Sliver
137 fields = ('id',
Tony Mack29c287f2013-04-11 21:07:16 -0400138 'instance_id',
Tony Mack5d6598c2013-04-12 12:45:02 -0400139 'name',
Tony Mack79748612013-05-01 14:52:03 -0400140 'instance_name',
Tony Mackd90cdbf2013-04-16 22:48:40 -0400141 'ip',
Tony Mack29c287f2013-04-11 21:07:16 -0400142 'image',
Tony Mack7130ac32013-03-22 21:58:00 -0400143 'slice',
Siobhan Tully5d7dc8d2013-07-02 13:17:33 -0400144 'deployment',
Tony Mack5d6598c2013-04-12 12:45:02 -0400145 'node')
Tony Mack7130ac32013-03-22 21:58:00 -0400146
Tony Macka2dfb372013-04-09 11:02:32 -0400147class NodeSerializer(serializers.HyperlinkedModelSerializer):
148 # HyperlinkedModelSerializer doesn't include the id by default
149 id = serializers.Field()
Tony Mack7130ac32013-03-22 21:58:00 -0400150 class Meta:
151 model = Node
152 fields = ('id',
153 'name')
154
Tony Macka2dfb372013-04-09 11:02:32 -0400155class ImageSerializer(serializers.HyperlinkedModelSerializer):
156 # HyperlinkedModelSerializer doesn't include the id by default
157 id = serializers.Field()
Tony Mack53310082013-04-09 09:26:12 -0400158 class Meta:
159 model = Image
Tony Mack879d14a2013-04-09 09:34:19 -0400160 fields = ('id',
161 'image_id',
Tony Mack53310082013-04-09 09:26:12 -0400162 'name',
163 'disk_format',
164 'container_format')
165
Tony Macka28f1cd2013-04-07 20:02:31 -0400166serializerLookUp = {
167 Role: RoleSerializer,
Siobhan Tully30fd4292013-05-10 08:59:56 -0400168 User: UserSerializer,
Tony Macka28f1cd2013-04-07 20:02:31 -0400169 Site: SiteSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400170 SitePrivilege: SitePrivilegeSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400171 Slice: SliceSerializer,
Tony Mack29c287f2013-04-11 21:07:16 -0400172 SliceMembership: SliceMembershipSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400173 Node: NodeSerializer,
174 Sliver: SliverSerializer,
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400175 Deployment: DeploymentSerializer,
Tony Mack53310082013-04-09 09:26:12 -0400176 Image: ImageSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -0400177 None: None,
178 }
Tony Mack53310082013-04-09 09:26:12 -0400179