pulp.app.viewsets

All viewsets documented here should be imported directly from the pulpcore.app.viewsets namespace.

Viewsets that dispatch tasks that are descendants of UserFacingTask should return an OperationPostponedResponse.

pulp.app.viewsets.base

class pulpcore.app.viewsets.base.AsyncCreateMixin

Provides a create method that dispatches a task with reservation.

create(request, *args, **kwargs)

Dispatches a task with reservation for creating an instance.

class pulpcore.app.viewsets.base.AsyncRemoveMixin

Provides a delete method that dispatches a task with reservation

destroy(request, pk, **kwargs)

Delete a model instance

class pulpcore.app.viewsets.base.AsyncReservedObjectMixin

Mixin class providing the default method to compute the resources to reserve in the task.

By default, lock the object instance we are working on.

async_reserved_resources(instance)

Return the resources to reserve for the task created by the Async…Mixins.

This default implementation locks the instance being worked on.

Note

This does not work for AsyncCreateMixin (as there is no instance). Classes using AsyncCreateMixin must override this method.

Parameters

instance (django.models.Model) – The instance that will be worked on by the task.

Returns

The resources to put in the task’s reservation

Return type

list/str

Raises

AssertionError if instance is None (which happens for creation)

class pulpcore.app.viewsets.base.AsyncUpdateMixin

Provides an update method that dispatches a task with reservation

partial_update(request, *args, **kwargs)
update(request, pk, **kwargs)
class pulpcore.app.viewsets.base.BaseFilterSet(data=None, queryset=None, *, request=None, prefix=None)

Class to override django_filter’s FilterSet and provide a way to set help text

By default, this class will use predefined text and the field name to create help text for the filter. However, this can be overriden by setting a help_text dict with the the field name mapped to some help text:

help_text = {‘name__in’: ‘Lorem ipsum dolor’, ‘pulp_last_updated__lt’: ‘blah blah’}

classmethod filter_for_field(field, name, lookup_expr)

Looks up and initializes a filter and returns it. Also, sets the help text on the filter.

Parameters
  • field – The field class for the filter

  • name – The name of filter field

  • lookup_expr – The lookup expression that specifies how the field is matched

Returns

an initialized Filter object with help text

Return type

django_filters.Filter

is_valid(*args, **kwargs)

Return True if the underlying form has no errors, or False otherwise.

LOOKUP_EXPR_TEXT = {'contains': 'contains', 'endswith': 'ends with', 'exact': 'matches', 'gt': 'is greater than', 'gte': 'is greater than or equal to', 'icontains': 'contains', 'iendswith': 'ends with', 'iexact': 'matches', 'in': 'is in a comma-separated list of', 'iregex': 'matches regex', 'isnull': 'has a null', 'istartswith': 'starts with', 'lt': 'is less than', 'lte': 'is less than or equal to', 'ne': 'not equal to', 'range': 'is between two comma separated', 'regex': 'matches regex', 'search': 'matches', 'startswith': 'starts with'}
base_filters = {}
declared_filters = {}
help_text = {}
class pulpcore.app.viewsets.base.DefaultSchema

Overrides _allows_filters method to include filter fields only for read actions.

Schema can be customised per view(set). Override this class and set it as a schema attribute of a view(set) of interest.

class pulpcore.app.viewsets.base.NamedModelViewSet(**kwargs)

A customized named ModelViewSet that knows how to register itself with the Pulp API router.

This viewset is discoverable by its name. “Normal” Django Models and Master/Detail models are supported by the register_with method.

Variables
  • lookup_field (str) – The name of the field by which an object should be looked up, in addition to any parent lookups if this ViewSet is nested. Defaults to ‘pk’

  • endpoint_name (str) – The name of the final path segment that should identify the ViewSet’s collection endpoint.

  • nest_prefix (str) – Optional prefix under which this ViewSet should be nested. This must correspond to the “parent_prefix” of a router with rest_framework_nested.NestedMixin. None indicates this ViewSet should not be nested.

  • parent_lookup_kwargs (dict) – Optional mapping of key names that would appear in self.kwargs to django model filter expressions that can be used with the corresponding value from self.kwargs, used only by a nested ViewSet to filter based on the parent object’s identity.

  • schema (DefaultSchema) – The schema class to use by default in a viewset.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

