|
| 1 | +# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md |
| 2 | + |
| 3 | + |
| 4 | +from typing import Any |
1 | 5 | from ocp_resources.resource import NamespacedResource |
| 6 | +from ocp_resources.exceptions import MissingRequiredArgumentError |
2 | 7 |
|
3 | 8 |
|
4 | 9 | class NetworkPolicy(NamespacedResource): |
5 | 10 | """ |
6 | | - NetworkPolicy object. |
| 11 | + NetworkPolicy describes what network traffic is allowed for a set of Pods |
7 | 12 | """ |
8 | 13 |
|
9 | | - api_group = NamespacedResource.ApiGroup.NETWORKING_K8S_IO |
| 14 | + api_group: str = NamespacedResource.ApiGroup.NETWORKING_K8S_IO |
| 15 | + |
| 16 | + def __init__( |
| 17 | + self, |
| 18 | + egress: list[Any] | None = None, |
| 19 | + ingress: list[Any] | None = None, |
| 20 | + pod_selector: dict[str, Any] | None = None, |
| 21 | + policy_types: list[Any] | None = None, |
| 22 | + **kwargs: Any, |
| 23 | + ) -> None: |
| 24 | + r""" |
| 25 | + Args: |
| 26 | + egress (list[Any]): ports endPort port protocol enum: SCTP, TCP, UDP to ipBlock cidr |
| 27 | + except namespaceSelector matchExpressions key operator values |
| 28 | + matchLabels podSelector matchExpressions key operator values |
| 29 | + matchLabels. |
| 30 | +
|
| 31 | + ingress (list[Any]): from ipBlock cidr except namespaceSelector matchExpressions key |
| 32 | + operator values matchLabels podSelector matchExpressions key |
| 33 | + operator values matchLabels ports endPort port protocol enum: |
| 34 | + SCTP, TCP, UDP. |
| 35 | +
|
| 36 | + pod_selector (dict[str, Any]): matchExpressions key operator values matchLabels. |
| 37 | +
|
| 38 | + policy_types (list[Any]): No field description from API |
| 39 | +
|
| 40 | + """ |
| 41 | + super().__init__(**kwargs) |
| 42 | + |
| 43 | + self.egress = egress |
| 44 | + self.ingress = ingress |
| 45 | + self.pod_selector = pod_selector |
| 46 | + self.policy_types = policy_types |
| 47 | + |
| 48 | + def to_dict(self) -> None: |
| 49 | + super().to_dict() |
| 50 | + |
| 51 | + if not self.kind_dict and not self.yaml_file: |
| 52 | + if self.pod_selector is None: |
| 53 | + raise MissingRequiredArgumentError(argument="self.pod_selector") |
| 54 | + |
| 55 | + self.res["spec"] = {} |
| 56 | + _spec = self.res["spec"] |
| 57 | + |
| 58 | + _spec["podSelector"] = self.pod_selector |
| 59 | + |
| 60 | + if self.egress is not None: |
| 61 | + _spec["egress"] = self.egress |
| 62 | + |
| 63 | + if self.ingress is not None: |
| 64 | + _spec["ingress"] = self.ingress |
| 65 | + |
| 66 | + if self.policy_types is not None: |
| 67 | + _spec["policyTypes"] = self.policy_types |
| 68 | + |
| 69 | + # End of generated code |
0 commit comments