pulpcore.plugin.serializers¶
All serializers documented here should be imported directly from the pulpcore.plugin.serializers
namespace.
-
class
pulpcore.plugin.serializers.
ArtifactSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.content.Artifact
-
fields
= ('pulp_href', 'pulp_created', 'file', 'size', 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')¶
-
-
validate
(data)¶ Validate file by size and by all checksums provided.
- Parameters
data (
django.http.QueryDict
) – QueryDict mapping Artifact model fields to their values- Raises
rest_framework.exceptions.ValidationError – When the expected file size or any of the checksums don’t match their actual values.
-
class
-
class
pulpcore.plugin.serializers.
AsyncOperationResponseSerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ Serializer for asynchronous operations.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.plugin.serializers.
BaseDistributionSerializer
(*args, **kwargs)¶ The Serializer for the BaseDistribution model.
The serializer deliberately omits the “remote” field, which is used for pull-through caching only. Plugins implementing pull-through caching will have to add the field in their derived serializer class like this:
remote = DetailRelatedField( required=False, help_text=_('Remote that can be used to fetch content when using pull-through caching.'), queryset=models.Remote.objects.all(), allow_null=True )
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.publication.BaseDistribution
-
abstract
= True¶
-
fields
= ('pulp_href', 'pulp_created', 'base_path', 'base_url', 'content_guard', 'name')¶
-
-
validate_base_path
(path)¶
-
class
-
class
pulpcore.plugin.serializers.
ContentChecksumSerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ Provide a serializer with artifact checksum fields for single artifact content.
If you use this serializer, it’s recommended that you prefetch artifacts:
Content.objects.prefetch_related(“_artifacts”).all()
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.plugin.serializers.
ContentGuardSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.plugin.serializers.
DetailRelatedField
(view_name=None, **kwargs)¶ RelatedField for use when relating to Master/Detail models
When using this field on a Serializer, relate it to the Master model in a Master/Detail relationship, and it will automatically cast objects to their Detail type before generating URLs for them.
Subclasses must indicate the Master model they represent by declaring a queryset in their class body, usually <MasterModelImplementation>.objects.all().
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_object
(*args, **kwargs)¶ Return the object corresponding to a matched URL.
Takes the matched URL conf arguments, and should return an object instance, or raise an ObjectDoesNotExist exception.
-
use_pk_only_optimization
()¶ If the lookup field is pk, DRF substitutes a PKOnlyObject as an optimization. This optimization breaks with Detail fields like this one which need access to their Meta class to get the relevant view_name.
-
-
class
pulpcore.plugin.serializers.
FileSystemExporterSerializer
(*args, **kwargs)¶ Base serializer for FileSystemExporters.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.plugin.serializers.
IdentityField
(view_name=None, **kwargs)¶ IdentityField for use in the pulp_href field of non-Master/Detail Serializers.
The get_url method is overriden so relative URLs are returned.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_url
(obj, view_name, request, *args, **kwargs)¶ Given an object, return the URL that hyperlinks to the object.
May raise a NoReverseMatch if the view_name and lookup_field attributes are not configured to correctly match the URL conf.
-
-
class
pulpcore.plugin.serializers.
ModelSerializer
(*args, **kwargs)¶ Base serializer for use with
pulpcore.app.models.Model
This ensures that all Serializers provide values for the ‘pulp_href` field.
The class provides a default for the
ref_name
attribute in the ModelSerializers’sMeta
class. This ensures that the OpenAPI definitions of plugins are namespaced properly.When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
validate
(data)¶
-
exclude_arg_name
= 'exclude_fields'¶
-
-
class
pulpcore.plugin.serializers.
MultipleArtifactContentSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.content.Content
-
fields
= ('pulp_href', 'pulp_created', 'artifacts')¶
-
-
create
(validated_data)¶ Create the content and associate it with all its Artifacts.
- Parameters
validated_data (dict) – Data to save to the database
-
class
-
class
pulpcore.plugin.serializers.
NestedRelatedField
(*args, **kwargs)¶ NestedRelatedField for use when relating to nested resources.
When using this field in a serializer, it serializes the related resource as a relative URL.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_url
(obj, view_name, request, *args, **kwargs)¶ Given an object, return the URL that hyperlinks to the object.
May raise a NoReverseMatch if the view_name and lookup_field attributes are not configured to correctly match the URL conf.
-
-
class
pulpcore.plugin.serializers.
NoArtifactContentSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.plugin.serializers.
PublicationDistributionSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.plugin.serializers.
PublicationExportSerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ Serializer for exporting publications.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.plugin.serializers.
PublicationSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.publication.Publication
-
abstract
= True¶
-
fields
= ('pulp_href', 'pulp_created', 'repository_version', 'repository')¶
-
-
validate
(data)¶
-
class
-
class
pulpcore.plugin.serializers.
RelatedField
(view_name=None, **kwargs)¶ RelatedField when relating to non-Master/Detail models
When using this field on a serializer, it will serialize the related resource as a relative URL.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_url
(obj, view_name, request, *args, **kwargs)¶ Given an object, return the URL that hyperlinks to the object.
May raise a NoReverseMatch if the view_name and lookup_field attributes are not configured to correctly match the URL conf.
-
-
class
pulpcore.plugin.serializers.
RemoteSerializer
(*args, **kwargs)¶ Every remote defined by a plugin should have a Remote serializer that inherits from this class. Please import from pulpcore.plugin.serializers rather than from this module directly.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.repository.Remote
-
abstract
= True¶
-
fields
= ('pulp_href', 'pulp_created', 'name', 'url', 'ca_cert', 'client_cert', 'client_key', 'tls_validation', 'proxy_url', 'username', 'password', 'pulp_last_updated', 'download_concurrency', 'policy')¶
-
-
validate_url
(value)¶ Check if the ‘url’ is a
file://
path, and if so, ensure it’s an ALLOWED_IMPORT_PATH.The ALLOWED_IMPORT_PATH is specified as a Pulp setting.
- Parameters
value – The user-provided value for ‘url’ to be validated.
- Raises
ValidationError – When the url starts with file://, but is not a subfolder of a path in the ALLOWED_IMPORT_PATH setting.
- Returns
The validated value.
-
class
-
class
pulpcore.plugin.serializers.
RepositorySerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.plugin.serializers.
RepositorySyncURLSerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.plugin.serializers.
RepositoryVersionDistributionSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
Meta
¶ -
abstract
= True¶
-
fields
= ('pulp_href', 'pulp_created', 'base_path', 'base_url', 'content_guard', 'name', 'repository', 'repository_version')¶
-
-
validate
(data)¶
-
class
-
class
pulpcore.plugin.serializers.
SingleArtifactContentSerializer
(*args, **kwargs)¶ Initializer for SingleArtifactContentSerializer
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.content.Content
-
fields
= ('pulp_href', 'pulp_created', 'artifact', 'relative_path')¶
-
-
create
(validated_data)¶ Create the content and associate it with its Artifact.
- Parameters
validated_data (dict) – Data to save to the database
-
class
-
class
pulpcore.plugin.serializers.
SingleArtifactContentUploadSerializer
(*args, **kwargs)¶ A serializer for content_types with a single Artifact.
The Artifact can either be specified via it’s url, or a new file can be uploaded. Additionally a repository can be specified, to which the content unit will be added.
When using this serializer, the creation of the real content must be wrapped in a task that locks the Artifact and when specified, the repository.
Initializer for SingleArtifactContentUploadSerializer.
-
class
Meta
¶ -
fields
= ('pulp_href', 'pulp_created', 'artifact', 'relative_path', 'file', 'repository')¶
-
-
create
(validated_data)¶ Save the GenericContent unit. This must be used inside a task that locks on the Artifact and if given, the repository.
-
deferred_validate
(data)¶ Validate the content unit by deeply analyzing the specified Artifact.
This is only called when validating without a request context to prevent stalling an ongoing http request. It should be overwritten by plugins to extract metadata from the actual content in much the same way as validate.
-
validate
(data)¶ Validate that we have an Artifact or can create one.
-
class
-
pulpcore.plugin.serializers.
validate_unknown_fields
(initial_data, defined_fields)¶ This will raise a ValidationError if a serializer is passed fields that are unknown. The csrfmiddlewaretoken field is silently ignored.