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') |
| 54 | |
| 55 | class Meta: |
| 56 | model = Slice |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 57 | fields = ('id', |
| 58 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 59 | 'name', |
| 60 | 'instantiation', |
| 61 | 'omf_friendly', |
| 62 | 'description', |
| 63 | 'slice_url', |
| 64 | 'site', |
| 65 | 'updated', |
| 66 | 'created') |
| 67 | |
| 68 | class SiteSerializer(serializers.HyperlinkedModelSerializer): |
| 69 | |
| 70 | #Experimenting with whether to use ids, hyperlinks, or nested includes |
| 71 | #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True) |
| 72 | #slices = serializers.RelatedField(many=True, read_only=True) |
| 73 | #slices = SliceSerializer(many=True) |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 74 | # HyperlinkedModelSerializer doesn't include the id by default |
| 75 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 76 | slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail') |
Tony Mack | 6bdc475 | 2013-04-09 01:05:37 -0400 | [diff] [blame] | 77 | deployment_networks = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='sitedeploymentnetwork-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 78 | |
| 79 | class Meta: |
| 80 | model = Site |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 81 | fields = ('id', |
| 82 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 83 | 'name', |
Tony Mack | e1ed6c7 | 2013-04-09 00:34:37 -0400 | [diff] [blame] | 84 | 'deployment_networks', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 85 | 'slices', |
| 86 | 'site_url', |
| 87 | 'enabled', |
| 88 | 'longitude', |
| 89 | 'latitude', |
| 90 | 'login_base', |
Tony Mack | e87bffa | 2013-04-08 23:18:04 -0400 | [diff] [blame] | 91 | 'tenant_id', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 92 | 'is_public', |
| 93 | 'abbreviated_name', |
| 94 | 'updated', |
| 95 | 'created') |
| 96 | |
| 97 | class DeploymentNetworkSerializer(serializers.HyperlinkedModelSerializer): |
| 98 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 99 | # HyperlinkedModelSerializer doesn't include the id by default |
| 100 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 101 | sites = serializers.HyperlinkedRelatedField(view_name='sitedeploymentnetwork-detail') |
| 102 | class Meta: |
| 103 | model = DeploymentNetwork |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 104 | fields = ('id', |
| 105 | 'name', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 106 | 'sites' |
| 107 | ) |
| 108 | |
| 109 | class SiteDeploymentNetworkSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 110 | # HyperlinkedModelSerializer doesn't include the id by default |
| 111 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 112 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
| 113 | deploymentNetwork = serializers.HyperlinkedRelatedField(view_name='deploymentnetwork-detail') |
| 114 | |
| 115 | class Meta: |
| 116 | model = SiteDeploymentNetwork |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 117 | fields = ('id', |
| 118 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 119 | 'site', |
| 120 | 'deploymentNetwork') |
| 121 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 122 | class SliverSerializer(serializers.HyperlinkedModelSerializer): |
| 123 | # HyperlinkedModelSerializer doesn't include the id by default |
| 124 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 125 | slice = serializers.RelatedField(read_only=True) |
| 126 | #slice = serializers.PrimaryKeyRelatedField(read_only=True) |
| 127 | |
| 128 | class Meta: |
| 129 | model = Sliver |
| 130 | fields = ('id', |
| 131 | 'slice', |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 132 | 'name') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 133 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 134 | class NodeSerializer(serializers.HyperlinkedModelSerializer): |
| 135 | # HyperlinkedModelSerializer doesn't include the id by default |
| 136 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 137 | class Meta: |
| 138 | model = Node |
| 139 | fields = ('id', |
| 140 | 'name') |
| 141 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 142 | class ImageSerializer(serializers.HyperlinkedModelSerializer): |
| 143 | # HyperlinkedModelSerializer doesn't include the id by default |
| 144 | id = serializers.Field() |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 145 | class Meta: |
| 146 | model = Image |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 147 | fields = ('id', |
| 148 | 'image_id', |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 149 | 'name', |
| 150 | 'disk_format', |
| 151 | 'container_format') |
| 152 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 153 | class FlavorSerializer(serializers.HyperlinkedModelSerializer): |
| 154 | # HyperlinkedModelSerializer doesn't include the id by default |
| 155 | id = serializers.Field() |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 156 | class Meta: |
| 157 | model = Flavor |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 158 | fields = ('id', |
| 159 | 'flavor_id', |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 160 | 'name', |
| 161 | 'memory_mb', |
| 162 | 'disk_gb', |
| 163 | 'vcpus') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 164 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 165 | serializerLookUp = { |
| 166 | Role: RoleSerializer, |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 167 | User: UserSerializer, |
Tony Mack | e4cee7a | 2013-04-09 12:45:32 -0400 | [diff] [blame] | 168 | Key: KeySerializer, |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 169 | Site: SiteSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 170 | Slice: SliceSerializer, |
| 171 | Node: NodeSerializer, |
| 172 | Sliver: SliverSerializer, |
| 173 | DeploymentNetwork: DeploymentNetworkSerializer, |
| 174 | SiteDeploymentNetwork: SiteDeploymentNetworkSerializer, |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 175 | Image: ImageSerializer, |
| 176 | Flavor: FlavorSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 177 | None: None, |
| 178 | } |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 179 | |