Coverage for ocp_resources/migration_policy.py: 0%
28 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 10:48 +0200
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 10:48 +0200
1from ocp_resources.resource import Resource
4class MigrationPolicy(Resource):
5 api_group = Resource.ApiGroup.MIGRATIONS_KUBEVIRT_IO
7 def __init__(
8 self,
9 name=None,
10 allow_auto_converge=None,
11 allow_post_copy=None,
12 bandwidth_per_migration=None,
13 completion_timeout_per_gb=None,
14 namespace_selector=None,
15 vmi_selector=None,
16 **kwargs,
17 ):
18 """
19 Create MigrationPolicy object.
21 Args:
22 name (str): Migration Policy name
23 allow_auto_converge (bool, optional)
24 allow_post_copy (bool, optional)
25 bandwidth_per_migration (str, optional, i.e. "1Gi")
26 completion_timeout_per_gb (int, optional)
27 namespace_selector (dict, optional): Dict of Namespace labels to match (e.g. {"project-owner": "redhat"})
28 vmi_selector (dict, optional): Dict of VMI labels to match (e.g. {"best-vm": ""})
29 """
30 super().__init__(
31 name=name,
32 **kwargs,
33 )
34 self.allow_auto_converge = allow_auto_converge
35 self.allow_post_copy = allow_post_copy
36 self.bandwidth_per_migration = bandwidth_per_migration
37 self.completion_timeout_per_gb = completion_timeout_per_gb
38 self.namespace_selector = namespace_selector or {}
39 self.vmi_selector = vmi_selector or {}
41 def to_dict(self) -> None:
42 super().to_dict()
43 if not self.kind_dict and not self.yaml_file:
44 spec = self.res.setdefault("spec", {})
45 selectors = spec.setdefault("selectors", {})
47 if self.allow_auto_converge is not None:
48 self.res["spec"]["allowAutoConverge"] = self.allow_auto_converge
49 if self.allow_post_copy is not None:
50 self.res["spec"]["allowPostCopy"] = self.allow_post_copy
51 if self.bandwidth_per_migration:
52 self.res["spec"]["bandwidthPerMigration"] = self.bandwidth_per_migration
53 if self.completion_timeout_per_gb:
54 self.res["spec"]["completionTimeoutPerGiB"] = self.completion_timeout_per_gb
56 if self.namespace_selector:
57 selectors.setdefault("namespaceSelector", self.namespace_selector)
59 if self.vmi_selector:
60 selectors.setdefault("virtualMachineInstanceSelector", self.vmi_selector)