openshift-python-wrapper 4.11.61__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. ocp_resources/__init__.py +0 -0
  2. ocp_resources/api_service.py +9 -0
  3. ocp_resources/backup.py +52 -0
  4. ocp_resources/benchmark.py +92 -0
  5. ocp_resources/catalog_source.py +63 -0
  6. ocp_resources/catalog_source_config.py +86 -0
  7. ocp_resources/cdi.py +13 -0
  8. ocp_resources/cdi_config.py +52 -0
  9. ocp_resources/chaos_engine.py +30 -0
  10. ocp_resources/chaos_result.py +11 -0
  11. ocp_resources/cluster_operator.py +5 -0
  12. ocp_resources/cluster_role.py +70 -0
  13. ocp_resources/cluster_role_binding.py +36 -0
  14. ocp_resources/cluster_service_version.py +8 -0
  15. ocp_resources/cluster_version.py +5 -0
  16. ocp_resources/configmap.py +37 -0
  17. ocp_resources/console_cli_download.py +9 -0
  18. ocp_resources/console_plugin.py +9 -0
  19. ocp_resources/console_quick_start.py +9 -0
  20. ocp_resources/constants.py +26 -0
  21. ocp_resources/csidriver.py +9 -0
  22. ocp_resources/custom_resource_definition.py +5 -0
  23. ocp_resources/daemonset.py +61 -0
  24. ocp_resources/data_import_cron.py +100 -0
  25. ocp_resources/data_source.py +59 -0
  26. ocp_resources/datavolume.py +275 -0
  27. ocp_resources/deployment.py +65 -0
  28. ocp_resources/destination_rule.py +11 -0
  29. ocp_resources/event.py +114 -0
  30. ocp_resources/forklift_controller.py +10 -0
  31. ocp_resources/gateway.py +11 -0
  32. ocp_resources/hook.py +52 -0
  33. ocp_resources/host.py +64 -0
  34. ocp_resources/hostpath_provisioner.py +50 -0
  35. ocp_resources/hyperconverged.py +43 -0
  36. ocp_resources/image.py +9 -0
  37. ocp_resources/image_content_source_policy.py +9 -0
  38. ocp_resources/image_stream.py +48 -0
  39. ocp_resources/imagestreamtag.py +9 -0
  40. ocp_resources/infrastructure.py +18 -0
  41. ocp_resources/installplan.py +8 -0
  42. ocp_resources/job.py +65 -0
  43. ocp_resources/kube_descheduler.py +65 -0
  44. ocp_resources/kubevirt.py +5 -0
  45. ocp_resources/kubevirt_common_templates_bundle.py +5 -0
  46. ocp_resources/kubevirt_metrics_aggregation.py +5 -0
  47. ocp_resources/kubevirt_node_labeller_bundle.py +5 -0
  48. ocp_resources/kubevirt_template_validaotr.py +5 -0
  49. ocp_resources/logger.py +76 -0
  50. ocp_resources/machine.py +50 -0
  51. ocp_resources/machine_config.py +5 -0
  52. ocp_resources/machine_config_pool.py +9 -0
  53. ocp_resources/machine_health_check.py +76 -0
  54. ocp_resources/machine_set.py +189 -0
  55. ocp_resources/migration.py +63 -0
  56. ocp_resources/migration_policy.py +66 -0
  57. ocp_resources/mtv.py +171 -0
  58. ocp_resources/mutating_webhook_config.py +9 -0
  59. ocp_resources/namespace.py +40 -0
  60. ocp_resources/network.py +5 -0
  61. ocp_resources/network_addons_config.py +9 -0
  62. ocp_resources/network_attachment_definition.py +24 -0
  63. ocp_resources/network_map.py +64 -0
  64. ocp_resources/network_policy.py +9 -0
  65. ocp_resources/nmstate.py +9 -0
  66. ocp_resources/node.py +41 -0
  67. ocp_resources/node_health_check.py +10 -0
  68. ocp_resources/node_maintenance.py +40 -0
  69. ocp_resources/node_network_configuration_enactment.py +20 -0
  70. ocp_resources/node_network_configuration_policy.py +472 -0
  71. ocp_resources/node_network_state.py +121 -0
  72. ocp_resources/oauth.py +9 -0
  73. ocp_resources/operator_condition.py +5 -0
  74. ocp_resources/operator_group.py +37 -0
  75. ocp_resources/operator_hub.py +5 -0
  76. ocp_resources/operator_source.py +50 -0
  77. ocp_resources/package_manifest.py +5 -0
  78. ocp_resources/peer_authentication.py +18 -0
  79. ocp_resources/persistent_volume.py +27 -0
  80. ocp_resources/persistent_volume_claim.py +103 -0
  81. ocp_resources/plan.py +143 -0
  82. ocp_resources/pod.py +175 -0
  83. ocp_resources/pod_disruption_budget.py +53 -0
  84. ocp_resources/priority_class.py +48 -0
  85. ocp_resources/project.py +60 -0
  86. ocp_resources/prometheus.py +9 -0
  87. ocp_resources/prometheus_rule.py +9 -0
  88. ocp_resources/provider.py +59 -0
  89. ocp_resources/replicaset.py +11 -0
  90. ocp_resources/resource.py +1383 -0
  91. ocp_resources/restore.py +52 -0
  92. ocp_resources/role.py +11 -0
  93. ocp_resources/role_binding.py +67 -0
  94. ocp_resources/route.py +76 -0
  95. ocp_resources/secret.py +75 -0
  96. ocp_resources/security_context_constraints.py +9 -0
  97. ocp_resources/service.py +16 -0
  98. ocp_resources/service_account.py +9 -0
  99. ocp_resources/service_mesh_control_plane.py +11 -0
  100. ocp_resources/service_mesh_member_roll.py +14 -0
  101. ocp_resources/service_monitor.py +9 -0
  102. ocp_resources/sriov_network.py +54 -0
  103. ocp_resources/sriov_network_node_policy.py +67 -0
  104. ocp_resources/sriov_network_node_state.py +44 -0
  105. ocp_resources/ssp.py +9 -0
  106. ocp_resources/storage_class.py +47 -0
  107. ocp_resources/storage_map.py +67 -0
  108. ocp_resources/storage_profile.py +7 -0
  109. ocp_resources/subscription.py +66 -0
  110. ocp_resources/tekton_tasks.py +9 -0
  111. ocp_resources/template.py +74 -0
  112. ocp_resources/upload_token_request.py +39 -0
  113. ocp_resources/utils.py +278 -0
  114. ocp_resources/validating_webhook_config.py +9 -0
  115. ocp_resources/virtual_machine.py +177 -0
  116. ocp_resources/virtual_machine_Instance_replica_set.py +9 -0
  117. ocp_resources/virtual_machine_cluster_flavor.py +5 -0
  118. ocp_resources/virtual_machine_flavor.py +5 -0
  119. ocp_resources/virtual_machine_import.py +307 -0
  120. ocp_resources/virtual_machine_instance.py +322 -0
  121. ocp_resources/virtual_machine_instance_migration.py +36 -0
  122. ocp_resources/virtual_machine_instance_preset.py +9 -0
  123. ocp_resources/virtual_machine_restore.py +99 -0
  124. ocp_resources/virtual_machine_snapshot.py +96 -0
  125. ocp_resources/virtual_service.py +11 -0
  126. ocp_resources/vm_import_config.py +9 -0
  127. ocp_resources/volume_snapshot.py +9 -0
  128. ocp_resources/volume_snapshot_class.py +9 -0
  129. openshift_python_wrapper-4.11.61.dist-info/LICENSE +201 -0
  130. openshift_python_wrapper-4.11.61.dist-info/METADATA +188 -0
  131. openshift_python_wrapper-4.11.61.dist-info/RECORD +132 -0
  132. openshift_python_wrapper-4.11.61.dist-info/WHEEL +4 -0