classmethod endpoint_pieces()
get_parent_field_and_object()

For nested ViewSets, retrieve the nested parent implied by the url.

Returns

(parent field name, parent)

Return type

tuple

Raises

django.http.Http404 – When the parent implied by the url does not exist. Synchronous use should allow this to bubble up and return a 404.

get_parent_object()

For nested ViewSets, retrieve the nested parent implied by the url.

Returns

parent model object

Return type

pulpcore.app.models.Model

Raises

django.http.Http404 – When the parent implied by the url does not exist. Synchronous use should allow this to bubble up and return a 404.

get_queryset()

Gets a QuerySet based on the current request.

For nested ViewSets, this adds parent filters to the result returned by the superclass. For non-nested ViewSets, this returns the original QuerySet unchanged.

Returns

The queryset returned by the superclass with additional

filters applied that match self.parent_lookup_kwargs, to scope the results to only those associated with the parent object.

Return type

django.db.models.query.QuerySet

static get_resource(uri, model)

Resolve a resource URI to an instance of the resource.

Provides a means to resolve an href passed in a POST body to an instance of the resource.

Parameters
  • uri (str) – A resource URI.

  • model (django.models.Model) – A model class.

Returns

The resource fetched from the DB.

Return type

django.models.Model

Raises

rest_framework.exceptions.ValidationError – on invalid URI or resource not found.

get_serializer_class()

Fetch the serializer class to use for the request.

The default behavior is to use the “serializer_class” attribute on the viewset. We override that for the case where a “minimal_serializer_class” attribute is defined and where the request contains a query parameter of “minimal=True”.

The intention is that ViewSets can define a second, more minimal serializer with only the most important fields.

initial(request, *args, **kwargs)

Runs anything that needs to occur prior to calling the method handler.

For nested ViewSets, it checks that the parent object exists, otherwise return 404. For non-nested Viewsets, this does nothing.

classmethod is_master_viewset()
classmethod urlpattern()
classmethod view_name()
endpoint_name = None
nest_prefix = None
parent_lookup_kwargs = {}
parent_viewset = None
schema

Overrides _allows_filters method to include filter fields only for read actions.

Schema can be customised per view(set). Override this class and set it as a schema attribute of a view(set) of interest.

pulp.app.viewsets.content

class pulpcore.app.viewsets.content.ArtifactFilter(data=None, queryset=None, *, request=None, prefix=None)
Artifact filter Plugin content filters should:
  • inherit from this class

  • add any plugin-specific filters if needed

  • define its own Meta class should: - specify plugin content model - extend fields with plugin-specific ones

class Meta
model

alias of pulpcore.app.models.content.Artifact

fields = {'md5': ['exact'], 'repository_version': ['exact'], 'sha1': ['exact'], 'sha224': ['exact'], 'sha256': ['exact'], 'sha384': ['exact'], 'sha512': ['exact']}
base_filters = {'md5': <django_filters.filters.CharFilter object>, 'repository_version': <pulpcore.app.viewsets.custom_filters.ArtifactRepositoryVersionFilter object>, 'sha1': <django_filters.filters.CharFilter object>, 'sha224': <django_filters.filters.CharFilter object>, 'sha256': <django_filters.filters.CharFilter object>, 'sha384': <django_filters.filters.CharFilter object>, 'sha512': <django_filters.filters.CharFilter object>}
declared_filters = {'repository_version': <pulpcore.app.viewsets.custom_filters.ArtifactRepositoryVersionFilter object>}
class pulpcore.app.viewsets.content.ArtifactViewSet(**kwargs)

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

filterset_class

alias of ArtifactFilter

serializer_class

alias of pulpcore.app.serializers.content.ArtifactSerializer

destroy(request, pk)

Remove Artifact only if it is not associated with any Content.

basename = None
description = None
detail = None
endpoint_name = 'artifacts'
name = None
queryset
suffix = None
class pulpcore.app.viewsets.content.BaseContentViewSet(**kwargs)

