|
| 1 | +# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md |
| 2 | + |
| 3 | +from __future__ import annotations |
1 | 4 | from ocp_resources.resource import MissingRequiredArgumentError, NamespacedResource
|
2 | 5 |
|
| 6 | +from typing import Any |
| 7 | + |
3 | 8 |
|
4 | 9 | class DataImportCron(NamespacedResource):
|
5 | 10 | """
|
6 |
| - https://kubevirt.io/cdi-api-reference/main/definitions.html#_v1beta1_dataimportcron |
| 11 | + DataImportCron defines a cron job for recurring polling/importing disk images as PVCs into a golden image namespace |
7 | 12 | """
|
8 | 13 |
|
9 |
| - api_group = NamespacedResource.ApiGroup.CDI_KUBEVIRT_IO |
| 14 | + api_group: str = NamespacedResource.ApiGroup.CDI_KUBEVIRT_IO |
10 | 15 |
|
11 | 16 | def __init__(
|
12 | 17 | self,
|
13 |
| - image_stream=None, |
14 |
| - url=None, |
15 |
| - cert_configmap=None, |
16 |
| - pull_method=None, |
17 |
| - storage_class=None, |
18 |
| - size=None, |
19 |
| - schedule=None, |
20 |
| - garbage_collect=None, |
21 |
| - managed_data_source=None, |
22 |
| - imports_to_keep=None, |
23 |
| - bind_immediate_annotation=None, |
24 |
| - **kwargs, |
25 |
| - ): |
| 18 | + garbage_collect: str | None = None, |
| 19 | + imports_to_keep: int | None = None, |
| 20 | + managed_data_source: str | None = None, |
| 21 | + retention_policy: str | None = None, |
| 22 | + schedule: str | None = None, |
| 23 | + template: dict[str, Any] | None = None, |
| 24 | + **kwargs: Any, |
| 25 | + ) -> None: |
26 | 26 | """
|
27 | 27 | Args:
|
28 |
| - garbage_collect (str, optional): whether old PVCs should be cleaned up after a new PVC is imported. |
29 |
| - Options are "Outdated"/"Never". |
30 |
| - imports_to_keep (int, optional): number of import PVCs to keep when garbage collecting. |
31 |
| - managed_data_source(str, optional): specifies the name of the corresponding DataSource to manage. |
32 |
| - DataSource has to be in the same namespace. |
33 |
| - schedule (str, optional): specifies in cron format when and how often to look for new imports. |
34 |
| - storage_class (str, optional): Name of the StorageClass required by the claim. |
35 |
| - size (str): Size of the resources claim quantity. Format is size+size unit, for example: "5Gi". |
36 |
| - url (str, optional): URL is the url of the registry source (starting with the scheme: docker, oci-archive). |
37 |
| - cert_configmap (str, optional): CertConfigMap provides a reference to the Registry certs |
38 |
| - image_stream (str, optional): ImageStream is the name of image stream for import |
39 |
| - bind_immediate_annotation (bool, optional): when WaitForFirstConsumer is set in StorageClass and the |
40 |
| - DataSource should be bound immediately. |
41 |
| - pull_method (str): can be either "pod" or "node" (node docker cache based import) |
| 28 | + garbage_collect (str): GarbageCollect specifies whether old PVCs should be cleaned up after a |
| 29 | + new PVC is imported. Options are currently "Outdated" and "Never", |
| 30 | + defaults to "Outdated". |
| 31 | +
|
| 32 | + imports_to_keep (int): Number of import PVCs to keep when garbage collecting. Default is 3. |
| 33 | +
|
| 34 | + managed_data_source (str): ManagedDataSource specifies the name of the corresponding DataSource |
| 35 | + this cron will manage. DataSource has to be in the same namespace. |
| 36 | +
|
| 37 | + retention_policy (str): RetentionPolicy specifies whether the created DataVolumes and |
| 38 | + DataSources are retained when their DataImportCron is deleted. |
| 39 | + Default is RatainAll. |
| 40 | +
|
| 41 | + schedule (str): Schedule specifies in cron format when and how often to look for new |
| 42 | + imports |
| 43 | +
|
| 44 | + template (dict[str, Any]): Template specifies template for the DVs to be created |
| 45 | +
|
42 | 46 | """
|
43 | 47 | super().__init__(**kwargs)
|
44 |
| - self.image_stream = image_stream |
45 |
| - self.url = url |
46 |
| - self.cert_configmap = cert_configmap |
47 |
| - self.pull_method = pull_method |
48 |
| - self.storage_class = storage_class |
49 |
| - self.size = size |
50 |
| - self.schedule = schedule |
| 48 | + |
51 | 49 | self.garbage_collect = garbage_collect
|
52 |
| - self.managed_data_source = managed_data_source |
53 | 50 | self.imports_to_keep = imports_to_keep
|
54 |
| - self.bind_immediate_annotation = bind_immediate_annotation |
| 51 | + self.managed_data_source = managed_data_source |
| 52 | + self.retention_policy = retention_policy |
| 53 | + self.schedule = schedule |
| 54 | + self.template = template |
55 | 55 |
|
56 | 56 | def to_dict(self) -> None:
|
57 | 57 | super().to_dict()
|
| 58 | + |
58 | 59 | if not self.kind_dict and not self.yaml_file:
|
59 |
| - if self.image_stream and self.url: |
60 |
| - raise ValueError("imageStream and url cannot coexist") |
61 |
| - |
62 |
| - if not self.pull_method: |
63 |
| - raise MissingRequiredArgumentError(argument="pull_method") |
64 |
| - |
65 |
| - self.res.update({ |
66 |
| - "spec": { |
67 |
| - "template": {"spec": {"source": {"registry": {"pullMethod": self.pull_method}}}}, |
68 |
| - } |
69 |
| - }) |
70 |
| - spec = self.res["spec"]["template"]["spec"] |
71 |
| - |
72 |
| - if self.bind_immediate_annotation: |
73 |
| - self.res["metadata"].setdefault("annotations", {}).update({ |
74 |
| - f"{NamespacedResource.ApiGroup.CDI_KUBEVIRT_IO}/storage.bind.immediate.requested": ("true") |
75 |
| - }) |
76 |
| - if self.image_stream: |
77 |
| - spec["source"]["registry"]["imageStream"] = self.image_stream |
78 |
| - if self.url: |
79 |
| - spec["source"]["registry"]["url"] = self.url |
80 |
| - if self.cert_configmap: |
81 |
| - spec["source"]["registry"]["certConfigMap"] = self.cert_configmap |
82 |
| - if self.schedule: |
83 |
| - self.res["spec"]["schedule"] = self.schedule |
84 |
| - if self.garbage_collect: |
85 |
| - self.res["spec"]["garbageCollect"] = self.garbage_collect |
86 |
| - if self.managed_data_source: |
87 |
| - self.res["spec"]["managedDataSource"] = self.managed_data_source |
88 |
| - if self.imports_to_keep: |
89 |
| - self.res["spec"]["importsToKeep"] = self.imports_to_keep |
90 |
| - |
91 |
| - storage = {} |
92 |
| - if self.size: |
93 |
| - storage["resources"] = {"requests": {"storage": self.size}} |
94 |
| - if self.storage_class: |
95 |
| - storage["storageClassName"] = self.storage_class |
96 |
| - if storage: |
97 |
| - spec["storage"] = storage |
| 60 | + if self.managed_data_source is None: |
| 61 | + raise MissingRequiredArgumentError(argument="self.managed_data_source") |
| 62 | + |
| 63 | + if self.schedule is None: |
| 64 | + raise MissingRequiredArgumentError(argument="self.schedule") |
| 65 | + |
| 66 | + if self.template is None: |
| 67 | + raise MissingRequiredArgumentError(argument="self.template") |
| 68 | + |
| 69 | + self.res["spec"] = {} |
| 70 | + _spec = self.res["spec"] |
| 71 | + |
| 72 | + _spec["managedDataSource"] = self.managed_data_source |
| 73 | + _spec["schedule"] = self.schedule |
| 74 | + _spec["template"] = self.template |
| 75 | + |
| 76 | + if self.garbage_collect is not None: |
| 77 | + _spec["garbageCollect"] = self.garbage_collect |
| 78 | + |
| 79 | + if self.imports_to_keep is not None: |
| 80 | + _spec["importsToKeep"] = self.imports_to_keep |
| 81 | + |
| 82 | + if self.retention_policy is not None: |
| 83 | + _spec["retentionPolicy"] = self.retention_policy |
| 84 | + |
| 85 | + # End of generated code |
0 commit comments