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.

serializer_class

alias of 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

classmethod get_filters()

Get all filters for the filterset. This is the combination of declared and generated filters.

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.

  • orphaned_for – Return Content which has been orphaned for a given number of minutes; -1 uses ORPHAN_PROTECTION_TIME value.

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.

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 ExporterViewSet

serializer_class

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

serializer_class

alias of ExporterSerializer

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

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

Foreign key filter can be specified to an object type by specifying the base URI of that type. e.g. Filter by file remotes: ?remote=/pulp/api/v3/remotes/file/file/

Can also filter for foreign key to be unset by setting allow_null to True. Query parameter will then accept “null” or “” for filtering. e.g. Filter for no remote: ?remote=”null”

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

  • value (string or list of strings) – 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)

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

ALLOW_NON_BLOCKING_DELETE = False

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

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 ImporterViewSet

serializer_class

alias of ImportSerializer

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

ViewSet for Importers.

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

serializer_class

alias of ImporterSerializer

class pulpcore.plugin.viewsets.LabelFilter(*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 query

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.

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 can be performed if enabled by the permission class and ViewSet. The default permission class AccessPolicyFromDB will see if a queryset_scoping method is defined and call that method to further scope the queryset on user permissions.

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. Additional queryset filtering could be performed if queryset_scoping is enabled.

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.

static get_resource_model(uri)

Resolve a resource URI to the model for the resource.

Provides a means to resolve an href passed in a POST body to an model for the resource.

Parameters:

uri (str) – A resource URI.

Returns:

The model for the specified URI.

Return type:

django.models.Model

Raises:

rest_framework.exceptions.ValidationError – on invalid URI.

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.

scope_queryset(qs)

A default queryset scoping method implementation for all NamedModelViewSets.

If the ViewSet is not a Master ViewSet, then it’ll perform scoping based on the ViewSet’s queryset_filtering_required_permission attribute if present. Else it will call each child’s view get_queryset() method to determine what objects the user can see.

This method is intended to be overriden by subclasses if different behavior is desired.

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

A ViewSet for content creation that does not require a file to be uploaded.

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)

Provides read, list and destroy methods for publications. Plugins should inherit from this.

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

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 RepositoryFilter

serializer_class

alias of 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 RemoteFilter

serializer_class

alias of 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 RepositoryVersionFilter

parent_viewset

alias of RepositoryViewSet

serializer_class

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

serializer_class

alias of 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 TaskFilter

minimal_serializer_class

alias of MinimalTaskSerializer

serializer_class

alias of TaskSerializer

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 can be performed if enabled by the permission class and ViewSet. The default permission class AccessPolicyFromDB will see if a queryset_scoping method is defined and call that method to further scope the queryset on user permissions.

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. Additional queryset filtering could be performed if queryset_scoping is enabled.

Return type:

django.db.models.query.QuerySet

get_serializer(*args, **kwargs)

Set repo_ver_mapping in serializer context for optimized serialization.

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.

purge(request)

Purge task-records for tasks in ‘final’ states.