Coverage for ocp_resources/machine_config.py: 0%

32 statements  

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

1from typing import Any, Dict, List, Optional 

2from ocp_resources.resource import Resource 

3 

4 

5class MachineConfig(Resource): 

6 """ 

7 https://docs.openshift.com/container-platform/4.16/rest_api/machine_apis/machineconfig-machineconfiguration-openshift-io-v1.html 

8 """ 

9 

10 api_group = Resource.ApiGroup.MACHINECONFIGURATION_OPENSHIFT_IO 

11 

12 def __init__( 

13 self, 

14 os_image_url: Optional[str] = "", 

15 config: Optional[Dict[str, Any]] = None, 

16 kernel_arguments: Optional[List[str]] = None, 

17 extensions: Optional[List[str]] = None, 

18 fips: Optional[bool] = None, 

19 kernel_type: Optional[str] = "", 

20 base_os_extensions_container_image: Optional[str] = "", 

21 **kwargs: Any, 

22 ) -> None: 

23 """ 

24 Args: 

25 os_image_url (str, optional): URL to the OS image. 

26 config (dict, optional): Ignition config file data. 

27 Example: 

28 { 

29 "ignition": { 

30 "version": "3.1.0", 

31 "config": { 

32 "merge": [ 

33 { 

34 "source": "http://path/to/your/config.ign" 

35 } 

36 ] 

37 } 

38 }, 

39 "storage": { 

40 "filesystems": [ 

41 { 

42 "name": "root", 

43 "mount": { 

44 "device": "/dev/disk/by-label/root", 

45 "format": "xfs", 

46 "wipeFilesystem": False 

47 } 

48 } 

49 ] 

50 } 

51 } 

52 kernel_arguments (list, optional): List of kernel arguments. 

53 extensions (list, optional): List of extensions to install. 

54 fips (bool, optional): Enable FIPS mode. Defaults to False. 

55 kernel_type (str, optional): Type of kernel to use. 

56 base_os_extensions_container_image (str, optional): URL to the base OS extensions container image. 

57 """ 

58 super().__init__(**kwargs) 

59 self.os_image_url: Optional[str] = os_image_url 

60 self.config: Optional[Dict[str, Any]] = config 

61 self.kernel_arguments: Optional[List[str]] = kernel_arguments 

62 self.extensions: Optional[List[str]] = extensions 

63 self.fips: Optional[bool] = fips 

64 self.kernel_type: Optional[str] = kernel_type 

65 self.base_os_extensions_container_image: Optional[str] = base_os_extensions_container_image 

66 

67 def to_dict(self) -> None: 

68 super().to_dict() 

69 

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

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

72 _spec = self.res["spec"] 

73 

74 if self.os_image_url: 

75 _spec["osImageURL"] = self.os_image_url 

76 

77 if self.config: 

78 _spec["config"] = self.config 

79 

80 if self.kernel_arguments: 

81 _spec["kernelArguments"] = self.kernel_arguments 

82 

83 if self.extensions: 

84 _spec["extensions"] = self.extensions 

85 

86 if self.fips is not None: 

87 _spec["fips"] = self.fips 

88 

89 if self.kernel_type: 

90 _spec["kernelType"] = self.kernel_type 

91 

92 if self.base_os_extensions_container_image: 

93 _spec["baseOSExtensionsContainerImage"] = self.base_os_extensions_container_image