def to_internal_value(self, data):
        """
        Overwrite to force custom logic required before accepting data to launch an instance.
        1. check of identity prior to checking size_alias or source_alias
        NOTE: This is required because we have identical alias' on multiple providers, so we must first filter-down based on the identity requested for launching the instance.
        2. Check source_alias is either a Volume or a ProviderMachine before continuing.
        """
        # For now-- It's okay to omit this.
        project = data.get('project')
        if not project:
            data['project'] = None

        identity_uuid = data.get('identity')
        if not identity_uuid:
            raise ValidationError({
                'identity': 'This field is required.'
            })
        provider_queryset = self.fields['provider_uuid'].queryset

        source_alias = data.get('source_alias')
        if not source_alias:
            raise ValidationError({
                'source_alias': 'This field is required.'
            })
        source = InstanceSource.get_source(
            source_alias, queryset=provider_queryset)
        if not source:
            raise ValidationError({
                'source_alias': 'Value %s did not match a ProviderMachine or Volume.' % source_alias
            })
        return super(InstanceSerializer, self).to_internal_value(data)
Exemplo n.º 2
0
    def to_internal_value(self, data):
        """
        Overwrite to force custom logic required before accepting data to launch an instance.
        1. check of identity prior to checking size_alias or source_alias
        NOTE: This is required because we have identical alias' on multiple providers, so we must first filter-down based on the identity requested for launching the instance.
        2. Check source_alias is either a Volume or a ProviderMachine before continuing.
        """

        identity_uuid = data.get('identity')
        if not identity_uuid:
            raise ValidationError({'identity': 'This field is required.'})
        size_queryset = self.fields['size_alias'].queryset
        source_queryset = self.fields['source_alias'].queryset

        size_alias = data.get('size_alias')
        if not size_alias:
            raise ValidationError({'size_alias': 'This field is required.'})
        size = size_queryset.filter(alias=size_alias)
        if not size:
            raise ValidationError(
                {'size_alias': 'Value %s did not match a Size.' % size_alias})

        source_alias = data.get('source_alias')
        if not source_alias:
            raise ValidationError({'source_alias': 'This field is required.'})
        source = InstanceSource.get_source(source_alias,
                                           queryset=source_queryset)
        if not source:
            raise ValidationError({
                'source_alias':
                'Value %s did not match a ProviderMachine or Volume.' %
                source_alias
            })
        return super(InstanceSerializer, self).to_internal_value(data)
Exemplo n.º 3
0
    def to_internal_value(self, data):
        """
        Overwrite to force custom logic required before accepting data to launch an instance.
        1. check of identity prior to checking size_alias or source_alias
        NOTE: This is required because we have identical alias' on multiple providers, so we must first filter-down based on the identity requested for launching the instance.
        2. Check source_alias is either a Volume or a ProviderMachine before continuing.
        """

        identity_uuid = data.get('identity')
        if not identity_uuid:
            raise ValidationError({
                'identity': 'This field is required.'
            })
        request_user = self.context['request'].user

        size_queryset = self.fields['size_alias'].queryset
        allocation_source_queryset = UserAllocationSource.objects.filter(user=request_user)
        source_queryset = self.fields['source_alias'].queryset

        allocation_source_id = data.get('allocation_source_id')
        if not allocation_source_id:
            raise ValidationError({
                'allocation_source_id': 'This field is required.'
            })
        allocation_source = allocation_source_queryset.filter(allocation_source__uuid=allocation_source_id)
        if not allocation_source:
            raise ValidationError({
                'allocation_source_id': 'Value %s did not match a allocation_source.' % allocation_source_id
            })

        size_alias = data.get('size_alias')
        if not size_alias:
            raise ValidationError({
                'size_alias': 'This field is required.'
            })
        size = size_queryset.filter(alias=size_alias)
        if not size:
            raise ValidationError({
                'size_alias': 'Value %s did not match a Size.' % size_alias
            })

        source_alias = data.get('source_alias')
        if not source_alias:
            raise ValidationError({
                'source_alias': 'This field is required.'
            })
        source = InstanceSource.get_source(
            source_alias, queryset=source_queryset)
        if not source:
            raise ValidationError({
                'source_alias': 'Value %s did not match a ProviderMachine or Volume.' % source_alias
            })
        return super(InstanceSerializer, self).to_internal_value(data)
Exemplo n.º 4
0
    def to_internal_value(self, data):
        """
        Overwrite to force custom logic required before accepting data to launch an instance.
        1. check of identity prior to checking size_alias or source_alias
        NOTE: This is required because we have identical alias' on multiple providers, so we must first filter-down based on the identity requested for launching the instance.
        2. Check source_alias is either a Volume or a ProviderMachine before continuing.
        """

        identity_uuid = data.get('identity')
        if not identity_uuid:
            raise ValidationError({'identity': 'This field is required.'})
        request_user = self.context['request'].user

        size_queryset = self.fields['size_alias'].queryset
        allocation_source_queryset = UserAllocationSource.objects.filter(
            user=request_user)
        source_queryset = self.fields['source_alias'].queryset

        allocation_source_id = data.get('allocation_source_id')
        #NOTE: When CyVerse uses the allocation_source feature, remove 'and 'jetstream' in settings.INSTALLED_APPS'
        if not allocation_source_id and 'jetstream' in settings.INSTALLED_APPS:
            raise ValidationError(
                {'allocation_source_id': 'This field is required.'})
        allocation_source = allocation_source_queryset.filter(
            allocation_source__source_id=allocation_source_id)
        if not allocation_source:
            raise ValidationError({
                'allocation_source_id':
                'Value %s did not match a allocation_source.' %
                allocation_source_id
            })

        size_alias = data.get('size_alias')
        if not size_alias:
            raise ValidationError({'size_alias': 'This field is required.'})
        size = size_queryset.filter(alias=size_alias)
        if not size:
            raise ValidationError(
                {'size_alias': 'Value %s did not match a Size.' % size_alias})

        source_alias = data.get('source_alias')
        if not source_alias:
            raise ValidationError({'source_alias': 'This field is required.'})
        source = InstanceSource.get_source(source_alias,
                                           queryset=source_queryset)
        if not source:
            raise ValidationError({
                'source_alias':
                'Value %s did not match a ProviderMachine or Volume.' %
                source_alias
            })
        return super(InstanceSerializer, self).to_internal_value(data)