pulp.app.viewsets¶
All viewsets documented here should be imported directly from the pulpcore.app.viewsets namespace.
Viewsets that dispatch tasks that are descendants of pulpcore.tasking.tasks.UserFacingTask
should return an pulpcore.app.response.OperationPostponedResponse.
pulpcore.app.viewsets
¶
pulp.app.viewsets.base¶
pulpcore.app.viewsets.base
¶
DefaultSchema
¶
Bases: PulpAutoSchema
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.
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.
AsyncReservedObjectMixin
¶
Mixin class providing the default method to compute the resources to reserve in the task.
By default, lock the object instance we are working on.
async_reserved_resources(instance, **kwargs)
¶
Return the resources to reserve for the task created by the Async...Mixins.
This default implementation locks the instance being worked on.
Parameters:
-
instance(Model | None) –The instance that will be worked on by the task.
Returns:
-
–
list[django.models.Model | str]: The resources to put in the task's reservation
async_shared_resources(instance, **kwargs)
¶
Return shared resources to reserve for the task created by the Async...Mixins.
This default implementation does not add any shared reservations.
AsyncCreateMixin
¶
Bases: AsyncReservedObjectMixin
Provides a create method that dispatches a task with reservation.
create(request, *args, **kwargs)
¶
Dispatches a task with reservation for creating an instance.
AsyncUpdateMixin
¶
AsyncRemoveMixin
¶
Bases: AsyncReservedObjectMixin
Provides a delete method that dispatches a task with reservation
destroy(request, pk, **kwargs)
¶
Delete a model instance
pulp.app.viewsets.content¶
pulpcore.app.viewsets.content
¶
ArtifactFilter
¶
Bases: BaseFilterSet
Artifact filter Plugin content filters should
- inherit from this class
- add any plugin-specific filters if needed
- define its own
Metaclass should: - specify plugin content model
- extend
fieldswith plugin-specific ones
ArtifactViewSet
¶
Bases: NamedModelViewSet, CreateModelMixin, RetrieveModelMixin, ListModelMixin, DestroyModelMixin
destroy(request, pk, **kwargs)
¶
Remove Artifact only if it is not associated with any Content.
ContentFilter
¶
Bases: BaseFilterSet
Plugin content filters should
- inherit from this class
- add any plugin-specific filters if needed
- define its own
Metaclass which should: - specify plugin content model
- extend
fieldswith 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.
added_between:
Given two Repository Version HREFs/PRNs as 'base,target', return the net set of
Content added going from the base version to the target version (present in target
but not in base). Diffs two arbitrary (possibly non-adjacent) versions.
removed_between:
Given two Repository Version HREFs/PRNs as 'base,target', return the net set of
Content removed going from the base version to the target version (present in base
but not in target). Diffs two arbitrary (possibly non-adjacent) versions.
orphaned_for:
Return Content which has been orphaned for a given number of minutes;
-1 uses ORPHAN_PROTECTION_TIME value.
pulp_label_select:
Return Content which has has the specified label
BaseContentViewSet
¶
Bases: NamedModelViewSet
A base class for any content viewset.
It ensures that 'content/' is a part of endpoint, sets a default filter class and provides
a default scope_queryset method.
ListContentViewSet
¶
Bases: BaseContentViewSet, ListModelMixin
Endpoint to list all content.
routable()
classmethod
¶
Do not hide from the routers.
ContentViewSet
¶
Bases: BaseContentViewSet, CreateModelMixin, RetrieveModelMixin, ListModelMixin, LabelsMixin
Content viewset that supports POST and GET by default.
ReadOnlyContentViewSet
¶
Bases: BaseContentViewSet, RetrieveModelMixin, ListModelMixin, LabelsMixin
Content viewset that supports only GET by default.
SigningServiceViewSet
¶
Bases: NamedModelViewSet, RetrieveModelMixin, ListModelMixin
A ViewSet that supports browsing of existing signing services.
pulp.app.viewsets.repository¶
pulpcore.app.viewsets.repository
¶
RepositoryContentFilter(*args, **kwargs)
¶
Bases: Filter
Filter used to filter repositories which have a piece of content
filter(qs, value)
¶
Parameters:
-
qs(QuerySet) –The Repository Queryset
-
value(string) –of content href/prn to filter
Returns:
-
–
Queryset of the Repository containing the specified content
BaseRepositoryViewSet
¶
Bases: NamedModelViewSet
A base class for any repository viewset.
get_queryset()
¶
Apply optimizations for list endpoint.
ListRepositoryViewSet
¶
Bases: BaseRepositoryViewSet, ListModelMixin
Endpoint to list all repositories.
routable()
classmethod
¶
Do not hide from the routers.
ReadOnlyRepositoryViewSet
¶
Bases: BaseRepositoryViewSet, ListModelMixin, RetrieveModelMixin
A readonly repository which allows only GET method.
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.
RepositoryViewSet
¶
Bases: ImmutableRepositoryViewSet, AsyncUpdateMixin, LabelsMixin
A ViewSet for an ordinary repository.
RepositoryVersionFilter
¶
Bases: BaseFilterSet
filter_pulp_href(queryset, name, value)
¶
Special handling for RepositoryVersion HREF filtering.
RepositoryVersionQuerysetMixin
¶
A mixin to hold the shared get_queryset logic used by RepositoryVersionViewSets.
RepositoryVersionViewSet
¶
Bases: RepositoryVersionQuerysetMixin, NamedModelViewSet, RetrieveModelMixin, ListModelMixin, DestroyModelMixin
RemoteFilter
¶
Bases: BaseFilterSet
Plugin remote filter should
- inherit from this class
- add any specific filters if needed
- define a
Metaclass which should: - specify a plugin remote model for which filter is defined
- extend
fieldswith specific ones
ListRemoteViewSet
¶
Bases: NamedModelViewSet, ListModelMixin
routable()
classmethod
¶
Do not hide from the routers.
ListRepositoryVersionViewSet
¶
Bases: RepositoryVersionQuerysetMixin, GenericViewSet, ListModelMixin
scope_queryset(qs)
¶
This scopes based on repositories the user can see (similar to content).