Skip to content

Commit 1e16b6a

Browse files
authored
VirtualMachineExport - update with class_generator (#2264)
* VirtualMachineExport - remove timeout arg, add typing * Use class generator * remove SourceKind
1 parent ff12fa9 commit 1e16b6a

File tree

1 file changed

+46
-50
lines changed

1 file changed

+46
-50
lines changed
Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,62 @@
1-
# -*- coding: utf-8 -*-
1+
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md
22

3-
from ocp_resources.utils.constants import TIMEOUT_1MINUTE
4-
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
3+
from __future__ import annotations
54
from ocp_resources.resource import MissingRequiredArgumentError, NamespacedResource
6-
from ocp_resources.virtual_machine import VirtualMachine
7-
from ocp_resources.virtual_machine_snapshot import VirtualMachineSnapshot
5+
6+
from typing import Any
87

98

109
class VirtualMachineExport(NamespacedResource):
1110
"""
12-
VirtualMachineExport object.
11+
VirtualMachineExport defines the operation of exporting a VM source
1312
"""
1413

15-
api_group = NamespacedResource.ApiGroup.EXPORT_KUBEVIRT_IO
16-
17-
class SourceKind:
18-
VM = VirtualMachine.kind
19-
VM_SNAPSHOT = VirtualMachineSnapshot.kind
20-
PVC = PersistentVolumeClaim.kind
14+
api_group: str = NamespacedResource.ApiGroup.EXPORT_KUBEVIRT_IO
2115

2216
def __init__(
2317
self,
24-
name=None,
25-
namespace=None,
26-
client=None,
27-
teardown=True,
28-
token_secret_ref=None,
29-
source_api_group=None,
30-
source_kind=None,
31-
source_name=None,
32-
timeout=TIMEOUT_1MINUTE,
33-
delete_timeout=TIMEOUT_1MINUTE,
34-
yaml_file=None,
35-
**kwargs,
36-
):
37-
super().__init__(
38-
name=name,
39-
namespace=namespace,
40-
client=client,
41-
teardown=teardown,
42-
yaml_file=yaml_file,
43-
timeout=timeout,
44-
delete_timeout=delete_timeout,
45-
**kwargs,
46-
)
18+
source: dict[str, Any] | None = None,
19+
token_secret_ref: str | None = None,
20+
ttl_duration: str | None = None,
21+
**kwargs: Any,
22+
) -> None:
23+
"""
24+
Args:
25+
source (dict[str, Any]): TypedLocalObjectReference contains enough information to let you
26+
locate the typed referenced object inside the same namespace.
27+
28+
token_secret_ref (str): TokenSecretRef is the name of the custom-defined secret that contains
29+
the token used by the export server pod
30+
31+
ttl_duration (str): ttlDuration limits the lifetime of an export If this field is set,
32+
after this duration has passed from counting from
33+
CreationTimestamp, the export is eligible to be automatically
34+
deleted. If this field is omitted, a reasonable default is
35+
applied.
36+
37+
"""
38+
super().__init__(**kwargs)
39+
40+
self.source = source
4741
self.token_secret_ref = token_secret_ref
48-
self.source_api_group = source_api_group
49-
self.source_kind = source_kind
50-
self.source_name = source_name
42+
self.ttl_duration = ttl_duration
5143

5244
def to_dict(self) -> None:
5345
super().to_dict()
46+
5447
if not self.kind_dict and not self.yaml_file:
55-
if not (self.source_kind and self.source_name):
56-
raise MissingRequiredArgumentError(argument="'source_kind' and 'source_name'")
57-
self.res.update({
58-
"spec": {
59-
"tokenSecretRef": self.token_secret_ref,
60-
"source": {
61-
"apiGroup": self.source_api_group,
62-
"kind": self.source_kind,
63-
"name": self.source_name,
64-
},
65-
}
66-
})
48+
if self.source is None:
49+
raise MissingRequiredArgumentError(argument="self.source")
50+
51+
self.res["spec"] = {}
52+
_spec = self.res["spec"]
53+
54+
_spec["source"] = self.source
55+
56+
if self.token_secret_ref:
57+
_spec["tokenSecretRef"] = self.token_secret_ref
58+
59+
if self.ttl_duration:
60+
_spec["ttlDuration"] = self.ttl_duration
61+
62+
# End of generated code

0 commit comments

Comments
 (0)