A base class for any content viewset.

It ensures that ‘content/’ is a part of endpoint. It also sets a default filter class.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

filterset_class

alias of ContentFilter

serializer_class

alias of pulpcore.app.serializers.content.MultipleArtifactContentSerializer

endpoint_name = 'content'
queryset
class pulpcore.app.viewsets.content.ContentFilter(data=None, queryset=None, *, request=None, prefix=None)
Plugin content filters should:
  • inherit from this class

  • add any plugin-specific filters if needed

  • define its own Meta class which should: - specify plugin content model - extend fields with plugin-specific ones

Allows you to filter the content app by repository version.

Fields
  • repository_version – Return Content which is contained within this repository version.

  • repository_version_added – Return Content which was added in this repository version.

  • repository_version_removed – Return Content which was removed from this repository version.

class Meta
model

alias of pulpcore.app.models.content.Content

fields = {'repository_version': ['exact'], 'repository_version_added': ['exact'], 'repository_version_removed': ['exact']}
base_filters = {'repository_version': <pulpcore.app.viewsets.custom_filters.ContentRepositoryVersionFilter object>, 'repository_version_added': <pulpcore.app.viewsets.custom_filters.ContentAddedRepositoryVersionFilter object>, 'repository_version_removed': <pulpcore.app.viewsets.custom_filters.ContentRemovedRepositoryVersionFilter object>}
declared_filters = {'repository_version': <pulpcore.app.viewsets.custom_filters.ContentRepositoryVersionFilter object>, 'repository_version_added': <pulpcore.app.viewsets.custom_filters.ContentAddedRepositoryVersionFilter object>, 'repository_version_removed': <pulpcore.app.viewsets.custom_filters.ContentRemovedRepositoryVersionFilter object>}
class pulpcore.app.viewsets.content.ContentViewSet(**kwargs)

Content viewset that supports POST and GET by default.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

class pulpcore.app.viewsets.content.ReadOnlyContentViewSet(**kwargs)

Content viewset that supports only GET by default.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

class pulpcore.app.viewsets.content.SigningServiceViewSet(**kwargs)

A ViewSet that supports browsing of existing signing services.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

serializer_class

alias of pulpcore.app.serializers.content.SigningServiceSerializer

basename = None
description = None
detail = None
endpoint_name = 'signing-services'
name = None
queryset
suffix = None

pulp.app.viewsets.repository

class pulpcore.app.viewsets.repository.RemoteFilter(data=None, queryset=None, *, request=None, prefix=None)
Plugin remote filter should:
  • inherit from this class

  • add any specific filters if needed

  • define a Meta class which should: - specify a plugin remote model for which filter is defined - extend fields with specific ones

class Meta
model

alias of pulpcore.app.models.repository.Remote

fields = {'name': ['exact', 'in'], 'pulp_last_updated': ['lt', 'lte', 'gt', 'gte', 'range']}
base_filters = {'name': <django_filters.filters.CharFilter object>, 'name__in': <django_filters.filterset.BaseFilterSet.filter_for_lookup.<locals>.ConcreteInFilter object>, 'pulp_last_updated': <pulpcore.app.viewsets.custom_filters.IsoDateTimeFilter object>, 'pulp_last_updated__gt': <django_filters.filters.IsoDateTimeFilter object>, 'pulp_last_updated__gte': <django_filters.filters.IsoDateTimeFilter object>, 'pulp_last_updated__lt': <django_filters.filters.IsoDateTimeFilter object>, 'pulp_last_updated__lte': <django_filters.filters.IsoDateTimeFilter object>, 'pulp_last_updated__range': <django_filters.filterset.BaseFilterSet.filter_for_lookup.<locals>.ConcreteRangeFilter object>}
declared_filters = {'name': <django_filters.filters.CharFilter object>, 'pulp_last_updated': <pulpcore.app.viewsets.custom_filters.IsoDateTimeFilter object>}
class pulpcore.app.viewsets.repository.RemoteViewSet(**kwargs)

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

filterset_class

alias of RemoteFilter

serializer_class

alias of pulpcore.app.serializers.repository.RemoteSerializer

