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
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’, ‘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', 'range': 'is between two comma separated', 'regex': 'matches regex', 'search': 'matches', 'startswith': 'starts with'}
base_filters = {}
declared_filters = {}
help_text = {}
class pulpcore.plugin.viewsets.CharInFilter(*args, **kwargs)
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>, '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.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>, 'name__in': <django_filters.filterset.BaseFilterSet.filter_for_lookup.<locals>.ConcreteInFilter object>}
declared_filters = {'name': <django_filters.filters.CharFilter object>}
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
class pulpcore.plugin.viewsets.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.plugin.viewsets.FileSystemExporterViewSet(**kwargs)

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

filterset_class

alias of FileSystemExporterFilter

serializer_class

alias of pulpcore.app.serializers.exporter.FileSystemExporterSerializer

endpoint_name = 'file_exporters'
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:

{
    "pulp_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 pulp_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 = ('-pulp_created',)
queryset
class pulpcore.plugin.viewsets.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.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
class pulpcore.plugin.viewsets.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.plugin.viewsets.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'
class pulpcore.plugin.viewsets.SingleArtifactContentUploadViewSet(**kwargs)

A base ContentViewSet with added upload functionality.

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

create(request)

Create a content unit.

get_deferred_context(request)

Supply context for deferred validation.

When overwriting this method, it must return a dict, that is serializable by rq and does _not_ contain ‘request’ as a key.