<s> from django . db import transaction <EOL> from rest_framework import serializers <EOL> from ralph . api import RalphAPISerializer , RalphAPIViewSet , router <EOL> from ralph . api . serializers import RalphAPISaveSerializer <EOL> from ralph . assets . api . serializers import ( <EOL> BaseObjectSerializer , <EOL> ServiceEnvironmentSimpleSerializer <EOL> ) <EOL> from ralph . data_center . api . serializers import DataCenterAssetSimpleSerializer <EOL> from ralph . virtual . models import ( <EOL> CloudFlavor , <EOL> CloudHost , <EOL> CloudProject , <EOL> CloudProvider , <EOL> VirtualServer <EOL> ) <EOL> class CloudFlavorSimpleSerializer ( BaseObjectSerializer ) : <EOL> class Meta : <EOL> model = CloudFlavor <EOL> fields = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:url>' ] <EOL> _skip_tags_field = True <EOL> class CloudHostSimpleSerializer ( BaseObjectSerializer ) : <EOL> ip_addresses = serializers . ListField ( ) <EOL> class Meta : <EOL> model = CloudHost <EOL> fields = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:url>' ] <EOL> class CloudProjectSimpleSerializer ( BaseObjectSerializer ) : <EOL> class Meta : <EOL> model = CloudProject <EOL> fields = [ '<STR_LIT:name>' , '<STR_LIT:url>' , '<STR_LIT>' ] <EOL> _skip_tags_field = True <EOL> class SaveCloudFlavorSerializer ( RalphAPISaveSerializer ) : <EOL> cores = serializers . IntegerField ( ) <EOL> memory = serializers . IntegerField ( ) <EOL> disk = serializers . IntegerField ( ) <EOL> @ transaction . atomic <EOL> def create ( self , validated_data ) : <EOL> cores = validated_data . pop ( '<STR_LIT>' ) <EOL> memory = validated_data . pop ( '<STR_LIT>' ) <EOL> disk = validated_data . pop ( '<STR_LIT>' ) <EOL> instance = super ( ) . create ( validated_data ) <EOL> instance . cores = cores <EOL> instance . memory = memory <EOL> instance . disk = disk <EOL> return instance <EOL> class Meta : <EOL> model = CloudFlavor <EOL> exclude = [ '<STR_LIT>' ] <EOL> class SaveCloudHostSerializer ( RalphAPISaveSerializer ) : <EOL> ip_addresses = serializers . ListField ( ) <EOL> def create ( self , validated_data ) : <EOL> ip_addresses = validated_data . pop ( '<STR_LIT>' ) <EOL> instance = super ( ) . create ( validated_data ) <EOL> instance . ip_addresses = ip_addresses <EOL> return instance <EOL> class Meta : <EOL> model = CloudHost <EOL> exclude = [ '<STR_LIT>' ] <EOL> class CloudFlavorSerializer ( BaseObjectSerializer ) : <EOL> cores = serializers . IntegerField ( ) <EOL> memory = serializers . IntegerField ( ) <EOL> disk = serializers . IntegerField ( ) <EOL> class Meta ( BaseObjectSerializer . Meta ) : <EOL> model = CloudFlavor <EOL> exclude = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class CloudHostSerializer ( BaseObjectSerializer ) : <EOL> ip_addresses = serializers . ListField ( ) <EOL> hypervisor = DataCenterAssetSimpleSerializer ( ) <EOL> parent = CloudProjectSimpleSerializer ( source = '<STR_LIT>' ) <EOL> cloudflavor = CloudFlavorSimpleSerializer ( ) <EOL> service_env = ServiceEnvironmentSimpleSerializer ( ) <EOL> class Meta ( BaseObjectSerializer . Meta ) : <EOL> model = CloudHost <EOL> depth = <NUM_LIT:1> <EOL> class CloudProjectSerializer ( BaseObjectSerializer ) : <EOL> cloud_hosts = CloudHostSimpleSerializer ( many = True , source = '<STR_LIT>' ) <EOL> class Meta ( BaseObjectSerializer . Meta ) : <EOL> model = CloudProject <EOL> depth = <NUM_LIT:2> <EOL> exclude = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> class CloudProviderSerializer ( RalphAPISerializer ) : <EOL> class Meta : <EOL> model = CloudProvider <EOL> class VirtualServerSerializer ( BaseObjectSerializer ) : <EOL> class Meta ( BaseObjectSerializer . Meta ) : <EOL> model = VirtualServer <EOL> class CloudFlavorViewSet ( RalphAPIViewSet ) : <EOL> queryset = CloudFlavor . objects . all ( ) <EOL> serializer_class = CloudFlavorSerializer <EOL> save_serializer_class = SaveCloudFlavorSerializer <EOL> prefetch_related = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> class CloudProviderViewSet ( RalphAPIViewSet ) : <EOL> queryset = CloudProvider . objects . all ( ) <EOL> serializer_class = CloudProviderSerializer <EOL> class CloudHostViewSet ( RalphAPIViewSet ) : <EOL> queryset = CloudHost . objects . all ( ) <EOL> serializer_class = CloudHostSerializer <EOL> save_serializer_class = SaveCloudHostSerializer <EOL> select_related = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> prefetch_related = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> class CloudProjectViewSet ( RalphAPIViewSet ) : <EOL> queryset = CloudProject . objects . all ( ) <EOL> serializer_class = CloudProjectSerializer <EOL> prefetch_related = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> class VirtualServerViewSet ( RalphAPIViewSet ) : <EOL> queryset = VirtualServer . objects . all ( ) <EOL> serializer_class = VirtualServerSerializer <EOL> router . register ( r'<STR_LIT>' , CloudFlavorViewSet ) <EOL> router . register ( r'<STR_LIT>' , CloudHostViewSet ) <EOL> router . register ( r'<STR_LIT>' , CloudProjectViewSet ) <EOL> router . register ( r'<STR_LIT>' , CloudProviderViewSet ) <EOL> router . register ( r'<STR_LIT>' , VirtualServerViewSet ) <EOL> urlpatterns = [ ] </s>