endpoint_name = 'remotes'
queryset
class pulpcore.app.viewsets.repository.RepositoryFilter(data=None, queryset=None, *, request=None, prefix=None)
class Meta
model

alias of pulpcore.app.models.repository.Repository

fields = {'name': ['exact', 'in']}
base_filters = {'name': <django_filters.filters.CharFilter object>, 'name__in': <django_filters.filterset.BaseFilterSet.filter_for_lookup.<locals>.ConcreteInFilter object>}
declared_filters = {'name': <django_filters.filters.CharFilter object>}
class pulpcore.app.viewsets.repository.RepositoryVersionContentFilter(*args, **kwargs)

Filter used to get the repository versions where some given content can be found.

Given a content_href, this filter will:
  1. Get the RepositoryContent that the content can be found in

  2. Get a list of version_added and version_removed where the content was changed on the repository

  3. Calculate and return the versions that the content can be found on

filter(qs, value)
Parameters
  • qs (django.db.models.query.QuerySet) – The RepositoryVersion Queryset

  • value (string) – of content href to filter

Returns

Queryset of the RepositoryVersions containing the specified content

class pulpcore.app.viewsets.repository.RepositoryVersionFilter(data=None, queryset=None, *, request=None, prefix=None)
class Meta
model

alias of pulpcore.app.models.repository.RepositoryVersion

fields = {'content': ['exact', 'in'], 'number': ['exact', 'lt', 'lte', 'gt', 'gte', 'range'], 'pulp_created': ['lt', 'lte', 'gt', 'gte', 'range']}
base_filters = {'content': <pulpcore.app.viewsets.repository.RepositoryVersionContentFilter object>, 'number': <django_filters.filters.NumberFilter object>, 'number__gt': <django_filters.filters.NumberFilter object>, 'number__gte': <django_filters.filters.NumberFilter object>, 'number__lt': <django_filters.filters.NumberFilter object>, 'number__lte': <django_filters.filters.NumberFilter object>, 'number__range': <django_filters.filterset.BaseFilterSet.filter_for_lookup.<locals>.ConcreteRangeFilter object>, 'pulp_created': <pulpcore.app.viewsets.custom_filters.IsoDateTimeFilter object>, 'pulp_created__gt': <django_filters.filters.IsoDateTimeFilter object>, 'pulp_created__gte': <django_filters.filters.IsoDateTimeFilter object>, 'pulp_created__lt': <django_filters.filters.IsoDateTimeFilter object>, 'pulp_created__lte': <django_filters.filters.IsoDateTimeFilter object>, 'pulp_created__range': <django_filters.filterset.BaseFilterSet.filter_for_lookup.<locals>.ConcreteRangeFilter object>}
declared_filters = {'content': <pulpcore.app.viewsets.repository.RepositoryVersionContentFilter object>, 'number': <django_filters.filters.NumberFilter object>, 'pulp_created': <pulpcore.app.viewsets.custom_filters.IsoDateTimeFilter object>}
class pulpcore.app.viewsets.repository.RepositoryVersionViewSet(**kwargs)

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

filterset_class

alias of RepositoryVersionFilter

parent_viewset

alias of RepositoryViewSet

serializer_class

alias of pulpcore.app.serializers.repository.RepositoryVersionSerializer

destroy(request, repository_pk, number)

Queues a task to handle deletion of a RepositoryVersion

endpoint_name = 'versions'
filter_backends = (<class 'rest_framework.filters.OrderingFilter'>, <class 'django_filters.rest_framework.backends.DjangoFilterBackend'>)
lookup_field = 'number'
nest_prefix = 'repositories'
ordering = ('-number',)
parent_lookup_kwargs = {'repository_pk': 'repository__pk'}
queryset
router_lookup = 'version'
class pulpcore.app.viewsets.repository.RepositoryViewSet(**kwargs)

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

filterset_class

alias of RepositoryFilter

serializer_class

alias of pulpcore.app.serializers.repository.RepositorySerializer

destroy(request, pk)

Generates a Task to delete a Repository

update(request, pk, partial=False)

Generates a Task to update a Repository

endpoint_name = 'repositories'
queryset
router_lookup = 'repository'