pulpcore.plugin.viewsets

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

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

A class for ACS viewset.

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

filterset_class

alias of pulpcore.app.viewsets.acs.AlternateContentSourceFilter

serializer_class

alias of pulpcore.app.serializers.acs.AlternateContentSourceSerializer

class pulpcore.plugin.viewsets.AsyncUpdateMixin

Provides an update method that dispatches a task with reservation

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 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.

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 pulpcore.plugin.viewsets.ContentGuardFilter(data=None, queryset=None, *, request=None, prefix=None)
class pulpcore.plugin.viewsets.ContentGuardViewSet(**kwargs)

A viewset for contentguards.

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

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.DistributionFilter(data=None, queryset=None, *, request=None, prefix=None)
class pulpcore.plugin.viewsets.DistributionViewSet(**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 pulpcore.app.viewsets.publication.DistributionFilter

serializer_class

alias of pulpcore.app.serializers.publication.DistributionSerializer

async_reserved_resources(instance)

Return resource that locks all Distributions.

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

ViewSet for viewing exports from an Exporter.

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

parent_viewset

alias of pulpcore.app.viewsets.exporter.ExporterViewSet

serializer_class

alias of pulpcore.app.serializers.exporter.ExportSerializer

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

ViewSet for viewing exporters.

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

filterset_class

alias of pulpcore.app.viewsets.exporter.ExporterFilter

serializer_class

alias of pulpcore.app.serializers.exporter.ExporterSerializer

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.ImmutableRepositoryViewSet(**kwargs)

An immutable repository ViewSet that does not allow the usage of the methods PATCH and PUT.

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

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

ViewSet for viewing imports from an Importer.

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

parent_viewset

alias of pulpcore.app.viewsets.importer.ImporterViewSet

serializer_class

alias of pulpcore.app.serializers.importer.ImportSerializer

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

ViewSet for Importers.

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

filterset_class

alias of pulpcore.app.viewsets.importer.ImporterFilter

serializer_class

alias of pulpcore.app.serializers.importer.ImporterSerializer

class pulpcore.plugin.viewsets.LabelSelectFilter(*args, **kwargs)

Filter to get resources that match a label filter string.

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

  • value (string) – label search querry

Returns

Queryset of the Models filtered by label(s)

Raises

rest_framework.exceptions.ValidationError – on invalid search string

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.

static extract_pk(uri)

Resolve a resource URI to a simple PK value.

Provides a means to resolve an href passed in a POST body to a primary key. Doesn’t assume anything about whether the resource corresponding to the URI passed in actually exists.

Note

Cannot be used with nested URIs where the PK of the final resource is not present. e.g. RepositoryVersion URI consists of repository PK and version number - no RepositoryVersion PK is present within the URI.

Parameters

uri (str) – A resource URI.

Returns

The primary key of the resource extracted from the URI.

Return type

primary_key (uuid.uuid4)

Raises

rest_framework.exceptions.ValidationError – on invalid URI.

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.

Additional permissions-based filtering is provided for ViewSets that declare a queryset_filtering_required_permission attribute naming the permission users must have to view an object. This includes receiving the permission through either model-level, object-level, and access through either a user or group.

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. Additionally the QuerySet is filtered by the permission named if the ViewSet declares a queryset_filtering_required_permission attribute.

Return type

django.db.models.query.QuerySet

static get_resource(uri, model=None)

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. If not provided, the method automatically determines the used model from the resource URI.

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.

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

A ViewSet for uploads that do not require to store an uploaded content as an Artifact.

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

create(request)

Create a content unit.

class pulpcore.plugin.viewsets.OperationPostponedResponse(task, 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:

{
    "task": "/pulp/api/v3/tasks/735633bc-eb41-4737-b436-c7c6914f34b1/"
}
Parameters
  • task (pulpcore.plugin.models.Task) – A Task object used to generate the response.

  • request (rest_framework.request.Request) – Request used to generate the pulp_href urls

class pulpcore.plugin.viewsets.PublicationFilter(data=None, queryset=None, *, request=None, prefix=None)
class pulpcore.plugin.viewsets.PublicationViewSet(**kwargs)

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

filterset_class

alias of pulpcore.app.viewsets.publication.PublicationFilter

serializer_class

alias of pulpcore.app.serializers.publication.PublicationSerializer

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.ReadOnlyRepositoryViewSet(**kwargs)

A readonly repository which allows only GET method.

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

filterset_class

alias of pulpcore.app.viewsets.repository.RepositoryFilter

serializer_class

alias of pulpcore.app.serializers.repository.RepositorySerializer

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 pulpcore.plugin.viewsets.RemoteViewSet(**kwargs)

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

filterset_class

alias of pulpcore.app.viewsets.repository.RemoteFilter

serializer_class

alias of pulpcore.app.serializers.repository.RemoteSerializer

class pulpcore.plugin.viewsets.RepositoryVersionFilter(*args, **kwargs)

Filter by RepositoryVersion href.

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

  • value (string) – The RepositoryVersion href to filter by

Returns

Queryset filtered by given repository version on field_name

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

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

filterset_class

alias of pulpcore.app.viewsets.repository.RepositoryVersionFilter

parent_viewset

alias of pulpcore.app.viewsets.repository.RepositoryViewSet

serializer_class

alias of pulpcore.app.serializers.repository.RepositoryVersionSerializer

destroy(request, repository_pk, number)

Queues a task to handle deletion of a RepositoryVersion

repair(request, repository_pk, number)

Queues a task to repair corrupted artifacts corresponding to a RepositoryVersion

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

A ViewSet for an ordinary repository.

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

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

A ViewSet which can be used to store an uploaded content as an Artifact.

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

create(request)

Create a content unit.

init_content_data(serializer, request)

Initialize the reference to an Artifact along with relevant task’s payload data.

class pulpcore.plugin.viewsets.TaskGroupOperationResponse(task_group, request)

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

This response object should be used by views that create a task group and dispatch one or more tasks for that group. When JSON is requested, the response will look like the following:

{
    "task_group": "/pulp/api/v3/task-groups/735633bc-eb41-4737-b436-c7c6914f34b1/"
}
Parameters
  • task_group (pulpcore.plugin.models.TaskGroup) – A TaskGroup object used to generate the response.

  • request (rest_framework.request.Request) – Request used to generate the pulp_href urls

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

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

filterset_class

alias of pulpcore.app.viewsets.task.TaskGroupFilter

serializer_class

alias of pulpcore.app.serializers.task.TaskGroupSerializer

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

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

filterset_class

alias of pulpcore.app.viewsets.task.TaskFilter

minimal_serializer_class

alias of pulpcore.app.serializers.task.MinimalTaskSerializer

serializer_class

alias of pulpcore.app.serializers.task.TaskSerializer

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.