-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VirtualMachineExport - update with class_generator (#2264)
* VirtualMachineExport - remove timeout arg, add typing * Use class generator * remove SourceKind
- Loading branch information
Showing
1 changed file
with
46 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md | ||
|
||
from ocp_resources.utils.constants import TIMEOUT_1MINUTE | ||
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim | ||
from __future__ import annotations | ||
from ocp_resources.resource import MissingRequiredArgumentError, NamespacedResource | ||
from ocp_resources.virtual_machine import VirtualMachine | ||
from ocp_resources.virtual_machine_snapshot import VirtualMachineSnapshot | ||
|
||
from typing import Any | ||
|
||
|
||
class VirtualMachineExport(NamespacedResource): | ||
""" | ||
VirtualMachineExport object. | ||
VirtualMachineExport defines the operation of exporting a VM source | ||
""" | ||
|
||
api_group = NamespacedResource.ApiGroup.EXPORT_KUBEVIRT_IO | ||
|
||
class SourceKind: | ||
VM = VirtualMachine.kind | ||
VM_SNAPSHOT = VirtualMachineSnapshot.kind | ||
PVC = PersistentVolumeClaim.kind | ||
api_group: str = NamespacedResource.ApiGroup.EXPORT_KUBEVIRT_IO | ||
|
||
def __init__( | ||
self, | ||
name=None, | ||
namespace=None, | ||
client=None, | ||
teardown=True, | ||
token_secret_ref=None, | ||
source_api_group=None, | ||
source_kind=None, | ||
source_name=None, | ||
timeout=TIMEOUT_1MINUTE, | ||
delete_timeout=TIMEOUT_1MINUTE, | ||
yaml_file=None, | ||
**kwargs, | ||
): | ||
super().__init__( | ||
name=name, | ||
namespace=namespace, | ||
client=client, | ||
teardown=teardown, | ||
yaml_file=yaml_file, | ||
timeout=timeout, | ||
delete_timeout=delete_timeout, | ||
**kwargs, | ||
) | ||
source: dict[str, Any] | None = None, | ||
token_secret_ref: str | None = None, | ||
ttl_duration: str | None = None, | ||
**kwargs: Any, | ||
) -> None: | ||
""" | ||
Args: | ||
source (dict[str, Any]): TypedLocalObjectReference contains enough information to let you | ||
locate the typed referenced object inside the same namespace. | ||
token_secret_ref (str): TokenSecretRef is the name of the custom-defined secret that contains | ||
the token used by the export server pod | ||
ttl_duration (str): ttlDuration limits the lifetime of an export If this field is set, | ||
after this duration has passed from counting from | ||
CreationTimestamp, the export is eligible to be automatically | ||
deleted. If this field is omitted, a reasonable default is | ||
applied. | ||
""" | ||
super().__init__(**kwargs) | ||
|
||
self.source = source | ||
self.token_secret_ref = token_secret_ref | ||
self.source_api_group = source_api_group | ||
self.source_kind = source_kind | ||
self.source_name = source_name | ||
self.ttl_duration = ttl_duration | ||
|
||
def to_dict(self) -> None: | ||
super().to_dict() | ||
|
||
if not self.kind_dict and not self.yaml_file: | ||
if not (self.source_kind and self.source_name): | ||
raise MissingRequiredArgumentError(argument="'source_kind' and 'source_name'") | ||
self.res.update({ | ||
"spec": { | ||
"tokenSecretRef": self.token_secret_ref, | ||
"source": { | ||
"apiGroup": self.source_api_group, | ||
"kind": self.source_kind, | ||
"name": self.source_name, | ||
}, | ||
} | ||
}) | ||
if self.source is None: | ||
raise MissingRequiredArgumentError(argument="self.source") | ||
|
||
self.res["spec"] = {} | ||
_spec = self.res["spec"] | ||
|
||
_spec["source"] = self.source | ||
|
||
if self.token_secret_ref: | ||
_spec["tokenSecretRef"] = self.token_secret_ref | ||
|
||
if self.ttl_duration: | ||
_spec["ttlDuration"] = self.ttl_duration | ||
|
||
# End of generated code |