Coverage for ocp_resources/virtual_machine_cluster_instancetype.py: 0%

40 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-30 10:48 +0200

1# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md 

2 

3from typing import Any, Dict, List, Optional 

4from ocp_resources.resource import Resource, MissingRequiredArgumentError 

5 

6 

7class VirtualMachineClusterInstancetype(Resource): 

8 """ 

9 VirtualMachineClusterInstancetype is a cluster scoped version of VirtualMachineInstancetype resource. 

10 """ 

11 

12 api_group: str = Resource.ApiGroup.INSTANCETYPE_KUBEVIRT_IO 

13 

14 def __init__( 

15 self, 

16 spec_annotations: Optional[Dict[str, Any]] = None, 

17 cpu: Optional[Dict[str, Any]] = None, 

18 gpus: Optional[List[Any]] = None, 

19 host_devices: Optional[List[Any]] = None, 

20 io_threads_policy: Optional[str] = "", 

21 launch_security: Optional[Dict[str, Any]] = None, 

22 memory: Optional[Dict[str, Any]] = None, 

23 node_selector: Optional[Dict[str, Any]] = None, 

24 scheduler_name: Optional[str] = "", 

25 **kwargs: Any, 

26 ) -> None: 

27 """ 

28 Args: 

29 spec_annotations (Dict[str, Any]): Optionally defines the required Annotations to be used by the instance 

30 type and applied to the VirtualMachineInstance 

31 

32 cpu (Dict[str, Any]): Required CPU related attributes of the instancetype. 

33 

34 gpus (List[Any]): Optionally defines any GPU devices associated with the instancetype. 

35 

36 host_devices (List[Any]): Optionally defines any HostDevices associated with the instancetype. 

37 

38 io_threads_policy (str): Optionally defines the IOThreadsPolicy to be used by the instancetype. 

39 

40 launch_security (Dict[str, Any]): Optionally defines the LaunchSecurity to be used by the instancetype. 

41 

42 memory (Dict[str, Any]): Required Memory related attributes of the instancetype. 

43 

44 node_selector (Dict[str, Any]): NodeSelector is a selector which must be true for the vmi to fit on a 

45 node. Selector which must match a node's labels for the vmi to be 

46 scheduled on that node. More info: 

47 https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ 

48 NodeSelector is the name of the custom node selector for the 

49 instancetype. 

50 

51 scheduler_name (str): If specified, the VMI will be dispatched by specified scheduler. If 

52 not specified, the VMI will be dispatched by default scheduler. 

53 SchedulerName is the name of the custom K8s scheduler for the 

54 instancetype. 

55 

56 """ 

57 super().__init__(**kwargs) 

58 

59 self.spec_annotations = spec_annotations 

60 self.cpu = cpu 

61 self.gpus = gpus 

62 self.host_devices = host_devices 

63 self.io_threads_policy = io_threads_policy 

64 self.launch_security = launch_security 

65 self.memory = memory 

66 self.node_selector = node_selector 

67 self.scheduler_name = scheduler_name 

68 

69 def to_dict(self) -> None: 

70 super().to_dict() 

71 

72 if not self.kind_dict and not self.yaml_file: 

73 if not self.cpu: 

74 raise MissingRequiredArgumentError(argument="self.cpu") 

75 

76 if not self.memory: 

77 raise MissingRequiredArgumentError(argument="self.memory") 

78 

79 self.res["spec"] = {} 

80 _spec = self.res["spec"] 

81 

82 _spec["cpu"] = self.cpu 

83 _spec["memory"] = self.memory 

84 

85 if self.spec_annotations: 

86 _spec["annotations"] = self.spec_annotations 

87 

88 if self.gpus: 

89 _spec["gpus"] = self.gpus 

90 

91 if self.host_devices: 

92 _spec["hostDevices"] = self.host_devices 

93 

94 if self.io_threads_policy: 

95 _spec["ioThreadsPolicy"] = self.io_threads_policy 

96 

97 if self.launch_security: 

98 _spec["launchSecurity"] = self.launch_security 

99 

100 if self.node_selector: 

101 _spec["nodeSelector"] = self.node_selector 

102 

103 if self.scheduler_name: 

104 _spec["schedulerName"] = self.scheduler_name 

105 

106 # End of generated code