Skip to content

Commit 2e98482

Browse files
authored
feat: Update virtual_machine_instance.py with class generator (#2644)
Signed-off-by: Roni Kishner <rkishner@redhat.com>
1 parent 68c412c commit 2e98482

1 file changed

Lines changed: 225 additions & 21 deletions

File tree

ocp_resources/virtual_machine_instance.py

Lines changed: 225 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md
2+
3+
14
import shlex
25
from typing import Any
36
from warnings import warn
@@ -6,6 +9,7 @@
69
from kubernetes.dynamic.exceptions import ResourceNotFoundError
710
from timeout_sampler import TimeoutExpiredError, TimeoutSampler
811

12+
from ocp_resources.exceptions import MissingRequiredArgumentError
913
from ocp_resources.node import Node
1014
from ocp_resources.pod import Pod
1115
from ocp_resources.resource import NamespacedResource
@@ -14,32 +18,232 @@
1418

1519
class VirtualMachineInstance(NamespacedResource):
1620
"""
17-
Virtual Machine Instance object, inherited from Resource.
21+
VirtualMachineInstance is *the* VirtualMachineInstance Definition. It represents a virtual machine in the runtime environment of kubernetes.
1822
"""
1923

20-
api_group = NamespacedResource.ApiGroup.KUBEVIRT_IO
21-
22-
class Status(NamespacedResource.Status):
23-
SCHEDULING = "Scheduling"
24-
SCHEDULED = "Scheduled"
24+
api_group: str = NamespacedResource.ApiGroup.KUBEVIRT_IO
2525

2626
def __init__(
2727
self,
28-
name=None,
29-
namespace=None,
30-
client=None,
31-
yaml_file=None,
32-
delete_timeout=TIMEOUT_4MINUTES,
33-
**kwargs,
34-
):
35-
super().__init__(
36-
name=name,
37-
namespace=namespace,
38-
client=client,
39-
yaml_file=yaml_file,
40-
delete_timeout=delete_timeout,
41-
**kwargs,
42-
)
28+
access_credentials: list[Any] | None = None,
29+
affinity: dict[str, Any] | None = None,
30+
architecture: str | None = None,
31+
dns_config: dict[str, Any] | None = None,
32+
dns_policy: str | None = None,
33+
domain: dict[str, Any] | None = None,
34+
eviction_strategy: str | None = None,
35+
hostname: str | None = None,
36+
liveness_probe: dict[str, Any] | None = None,
37+
networks: list[Any] | None = None,
38+
node_selector: dict[str, Any] | None = None,
39+
priority_class_name: str | None = None,
40+
readiness_probe: dict[str, Any] | None = None,
41+
resource_claims: list[Any] | None = None,
42+
scheduler_name: str | None = None,
43+
start_strategy: str | None = None,
44+
subdomain: str | None = None,
45+
termination_grace_period_seconds: int | None = None,
46+
tolerations: list[Any] | None = None,
47+
topology_spread_constraints: list[Any] | None = None,
48+
volumes: list[Any] | None = None,
49+
**kwargs: Any,
50+
) -> None:
51+
r"""
52+
Args:
53+
access_credentials (list[Any]): Specifies a set of public keys to inject into the vm guest
54+
55+
affinity (dict[str, Any]): If affinity is specifies, obey all the affinity rules
56+
57+
architecture (str): Specifies the architecture of the vm guest you are attempting to run.
58+
Defaults to the compiled architecture of the KubeVirt components
59+
60+
dns_config (dict[str, Any]): Specifies the DNS parameters of a pod. Parameters specified here will
61+
be merged to the generated DNS configuration based on DNSPolicy.
62+
63+
dns_policy (str): Set DNS policy for the pod. Defaults to "ClusterFirst". Valid values
64+
are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or
65+
'None'. DNS parameters given in DNSConfig will be merged with the
66+
policy selected with DNSPolicy. To have DNS options set along with
67+
hostNetwork, you have to specify DNS policy explicitly to
68+
'ClusterFirstWithHostNet'.
69+
70+
domain (dict[str, Any]): Specification of the desired behavior of the VirtualMachineInstance on
71+
the host.
72+
73+
eviction_strategy (str): EvictionStrategy describes the strategy to follow when a node drain
74+
occurs. The possible options are: - "None": No action will be
75+
taken, according to the specified 'RunStrategy' the VirtualMachine
76+
will be restarted or shutdown. - "LiveMigrate": the
77+
VirtualMachineInstance will be migrated instead of being shutdown.
78+
- "LiveMigrateIfPossible": the same as "LiveMigrate" but only if
79+
the VirtualMachine is Live-Migratable, otherwise it will behave as
80+
"None". - "External": the VirtualMachineInstance will be protected
81+
and 'vmi.Status.EvacuationNodeName' will be set on eviction. This
82+
is mainly useful for cluster-api-provider-kubevirt (capk) which
83+
needs a way for VMI's to be blocked from eviction, yet signal capk
84+
that eviction has been called on the VMI so the capk controller
85+
can handle tearing the VMI down. Details can be found in the
86+
commit description https://github.com/kubevirt/kubevirt/commit/c1d
87+
77face705c8b126696bac9a3ee3825f27f1fa.
88+
89+
hostname (str): Specifies the hostname of the vmi If not specified, the hostname will
90+
be set to the name of the vmi, if dhcp or cloud-init is configured
91+
properly.
92+
93+
liveness_probe (dict[str, Any]): Periodic probe of VirtualMachineInstance liveness.
94+
VirtualmachineInstances will be stopped if the probe fails. Cannot
95+
be updated. More info:
96+
https://kubernetes.io/docs/concepts/workloads/pods/pod-
97+
lifecycle#container-probes
98+
99+
networks (list[Any]): List of networks that can be attached to a vm's virtual interface.
100+
101+
node_selector (dict[str, Any]): NodeSelector is a selector which must be true for the vmi to fit on a
102+
node. Selector which must match a node's labels for the vmi to be
103+
scheduled on that node. More info:
104+
https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
105+
106+
priority_class_name (str): If specified, indicates the pod's priority. If not specified, the pod
107+
priority will be default or zero if there is no default.
108+
109+
readiness_probe (dict[str, Any]): Periodic probe of VirtualMachineInstance service readiness.
110+
VirtualmachineInstances will be removed from service endpoints if
111+
the probe fails. Cannot be updated. More info:
112+
https://kubernetes.io/docs/concepts/workloads/pods/pod-
113+
lifecycle#container-probes
114+
115+
resource_claims (list[Any]): ResourceClaims define which ResourceClaims must be allocated and
116+
reserved before the VMI, hence virt-launcher pod is allowed to
117+
start. The resources will be made available to the domain which
118+
consumes them by name. This is an alpha field and requires
119+
enabling the DynamicResourceAllocation feature gate in kubernetes
120+
https://kubernetes.io/docs/concepts/scheduling-eviction/dynamic-
121+
resource-allocation/ This field should only be configured if one
122+
of the feature-gates GPUsWithDRA or HostDevicesWithDRA is enabled.
123+
This feature is in alpha.
124+
125+
scheduler_name (str): If specified, the VMI will be dispatched by specified scheduler. If
126+
not specified, the VMI will be dispatched by default scheduler.
127+
128+
start_strategy (str): StartStrategy can be set to "Paused" if Virtual Machine should be
129+
started in paused state.
130+
131+
subdomain (str): If specified, the fully qualified vmi hostname will be
132+
"<hostname>.<subdomain>.<pod namespace>.svc.<cluster domain>". If
133+
not specified, the vmi will not have a domainname at all. The DNS
134+
entry will resolve to the vmi, no matter if the vmi itself can
135+
pick up a hostname.
136+
137+
termination_grace_period_seconds (int): Grace period observed after signalling a VirtualMachineInstance to
138+
stop after which the VirtualMachineInstance is force terminated.
139+
140+
tolerations (list[Any]): If toleration is specified, obey all the toleration rules.
141+
142+
topology_spread_constraints (list[Any]): TopologySpreadConstraints describes how a group of VMIs will be spread
143+
across a given topology domains. K8s scheduler will schedule VMI
144+
pods in a way which abides by the constraints.
145+
146+
volumes (list[Any]): List of volumes that can be mounted by disks belonging to the vmi.
147+
148+
"""
149+
super().__init__(**kwargs)
150+
151+
self.access_credentials = access_credentials
152+
self.affinity = affinity
153+
self.architecture = architecture
154+
self.dns_config = dns_config
155+
self.dns_policy = dns_policy
156+
self.domain = domain
157+
self.eviction_strategy = eviction_strategy
158+
self.hostname = hostname
159+
self.liveness_probe = liveness_probe
160+
self.networks = networks
161+
self.node_selector = node_selector
162+
self.priority_class_name = priority_class_name
163+
self.readiness_probe = readiness_probe
164+
self.resource_claims = resource_claims
165+
self.scheduler_name = scheduler_name
166+
self.start_strategy = start_strategy
167+
self.subdomain = subdomain
168+
self.termination_grace_period_seconds = termination_grace_period_seconds
169+
self.tolerations = tolerations
170+
self.topology_spread_constraints = topology_spread_constraints
171+
self.volumes = volumes
172+
173+
def to_dict(self) -> None:
174+
175+
super().to_dict()
176+
177+
if not self.kind_dict and not self.yaml_file:
178+
if self.domain is None:
179+
raise MissingRequiredArgumentError(argument="self.domain")
180+
181+
self.res["spec"] = {}
182+
_spec = self.res["spec"]
183+
184+
_spec["domain"] = self.domain
185+
186+
if self.access_credentials is not None:
187+
_spec["accessCredentials"] = self.access_credentials
188+
189+
if self.affinity is not None:
190+
_spec["affinity"] = self.affinity
191+
192+
if self.architecture is not None:
193+
_spec["architecture"] = self.architecture
194+
195+
if self.dns_config is not None:
196+
_spec["dnsConfig"] = self.dns_config
197+
198+
if self.dns_policy is not None:
199+
_spec["dnsPolicy"] = self.dns_policy
200+
201+
if self.eviction_strategy is not None:
202+
_spec["evictionStrategy"] = self.eviction_strategy
203+
204+
if self.hostname is not None:
205+
_spec["hostname"] = self.hostname
206+
207+
if self.liveness_probe is not None:
208+
_spec["livenessProbe"] = self.liveness_probe
209+
210+
if self.networks is not None:
211+
_spec["networks"] = self.networks
212+
213+
if self.node_selector is not None:
214+
_spec["nodeSelector"] = self.node_selector
215+
216+
if self.priority_class_name is not None:
217+
_spec["priorityClassName"] = self.priority_class_name
218+
219+
if self.readiness_probe is not None:
220+
_spec["readinessProbe"] = self.readiness_probe
221+
222+
if self.resource_claims is not None:
223+
_spec["resourceClaims"] = self.resource_claims
224+
225+
if self.scheduler_name is not None:
226+
_spec["schedulerName"] = self.scheduler_name
227+
228+
if self.start_strategy is not None:
229+
_spec["startStrategy"] = self.start_strategy
230+
231+
if self.subdomain is not None:
232+
_spec["subdomain"] = self.subdomain
233+
234+
if self.termination_grace_period_seconds is not None:
235+
_spec["terminationGracePeriodSeconds"] = self.termination_grace_period_seconds
236+
237+
if self.tolerations is not None:
238+
_spec["tolerations"] = self.tolerations
239+
240+
if self.topology_spread_constraints is not None:
241+
_spec["topologySpreadConstraints"] = self.topology_spread_constraints
242+
243+
if self.volumes is not None:
244+
_spec["volumes"] = self.volumes
245+
246+
# End of generated code
43247

44248
@property
45249
def _subresource_api_url(self):

0 commit comments

Comments
 (0)