ocp_resources/pod.py ADDED
@@ -0,0 +1,175 @@
1
+ import json
2
+
3
+ import kubernetes
4
+
5
+ from ocp_resources.constants import TIMEOUT_4MINUTES
6
+ from ocp_resources.node import Node
7
+ from ocp_resources.resource import NamespacedResource, kube_v1_api
8
+ from ocp_resources.utils import TimeoutWatch
9
+
10
+
11
+ class ExecOnPodError(Exception):
12
+ def __init__(self, command, rc, out, err):
13
+ self.cmd = command
14
+ self.rc = rc
15
+ self.out = out
16
+ self.err = err
17
+
18
+ def __str__(self):
19
+ return (
20
+ f"Command execution failure: "
21
+ f"{self.cmd}, "
22
+ f"RC: {self.rc}, "
23
+ f"OUT: {self.out}, "
24
+ f"ERR: {self.err}"
25
+ )
26
+
27
+
28
+ class Pod(NamespacedResource):
29
+ """
30
+ Pod object, inherited from Resource.
31
+ """
32
+
33
+ api_version = NamespacedResource.ApiVersion.V1
34
+
35
+ class Status(NamespacedResource.Status):
36
+ CRASH_LOOPBACK_OFF = "CrashLoopBackOff"
37
+ IMAGE_PULL_BACK_OFF = "ImagePullBackOff"
38
+ ERR_IMAGE_PULL = "ErrImagePull"
39
+
40
+ def __init__(
41
+ self,
42
+ name=None,
43
+ namespace=None,
44
+ client=None,
45
+ teardown=True,
46
+ privileged_client=None,
47
+ yaml_file=None,
48
+ delete_timeout=TIMEOUT_4MINUTES,
49
+ **kwargs,
50
+ ):
51
+ super().__init__(
52
+ name=name,
53
+ namespace=namespace,
54
+ client=client,
55
+ teardown=teardown,
56
+ privileged_client=privileged_client,
57
+ yaml_file=yaml_file,
58
+ delete_timeout=delete_timeout,
59
+ **kwargs,
60
+ )
61
+
62
+ @property
63
+ def containers(self):
64
+ """
65
+ Get Pod containers
66
+
67
+ Returns:
68
+ list: List of Pod containers
69
+ """
70
+ return self.instance.spec.containers
71
+
72
+ def execute(self, command, timeout=60, container=None, ignore_rc=False):
73
+ """
74
+ Run command on Pod
75
+
76
+ Args:
77
+ command (list): Command to run.
78
+ timeout (int): Time to wait for the command.
79
+ container (str): Container name where to exec the command.
80
+ ignore_rc (bool): If True ignore error rc from the shell and return out.
81
+
82
+ Returns:
83
+ str: Command output.
84
+
85
+ Raises:
86
+ ExecOnPodError: If the command failed.
87
+ """
88
+ error_channel = {}
89
+ stream_closed_error = "stream resp is closed"
90
+ self.logger.info(f"Execute {command} on {self.name} ({self.node.name})")
91
+ resp = kubernetes.stream.stream(
92
+ api_method=self._kube_v1_api.connect_get_namespaced_pod_exec,
93
+ name=self.name,
94
+ namespace=self.namespace,
95
+ command=command,
96
+ container=container or self.containers[0].name,
97
+ stderr=True,
98
+ stdin=False,
99
+ stdout=True,
100
+ tty=False,
101
+ _preload_content=False,
102
+ )
103
+
104
+ timeout_watch = TimeoutWatch(timeout=timeout)
105
+ while resp.is_open():
106
+ resp.run_forever(timeout=2)
107
+ try:
108
+ error_channel = json.loads(
109
+ resp.read_channel(kubernetes.stream.ws_client.ERROR_CHANNEL)
110
+ )
111
+ break
112
+ except json.decoder.JSONDecodeError:
113
+ # Check remaining time, in order to throw exception
114
+ # if remaining time reached zero
115
+ if timeout_watch.remaining_time() <= 0:
116
+ raise ExecOnPodError(
117
+ command=command, rc=-1, out="", err=stream_closed_error
118
+ )
119
+
120
+ rcstring = error_channel.get("status")
121
+ if rcstring is None:
122
+ raise ExecOnPodError(
123
+ command=command, rc=-1, out="", err=stream_closed_error
124
+ )
125
+
126
+ stdout = resp.read_stdout(timeout=5)
127
+ stderr = resp.read_stderr(timeout=5)
128
+
129
+ if rcstring == "Success" or ignore_rc:
130
+ return stdout
131
+
132
+ if rcstring == "Failure":
133
+ raise ExecOnPodError(command=command, rc=-1, out="", err=error_channel)
134
+
135
+ returncode = [
136
+ int(cause["message"])
137
+ for cause in error_channel["details"]["causes"]
138
+ if cause["reason"] == "ExitCode"
139
+ ][0]
140
+
141
+ raise ExecOnPodError(command=command, rc=returncode, out=stdout, err=stderr)
142
+
143
+ def log(self, **kwargs):
144
+ """
145
+ Get Pod logs
146
+
147
+ Returns:
148
+ str: Pod logs.
149
+ """
150
+ return self._kube_v1_api.read_namespaced_pod_log(
151
+ name=self.name, namespace=self.namespace, **kwargs
152
+ )
153
+
154
+ @property
155
+ def node(self):
156
+ """
157
+ Get the node name where the Pod is running
158
+
159
+ Returns:
160
+ Node: Node
161
+ """
162
+ node_name = self.instance.spec.nodeName
163
+ assert node_name, f"Node not found for pod {self.name}"
164
+ return Node(
165
+ client=self.privileged_client or self.client,
166
+ name=node_name,
167
+ )
168
+
169
+ @property
170
+ def ip(self):
171
+ return self.instance.status.podIP
172
+
173
+ @property
174
+ def _kube_v1_api(self):
175
+ return kube_v1_api(api_client=self.client.client)
@@ -0,0 +1,53 @@
1
+ from ocp_resources.constants import TIMEOUT_4MINUTES
2
+ from ocp_resources.resource import NamespacedResource
3
+
4
+
5
+ class PodDisruptionBudget(NamespacedResource):
6
+ """
7
+ PodDisruptionBudget object
8
+ """
9
+
10
+ api_group = NamespacedResource.ApiGroup.POLICY
11
+
12
+ def __init__(
13
+ self,
14
+ name=None,
15
+ namespace=None,
16
+ client=None,
17
+ min_available=None,
18
+ max_unavailable=None,
19
+ selector=None,
20
+ teardown=True,
21
+ yaml_file=None,
22
+ delete_timeout=TIMEOUT_4MINUTES,
23
+ **kwargs,
24
+ ):
25
+ super().__init__(
26
+ name=name,
27
+ namespace=namespace,
28
+ client=client,
29
+ teardown=teardown,
30
+ yaml_file=yaml_file,
31
+ delete_timeout=delete_timeout,
32
+ **kwargs,
33
+ )
34
+ self.min_available = min_available
35
+ self.max_unavailable = max_unavailable
36
+ self.selector = selector
37
+
38
+ def to_dict(self):
39
+ super().to_dict()
40
+ if not self.yaml_file:
41
+ update_dict = {
42
+ "spec": {
43
+ "selector": self.selector,
44
+ },
45
+ }
46
+
47
+ if self.min_available is not None:
48
+ update_dict["spec"]["minAvailable"] = self.min_available
49
+
50
+ if self.max_unavailable is not None:
51
+ update_dict["spec"]["maxUnavailable"] = self.max_unavailable
52
+
53
+ self.res.update(update_dict)
@@ -0,0 +1,48 @@
1
+ from ocp_resources.constants import TIMEOUT_4MINUTES
2
+ from ocp_resources.resource import Resource
3
+
4
+
5
+ class PriorityClass(Resource):
6
+ """
7
+ Priority Class object.
8
+ """
9
+
10
+ api_group = Resource.ApiGroup.SCHEDULING_K8S_IO
11
+
12
+ def __init__(
13
+ self,
14
+ name=None,
15
+ client=None,
16
+ teardown=True,
17
+ value=None,
18
+ global_default=False,
19
+ description=None,
20
+ preemption_policy=None,
21
+ yaml_file=None,
22
+ delete_timeout=TIMEOUT_4MINUTES,
23
+ **kwargs,
24
+ ):
25
+ super().__init__(
26
+ name=name,
27
+ client=client,
28
+ teardown=teardown,
29
+ yaml_file=yaml_file,
30
+ delete_timeout=delete_timeout,
31
+ **kwargs,
32
+ )
33
+ self.value = value
34
+ self.global_default = global_default
35
+ self.description = description
36
+ self.preemption_policy = preemption_policy
37
+
38
+ def to_dict(self):
39
+ super().to_dict()
40
+ if not self.yaml_file:
41
+ if self.value:
42
+ self.res["value"] = self.value
43
+ if self.global_default:
44
+ self.res["globalDefault"] = self.global_default
45
+ if self.description:
46
+ self.res["description"] = self.description
47
+ if self.preemption_policy:
48
+ self.res["preemptionPolicy"] = self.preemption_policy
@@ -0,0 +1,60 @@
1
+ from ocp_resources.constants import TIMEOUT_4MINUTES
2
+ from ocp_resources.resource import Resource
3
+
4
+
5
+ class Project(Resource):
6
+ """
7
+ Project object.
8
+ This is openshift's object which represents Namespace
9
+ """
10
+
11
+ api_group = Resource.ApiGroup.PROJECT_OPENSHIFT_IO
12
+
13
+ class Status(Resource.Status):
14
+ ACTIVE = "Active"
15
+
16
+ def clean_up(self):
17
+ Project(name=self.name).delete(wait=True)
18
+
19
+
20
+ class ProjectRequest(Resource):
21
+ """
22
+ RequestProject object.
23
+ Resource which adds Project and grand
24
+ full access to user who originated this request
25
+ """
26
+
27
+ api_group = Resource.ApiGroup.PROJECT_OPENSHIFT_IO
28
+
29
+ def __init__(
30
+ self,
31
+ name=None,
32
+ client=None,
33
+ teardown=True,
34
+ timeout=TIMEOUT_4MINUTES,
35
+ yaml_file=None,
36
+ delete_timeout=TIMEOUT_4MINUTES,
37
+ **kwargs,
38
+ ):
39
+ super().__init__(
40
+ name=name,
41
+ client=client,
42
+ teardown=teardown,
43
+ timeout=timeout,
44
+ yaml_file=yaml_file,
45
+ delete_timeout=delete_timeout,
46
+ **kwargs,
47
+ )
48
+
49
+ def clean_up(self):
50
+ Project(name=self.name).delete(wait=True)
51
+
52
+ def client_wait_deleted(self, timeout):
53
+ """
54
+ client-side Wait until resource is deleted
55
+
56
+ Args:
57
+ timeout (int): Time to wait for the resource.
58
+
59
+ """
60
+ super().client_wait_deleted(timeout=timeout)
@@ -0,0 +1,9 @@
1
+ from ocp_resources.resource import NamespacedResource
2
+
3
+
4
+ class Prometheus(NamespacedResource):
5
+ """
6
+ Prometheus object.
7
+ """
8
+
9
+ api_group = NamespacedResource.ApiGroup.MONITORING_COREOS_COM
@@ -0,0 +1,9 @@
1
+ from ocp_resources.resource import NamespacedResource
2
+
3
+
4
+ class PrometheusRule(NamespacedResource):
5
+ """
6
+ Prometheus Rule object.
7
+ """
8
+
9
+ api_group = NamespacedResource.ApiGroup.MONITORING_COREOS_COM
@@ -0,0 +1,59 @@
1
+ from ocp_resources.constants import TIMEOUT_4MINUTES
2
+ from ocp_resources.mtv import MTV
3
+ from ocp_resources.resource import NamespacedResource
4
+
5
+
6
+ class Provider(NamespacedResource, MTV):
7
+ """
8
+ Migration Toolkit For Virtualization (MTV) Provider object.
9
+ """
10
+
11
+ api_group = NamespacedResource.ApiGroup.FORKLIFT_KONVEYOR_IO
12
+
13
+ def __init__(
14
+ self,
15
+ name=None,
16
+ namespace=None,
17
+ provider_type=None,
18
+ url=None,
19
+ secret_name=None,
20
+ secret_namespace=None,
21
+ vddk_init_image=None,
22
+ client=None,
23
+ teardown=True,
24
+ yaml_file=None,
25
+ delete_timeout=TIMEOUT_4MINUTES,
26
+ **kwargs,
27
+ ):
28
+ super().__init__(
29
+ name=name,
30
+ namespace=namespace,
31
+ client=client,
32
+ teardown=teardown,
33
+ yaml_file=yaml_file,
34
+ delete_timeout=delete_timeout,
35
+ **kwargs,
36
+ )
37
+ self.provider_type = provider_type
38
+ self.url = url
39
+ self.secret_name = secret_name
40
+ self.secret_namespace = secret_namespace
41
+ self.condition_message_ready = self.ConditionMessage.PROVIDER_READY
42
+ self.vddk_init_image = vddk_init_image
43
+
44
+ def to_dict(self):
45
+ super().to_dict()
46
+ if not self.yaml_file:
47
+ self.res.update(
48
+ {
49
+ "spec": {
50
+ "type": self.provider_type,
51
+ "url": self.url,
52
+ "secret": {
53
+ "name": self.secret_name,
54
+ "namespace": self.secret_namespace,
55
+ },
56
+ "settings": {"vddkInitImage": self.vddk_init_image},
57
+ }
58
+ }
59
+ )
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ocp_resources.resource import NamespacedResource
4
+
5
+
6
+ class ReplicaSet(NamespacedResource):
7
+ """
8
+ OpenShift Service object.
9
+ """
10
+
11
+ api_group = NamespacedResource.ApiGroup.APPS