Coverage for ocp_resources/application_aware_resource_quota.py: 0%

22 statements  

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

1# API reference: https://github.com/kubevirt/application-aware-quota/tree/main/staging/src/kubevirt.io/application-aware-quota-api/pkg/apis/core/v1alpha1 

2# TODO: update API reference when OCP doc is available 

3from __future__ import annotations 

4from typing import Dict, Any, List 

5 

6from ocp_resources.resource import MissingRequiredArgumentError, NamespacedResource 

7 

8 

9class ApplicationAwareResourceQuota(NamespacedResource): 

10 api_group = NamespacedResource.ApiGroup.AAQ_KUBEVIRT_IO 

11 

12 def __init__( 

13 self, 

14 hard: Dict[str, Any] | None = None, 

15 scope_selector: Dict[str, Any] | None = None, 

16 scopes: List[str] | None = None, 

17 **kwargs: Any, 

18 ) -> None: 

19 """ 

20 Create ApplicationAwareResourceQuota object. 

21 

22 Args: 

23 hard (dict): set of desired hard limits 

24 example: {"pod": 3, "requests.cpu": "500m", "requests.memory/vmi": "4Gi", "requests.instances/vmi": 2} 

25 scope_selector (dict, optional): collection of filters 

26 example: {"matchExpressions": [{"operator": "In", "scopeName": "PriorityClass", "values": ["low"]}]} 

27 scopes (list, optional): collection of filters 

28 example: ["Terminating", "PriorityClass"] 

29 """ 

30 super().__init__(**kwargs) 

31 self.hard = hard 

32 self.scope_selector = scope_selector 

33 self.scopes = scopes 

34 

35 def to_dict(self): 

36 super().to_dict() 

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

38 if not self.hard: 

39 raise MissingRequiredArgumentError(argument="hard") 

40 

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

42 _spec = self.res["spec"] 

43 

44 _spec["hard"] = self.hard 

45 

46 if self.scope_selector: 

47 _spec["scopeSelector"] = self.scope_selector 

48 

49 if self.scopes: 

50 _spec["scopes"] = self.scopes