pulpcore.plugin.viewsets¶
All viewsets documented here should be imported directly from the pulpcore.plugin.viewsets
namespace.
pulpcore.plugin.viewsets
¶
BaseFilterSet
¶
Bases: FilterSet
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'}
filter_for_field(field, name, lookup_expr)
classmethod
¶
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: django_filters.Filter: an initialized Filter object with help text
OperationPostponedResponse(task, request)
¶
Bases: Response
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
(Task
) –A pulpcore.plugin.models.Task object used to generate the response.
-
request
(Request
) –Request used to generate the pulp_href urls
TaskGroupOperationResponse(task_group, request)
¶
Bases: Response
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
(TaskGroup
) –A pulpcore.plugin.models.TaskGroup object used to generate the response.
-
request
(Request
) –Request used to generate the pulp_href urls
AlternateContentSourceViewSet
¶
Bases: CreateModelMixin
, DestroyModelMixin
, ListModelMixin
, RetrieveModelMixin
, AsyncUpdateMixin
, NamedModelViewSet
A class for ACS viewset.
AsyncUpdateMixin
¶
ContentFilter
¶
Bases: BaseFilterSet
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.
ContentGuardViewSet
¶
Bases: BaseContentGuardViewSet
, CreateModelMixin
, UpdateModelMixin
, DestroyModelMixin
, RetrieveModelMixin
, ListModelMixin
A viewset for contentguards.
ContentViewSet
¶
Bases: BaseContentViewSet
, CreateModelMixin
, RetrieveModelMixin
, ListModelMixin
Content viewset that supports POST and GET by default.
DistributionViewSet
¶
Bases: ReadOnlyDistributionViewSet
, AsyncCreateMixin
, AsyncRemoveMixin
, AsyncUpdateMixin
, LabelsMixin
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.
ExporterViewSet
¶
Bases: NamedModelViewSet
, CreateModelMixin
, AsyncUpdateMixin
, RetrieveModelMixin
, ListModelMixin
, AsyncRemoveMixin
ViewSet for viewing exporters.
ExportViewSet
¶
Bases: NamedModelViewSet
, CreateModelMixin
, RetrieveModelMixin
, ListModelMixin
, DestroyModelMixin
ViewSet for viewing exports from an Exporter.
ImmutableRepositoryViewSet
¶
Bases: ReadOnlyRepositoryViewSet
, CreateModelMixin
, AsyncRemoveMixin
ALLOW_NON_BLOCKING_DELETE = False
class-attribute
instance-attribute
¶
An immutable repository ViewSet that does not allow the usage of the methods PATCH and PUT.
ImporterViewSet
¶
Bases: NamedModelViewSet
, CreateModelMixin
, UpdateModelMixin
, RetrieveModelMixin
, ListModelMixin
, DestroyModelMixin
ViewSet for Importers.
ImportViewSet
¶
Bases: NamedModelViewSet
, CreateModelMixin
, RetrieveModelMixin
, ListModelMixin
, DestroyModelMixin
ViewSet for viewing imports from an Importer.
NamedModelViewSet
¶
Bases: GenericViewSet
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.
Attributes:
-
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.
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.
get_resource_model(uri)
staticmethod
¶
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:
-
–
django.models.Model: The model for the specified URI.
Raises:
-
ValidationError
–on invalid URI.
get_resource(uri, model=None)
staticmethod
¶
Resolve a resource URI/PRN to an instance of the resource.
Provides a means to resolve an href/prn passed in a POST body to an instance of the resource.
Parameters:
-
uri
(str
) –A resource URI/PRN.
-
model
(Model
, default:None
) –A model class. If not provided, the method automatically determines the used model from the resource URI/PRN.
Returns:
-
–
django.models.Model: The resource fetched from the DB.
Raises:
-
ValidationError
–on invalid URI/PRN or resource not found.
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.
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:
-
–
django.db.models.query.QuerySet: 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.
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.
get_parent_field_and_object()
¶
For nested ViewSets, retrieve the nested parent implied by the url.
Returns:
-
tuple
–(parent field name, parent)
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:
-
–
pulpcore.app.models.Model: parent model object
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.
PublicationViewSet
¶
Bases: BasePublicationViewSet
, RetrieveModelMixin
, ListModelMixin
, DestroyModelMixin
Provides read, list and destroy methods for publications. Plugins should inherit from this.
ReadOnlyContentViewSet
¶
Bases: BaseContentViewSet
, RetrieveModelMixin
, ListModelMixin
Content viewset that supports only GET by default.
ReadOnlyRepositoryViewSet
¶
Bases: BaseRepositoryViewSet
, ListModelMixin
, RetrieveModelMixin
A readonly repository which allows only GET method.
RemoteFilter
¶
Bases: BaseFilterSet
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
RepositoryVersionViewSet
¶
Bases: RepositoryVersionQuerysetMixin
, NamedModelViewSet
, RetrieveModelMixin
, ListModelMixin
, DestroyModelMixin
RepositoryViewSet
¶
Bases: ImmutableRepositoryViewSet
, AsyncUpdateMixin
, LabelsMixin
A ViewSet for an ordinary repository.
TaskGroupViewSet
¶
Bases: RetrieveModelMixin
, ListModelMixin
, NamedModelViewSet
scope_queryset(qs)
¶
Filter based on having view permission on the parent task of the group.
TaskViewSet
¶
Bases: NamedModelViewSet
, RetrieveModelMixin
, ListModelMixin
, DestroyModelMixin
, RolesMixin
LabelFilter(*args, **kwargs)
¶
Bases: Filter
Filter to get resources that match a label filter string.
filter(qs, value)
¶
Parameters:
-
qs
(QuerySet
) –The Model queryset
-
value
(string
) –label search query
Returns:
-
–
Queryset of the Models filtered by label(s)
Raises:
-
ValidationError
–on invalid search string
RepositoryVersionFilter(*args, **kwargs)
¶
Bases: RepoVersionHrefPrnFilter
Filter by RepositoryVersion href/prn.
filter(qs, value)
¶
Parameters:
-
qs
(QuerySet
) –The Queryset to filter
-
value
(string
) –The RepositoryVersion href/prn to filter by
Returns:
-
–
Queryset filtered by given repository version on field_name
HyperlinkRelatedFilter(*args, **kwargs)
¶
Bases: Filter
Enables a user to filter by a foreign key using that FK's href/prn.
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/ Filtering by object type is not possible using PRNs.
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
(QuerySet
) –The Queryset to filter
-
value
(string or list of strings
) –href/prn containing pk for the foreign key instance
Returns:
-
–
django.db.models.query.QuerySet: Queryset filtered by the foreign key pk
NoArtifactContentViewSet
¶
Bases: DefaultDeferredContextMixin
, ContentViewSet
A ViewSet for content creation that does not require a file to be uploaded.
create(request)
¶
Create a content unit.
NoArtifactContentUploadViewSet
¶
Bases: DefaultDeferredContextMixin
, ContentViewSet
A ViewSet for uploads that do not require to store an uploaded content as an Artifact.
create(request)
¶
Create a content unit.
SingleArtifactContentUploadViewSet
¶
Bases: DefaultDeferredContextMixin
, ContentViewSet
A ViewSet which can be used to store an uploaded content as an Artifact.