Coverage for ocp_resources/csi_storage_capacity.py: 0%

21 statements  

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

1from ocp_resources.resource import MissingRequiredArgumentError, NamespacedResource 

2 

3 

4class CSIStorageCapacity(NamespacedResource): 

5 """ 

6 https://kubernetes.io/docs/reference/kubernetes-api/config-and-storage-resources/csi-storage-capacity-v1/#CSIStorageCapacity 

7 """ 

8 

9 api_group = NamespacedResource.ApiGroup.STORAGE_K8S_IO 

10 

11 def __init__( 

12 self, 

13 capacity=None, 

14 maximum_volume_size=None, 

15 node_topology=None, 

16 storage_class_name=None, 

17 **kwargs, 

18 ): 

19 """ 

20 Args: 

21 capacity (str, optional): value reported by the csi driver 

22 maximum_volume_size (str, optional): maximum volume size reported by csi driver 

23 storage_class_name (str): storage class name 

24 node_topology (dict, optional): defines which node has access to the storage for which capacity 

25 was reported 

26 Example: 

27 node_topology: {'matchLabels': {'topology.hostpath.csi/node': 'c01-dbn-413-4c48b-worker-0-pmtv8'}} 

28 """ 

29 super().__init__(**kwargs) 

30 self.capacity = capacity 

31 self.node_topology = node_topology 

32 self.storage_class_name = storage_class_name 

33 self.maximum_volume_size = maximum_volume_size 

34 

35 def to_dict(self) -> None: 

36 super().to_dict() 

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

38 if not self.storage_class_name: 

39 raise MissingRequiredArgumentError(argument="storage_class_name") 

40 self.res.update({ 

41 "storageClassName": self.storage_class_name, 

42 }) 

43 if self.maximum_volume_size: 

44 self.res["maximumVolumeSize"] = self.maximum_volume_size 

45 if self.node_topology: 

46 self.res["nodeTopology"] = self.node_topology 

47 if self.capacity: 

48 self.res["capacity"] = self.capacity