pulp.plugin.viewsets

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

class pulpcore.plugin.viewsets.BaseDistributionViewSet(**kwargs)

Provides read and list methods and also provides asynchronous CUD methods to dispatch tasks with reservation that lock all Distributions preventing race conditions during base_path checking.

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

filterset_class

alias of DistributionFilter

serializer_class

alias of pulpcore.app.serializers.publication.BaseDistributionSerializer

async_reserved_resources(instance)

Return resource that locks all Distributions.

endpoint_name = 'distributions'
queryset = <QuerySet []>
class pulpcore.plugin.viewsets.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’, ‘_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

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', 'range': 'is between two comma separated', 'regex': 'matches regex', 'search': 'matches', 'startswith': 'starts with'}
base_filters = {}
declared_filters = {}
help_text = {}
class pulpcore.plugin.viewsets.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 at 0x7fc469039400>, 'repository_version_added': <pulpcore.app.viewsets.custom_filters.ContentAddedRepositoryVersionFilter object at 0x7fc469039940>, 'repository_version_removed': <pulpcore.app.viewsets.custom_filters.ContentRemovedRepositoryVersionFilter object at 0x7fc469039be0>}
declared_filters = {'repository_version': <pulpcore.app.viewsets.custom_filters.ContentRepositoryVersionFilter object at 0x7fc469039400>, 'repository_version_added': <pulpcore.app.viewsets.custom_filters.ContentAddedRepositoryVersionFilter object at 0x7fc469039940>, 'repository_version_removed': <pulpcore.app.viewsets.custom_filters.ContentRemovedRepositoryVersionFilter object at 0x7fc469039be0>}
class pulpcore.plugin.viewsets.ContentGuardFilter(data=None, queryset=None, *, request=None, prefix=None)
class Meta
model

alias of pulpcore.app.models.publication.ContentGuard

fields = {'name': ['exact', 'in']}
base_filters = {'name': <django_filters.filters.CharFilter object at 0x7fc469017908>, 'name__in': <django_filters.filterset.BaseFilterSet.filter_for_lookup.<locals>.ConcreteInFilter object at 0x7fc468fd6ba8>}
declared_filters = {'name': <django_filters.filters.CharFilter object at 0x7fc469017908>}
class pulpcore.plugin.viewsets.ContentGuardViewSet(**kwargs)

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

filterset_class

alias of ContentGuardFilter

serializer_class

alias of pulpcore.app.serializers.publication.ContentGuardSerializer

endpoint_name = 'contentguards'
queryset = <QuerySet []>
class pulpcore.plugin.viewsets.ContentViewSet(**kwargs)

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 = <QuerySet []>
class pulpcore.plugin.viewsets.HyperlinkRelatedFilter(*args, **kwargs)

Enables a user to filter by a foreign key using that FK’s href

filter(qs, value)
Parameters:
  • qs (django.db.models.query.QuerySet) – The Queryset to filter
  • value (string) – href containing pk for the foreign key instance
Returns:

Queryset filtered by the foreign key pk

Return type:

django.db.models.query.QuerySet

class pulpcore.plugin.viewsets.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.

class pulpcore.plugin.viewsets.OperationPostponedResponse(result, request)

An HTTP response class for returning 202 and a spawned task.

This response object should be used by views that dispatch asynchronous tasks. The most common use case is for sync and publish operations. When JSON is requested, the response will look like the following:

{
    "_href": "https://example.com/pulp/api/v3/tasks/adlfk-bala-23k5l7-lslser",
    "task_id": "adlfk-bala-23k5l7-lslser"
}
Parameters:
  • result (rq.job.Job) – A rq.job.Job object used to generate the response.
  • request (rest_framework.request.Request) – Request used to generate the _href urls
class pulpcore.plugin.viewsets.PublicationViewSet(**kwargs)

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

serializer_class

alias of pulpcore.app.serializers.publication.PublicationSerializer

endpoint_name = 'publications'
filter_backends = (<class 'rest_framework.filters.OrderingFilter'>, <class 'django_filters.rest_framework.backends.DjangoFilterBackend'>)
ordering = ('-_created',)
queryset = <QuerySet []>
class pulpcore.plugin.viewsets.PublisherViewSet(**kwargs)

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

filterset_class

alias of PublisherFilter

serializer_class

alias of pulpcore.app.serializers.repository.PublisherSerializer

endpoint_name = 'publishers'
queryset = <QuerySet []>
class pulpcore.plugin.viewsets.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 = {'_last_updated': ['lt', 'lte', 'gt', 'gte', 'range'], 'name': ['exact', 'in']}
base_filters = {'_last_updated': <pulpcore.app.viewsets.custom_filters.IsoDateTimeFilter object at 0x7fc468fd4a58>, '_last_updated__gt': <django_filters.filters.IsoDateTimeFilter object at 0x7fc468fd4da0>, '_last_updated__gte': <django_filters.filters.IsoDateTimeFilter object at 0x7fc468fd4c50>, '_last_updated__lt': <django_filters.filters.IsoDateTimeFilter object at 0x7fc468fd4ba8>, '_last_updated__lte': <django_filters.filters.IsoDateTimeFilter object at 0x7fc468fd4e48>, '_last_updated__range': <django_filters.filterset.BaseFilterSet.filter_for_lookup.<locals>.ConcreteRangeFilter object at 0x7fc468fd4ef0>, 'name': <django_filters.filters.CharFilter object at 0x7fc468fd47b8>, 'name__in': <django_filters.filterset.BaseFilterSet.filter_for_lookup.<locals>.ConcreteInFilter object at 0x7fc468fd47f0>}
declared_filters = {'_last_updated': <pulpcore.app.viewsets.custom_filters.IsoDateTimeFilter object at 0x7fc468fd4a58>, 'name': <django_filters.filters.CharFilter object at 0x7fc468fd47b8>}
class pulpcore.plugin.viewsets.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 = <QuerySet []>