Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 1 | from django.forms import widgets |
| 2 | from rest_framework import serializers |
Tony Mack | f1c1224 | 2013-04-09 16:08:43 -0400 | [diff] [blame] | 3 | from plstackapi.core.models import * |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 4 | |
| 5 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 6 | class RoleSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 7 | # HyperlinkedModelSerializer doesn't include the id by default |
| 8 | id = serializers.Field() |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 9 | class Meta: |
| 10 | model = Role |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 11 | fields = ('id', |
| 12 | 'role_id', |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 13 | 'role_type') |
| 14 | |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 15 | |
| 16 | class UserSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 17 | # HyperlinkedModelSerializer doesn't include the id by default |
| 18 | id = serializers.Field() |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 19 | 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: |
Tony Mack | 0e723b9 | 2013-04-27 11:08:19 -0400 | [diff] [blame] | 23 | model = PLUser |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 24 | fields = ('id', |
| 25 | 'user_id', |
| 26 | 'firstname', |
| 27 | 'lastname', |
| 28 | 'email', |
Tony Mack | 8484bdb | 2013-04-14 20:26:03 -0400 | [diff] [blame] | 29 | 'password', |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 30 | 'phone', |
| 31 | 'user_url', |
| 32 | 'is_admin', |
| 33 | 'site', |
| 34 | 'slice_memberships', |
| 35 | 'site_privileges') |
| 36 | |
Tony Mack | e4cee7a | 2013-04-09 12:45:32 -0400 | [diff] [blame] | 37 | class 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 Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 49 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 50 | class SliceSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 51 | # HyperlinkedModelSerializer doesn't include the id by default |
| 52 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 53 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 54 | slivers = serializers.HyperlinkedRelatedField(view_name='sliver-detail') |
Tony Mack | 771f4b9 | 2013-04-12 01:49:57 -0400 | [diff] [blame] | 55 | subnet= serializers.HyperlinkedRelatedField(view_name='subnet-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 56 | class Meta: |
| 57 | model = Slice |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 58 | fields = ('id', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 59 | 'tenant_id', |
| 60 | 'enabled', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 61 | 'name', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 62 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 63 | 'instantiation', |
| 64 | 'omf_friendly', |
| 65 | 'description', |
| 66 | 'slice_url', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 67 | 'network_id', |
| 68 | 'router_id', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 69 | 'site', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 70 | 'slivers', |
Tony Mack | 771f4b9 | 2013-04-12 01:49:57 -0400 | [diff] [blame] | 71 | 'subnet', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 72 | 'updated', |
| 73 | 'created') |
| 74 | |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 75 | class 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 | |
| 87 | class 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 Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 100 | class 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 Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 106 | # HyperlinkedModelSerializer doesn't include the id by default |
| 107 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 108 | slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 109 | |
| 110 | class Meta: |
| 111 | model = Site |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 112 | fields = ('id', |
| 113 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 114 | 'name', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 115 | 'slices', |
| 116 | 'site_url', |
| 117 | 'enabled', |
| 118 | 'longitude', |
| 119 | 'latitude', |
| 120 | 'login_base', |
Tony Mack | e87bffa | 2013-04-08 23:18:04 -0400 | [diff] [blame] | 121 | 'tenant_id', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 122 | 'is_public', |
| 123 | 'abbreviated_name', |
| 124 | 'updated', |
| 125 | 'created') |
| 126 | |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 127 | class 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 Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 139 | class DeploymentNetworkSerializer(serializers.HyperlinkedModelSerializer): |
| 140 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 141 | # HyperlinkedModelSerializer doesn't include the id by default |
| 142 | id = serializers.Field() |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 143 | sites = serializers.HyperlinkedRelatedField(view_name='deploymentnetwork-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 144 | class Meta: |
| 145 | model = DeploymentNetwork |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 146 | fields = ('id', |
| 147 | 'name', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 148 | 'sites' |
| 149 | ) |
| 150 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 151 | class SliverSerializer(serializers.HyperlinkedModelSerializer): |
| 152 | # HyperlinkedModelSerializer doesn't include the id by default |
| 153 | id = serializers.Field() |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 154 | 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 Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 162 | #slice = serializers.PrimaryKeyRelatedField(read_only=True) |
| 163 | |
| 164 | class Meta: |
| 165 | model = Sliver |
| 166 | fields = ('id', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 167 | 'instance_id', |
Tony Mack | 5d6598c | 2013-04-12 12:45:02 -0400 | [diff] [blame] | 168 | 'name', |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 169 | 'ip', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 170 | 'flavor', |
| 171 | 'image', |
Tony Mack | 5d6598c | 2013-04-12 12:45:02 -0400 | [diff] [blame] | 172 | 'key', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 173 | 'slice', |
Tony Mack | 5d6598c | 2013-04-12 12:45:02 -0400 | [diff] [blame] | 174 | 'deploymentNetwork', |
| 175 | 'node') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 176 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 177 | class NodeSerializer(serializers.HyperlinkedModelSerializer): |
| 178 | # HyperlinkedModelSerializer doesn't include the id by default |
| 179 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 180 | class Meta: |
| 181 | model = Node |
| 182 | fields = ('id', |
| 183 | 'name') |
| 184 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 185 | class ImageSerializer(serializers.HyperlinkedModelSerializer): |
| 186 | # HyperlinkedModelSerializer doesn't include the id by default |
| 187 | id = serializers.Field() |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 188 | class Meta: |
| 189 | model = Image |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 190 | fields = ('id', |
| 191 | 'image_id', |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 192 | 'name', |
| 193 | 'disk_format', |
| 194 | 'container_format') |
| 195 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 196 | class FlavorSerializer(serializers.HyperlinkedModelSerializer): |
| 197 | # HyperlinkedModelSerializer doesn't include the id by default |
| 198 | id = serializers.Field() |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 199 | class Meta: |
| 200 | model = Flavor |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 201 | fields = ('id', |
| 202 | 'flavor_id', |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 203 | 'name', |
| 204 | 'memory_mb', |
| 205 | 'disk_gb', |
| 206 | 'vcpus') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 207 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 208 | serializerLookUp = { |
| 209 | Role: RoleSerializer, |
Tony Mack | 0e723b9 | 2013-04-27 11:08:19 -0400 | [diff] [blame] | 210 | PLUser: UserSerializer, |
Tony Mack | e4cee7a | 2013-04-09 12:45:32 -0400 | [diff] [blame] | 211 | Key: KeySerializer, |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 212 | Site: SiteSerializer, |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 213 | SitePrivilege: SitePrivilegeSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 214 | Slice: SliceSerializer, |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 215 | SliceMembership: SliceMembershipSerializer, |
| 216 | Subnet: SubnetSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 217 | Node: NodeSerializer, |
| 218 | Sliver: SliverSerializer, |
| 219 | DeploymentNetwork: DeploymentNetworkSerializer, |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 220 | Image: ImageSerializer, |
| 221 | Flavor: FlavorSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 222 | None: None, |
| 223 | } |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 224 | |