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() |
| 9 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 10 | class Meta: |
| 11 | model = Role |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 12 | fields = ('id', |
| 13 | 'role_id', |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 14 | 'role_type') |
| 15 | |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 16 | |
| 17 | class UserSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 18 | # HyperlinkedModelSerializer doesn't include the id by default |
| 19 | id = serializers.Field() |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 20 | 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 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 | 930355f | 2013-04-09 23:23:24 -0400 | [diff] [blame] | 55 | subnets = 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', |
| 71 | 'subnets', |
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 | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 109 | deployment_networks = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='deploymentnetwork-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 110 | |
| 111 | class Meta: |
| 112 | model = Site |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 113 | fields = ('id', |
| 114 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 115 | 'name', |
Tony Mack | e1ed6c7 | 2013-04-09 00:34:37 -0400 | [diff] [blame] | 116 | 'deployment_networks', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 117 | 'slices', |
| 118 | 'site_url', |
| 119 | 'enabled', |
| 120 | 'longitude', |
| 121 | 'latitude', |
| 122 | 'login_base', |
Tony Mack | e87bffa | 2013-04-08 23:18:04 -0400 | [diff] [blame] | 123 | 'tenant_id', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 124 | 'is_public', |
| 125 | 'abbreviated_name', |
| 126 | 'updated', |
| 127 | 'created') |
| 128 | |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 129 | class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer): |
| 130 | id = serializers.Field() |
| 131 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
| 132 | user = serializers.HyperlinkedRelatedField(view_name='user-detail') |
| 133 | role = serializers.HyperlinkedRelatedField(view_name='role-detail') |
| 134 | class Meta: |
| 135 | model = SitePrivilege |
| 136 | fields = ('id', |
| 137 | 'user', |
| 138 | 'site', |
| 139 | 'role') |
| 140 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 141 | class DeploymentNetworkSerializer(serializers.HyperlinkedModelSerializer): |
| 142 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 143 | # HyperlinkedModelSerializer doesn't include the id by default |
| 144 | id = serializers.Field() |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 145 | sites = serializers.HyperlinkedRelatedField(view_name='deploymentnetwork-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 146 | class Meta: |
| 147 | model = DeploymentNetwork |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 148 | fields = ('id', |
| 149 | 'name', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 150 | 'sites' |
| 151 | ) |
| 152 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 153 | class SliverSerializer(serializers.HyperlinkedModelSerializer): |
| 154 | # HyperlinkedModelSerializer doesn't include the id by default |
| 155 | id = serializers.Field() |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 156 | flavor = serializers.HyperlinkedRelatedField(view_name='flavor-detail') |
| 157 | image = serializers.HyperlinkedRelatedField(view_name='image-detail') |
| 158 | key = serializers.HyperlinkedRelatedField(view_name='key-detail') |
| 159 | slice = serializers.HyperlinkedRelatedField(view_name='slice-detail') |
| 160 | deployment_network = serializers.HyperlinkedRelatedField(view_name='deployment_network-detail') |
| 161 | node = serializers.HyperlinkedRelatedField(view_name='node-detail') |
| 162 | |
| 163 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 164 | #slice = serializers.PrimaryKeyRelatedField(read_only=True) |
| 165 | |
| 166 | class Meta: |
| 167 | model = Sliver |
| 168 | fields = ('id', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 169 | 'instance_id', |
| 170 | 'name' |
| 171 | 'flavor', |
| 172 | 'image', |
| 173 | 'key' |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 174 | 'slice', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 175 | 'deployment_network', |
| 176 | 'noode') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 177 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 178 | class NodeSerializer(serializers.HyperlinkedModelSerializer): |
| 179 | # HyperlinkedModelSerializer doesn't include the id by default |
| 180 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 181 | class Meta: |
| 182 | model = Node |
| 183 | fields = ('id', |
| 184 | 'name') |
| 185 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 186 | class ImageSerializer(serializers.HyperlinkedModelSerializer): |
| 187 | # HyperlinkedModelSerializer doesn't include the id by default |
| 188 | id = serializers.Field() |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 189 | class Meta: |
| 190 | model = Image |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 191 | fields = ('id', |
| 192 | 'image_id', |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 193 | 'name', |
| 194 | 'disk_format', |
| 195 | 'container_format') |
| 196 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 197 | class FlavorSerializer(serializers.HyperlinkedModelSerializer): |
| 198 | # HyperlinkedModelSerializer doesn't include the id by default |
| 199 | id = serializers.Field() |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 200 | class Meta: |
| 201 | model = Flavor |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 202 | fields = ('id', |
| 203 | 'flavor_id', |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 204 | 'name', |
| 205 | 'memory_mb', |
| 206 | 'disk_gb', |
| 207 | 'vcpus') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 208 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 209 | serializerLookUp = { |
| 210 | Role: RoleSerializer, |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 211 | User: UserSerializer, |
Tony Mack | e4cee7a | 2013-04-09 12:45:32 -0400 | [diff] [blame] | 212 | Key: KeySerializer, |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 213 | Site: SiteSerializer, |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 214 | SitePrivilege: SitePrivilegeSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 215 | Slice: SliceSerializer, |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 216 | SliceMembership: SliceMembershipSerializer, |
| 217 | Subnet: SubnetSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 218 | Node: NodeSerializer, |
| 219 | Sliver: SliverSerializer, |
| 220 | DeploymentNetwork: DeploymentNetworkSerializer, |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 221 | Image: ImageSerializer, |
| 222 | Flavor: FlavorSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 223 | None: None, |
| 224 | } |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 225 | |