From 7c19259cd852f278748b81d1d0d868fdd7e97c00 Mon Sep 17 00:00:00 2001 From: Meni Yakove Date: Wed, 26 Jul 2023 17:56:29 +0300 Subject: [PATCH] Remove openshift python module dependencies, use kubernetes --- README.md | 2 +- ocp_resources/constants.py | 4 +-- ocp_resources/data_source.py | 2 +- .../node_network_configuration_policy.py | 2 +- ocp_resources/node_network_state.py | 2 +- ocp_resources/resource.py | 16 ++++++---- ocp_resources/virtual_machine_instance.py | 2 +- ocp_resources/virtual_machine_restore.py | 2 +- ocp_resources/virtual_machine_snapshot.py | 2 +- poetry.lock | 29 +------------------ pyproject.toml | 3 +- 11 files changed, 21 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 5ff08bd54d..a56716eac2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # openshift-python-wrapper Pypi: [openshift-python-wrapper](https://pypi.org/project/openshift-python-wrapper) -A python wrapper for [openshift-restclient-python](https://github.com/openshift/openshift-restclient-python) with support for RedHat Container Virtualization. ([Openshift Virtualization](https://www.openshift.com/learn/topics/virtualization)) +A python wrapper for [kubernetes-python-client](https://github.com/kubernetes-client/python) with support for RedHat Container Virtualization. ([Openshift Virtualization](https://www.openshift.com/learn/topics/virtualization)) Docs: [openshift-python-wrapper docs](https://openshift-python-wrapper.readthedocs.io/en/latest/) ## Installation diff --git a/ocp_resources/constants.py b/ocp_resources/constants.py index 0d4027e289..b08c8d07a1 100644 --- a/ocp_resources/constants.py +++ b/ocp_resources/constants.py @@ -1,5 +1,5 @@ -from kubernetes.dynamic.exceptions import ForbiddenError -from openshift.dynamic.exceptions import ( +from kubernetes.dynamic.exceptions import ( + ForbiddenError, InternalServerError, NotFoundError, ServerTimeoutError, diff --git a/ocp_resources/data_source.py b/ocp_resources/data_source.py index 6c40f77842..6f45a686b7 100644 --- a/ocp_resources/data_source.py +++ b/ocp_resources/data_source.py @@ -1,4 +1,4 @@ -from openshift.dynamic.exceptions import ResourceNotFoundError +from kubernetes.dynamic.exceptions import ResourceNotFoundError from ocp_resources.constants import TIMEOUT_4MINUTES from ocp_resources.persistent_volume_claim import PersistentVolumeClaim diff --git a/ocp_resources/node_network_configuration_policy.py b/ocp_resources/node_network_configuration_policy.py index 4f9d9a1ef5..7f20d75ffa 100644 --- a/ocp_resources/node_network_configuration_policy.py +++ b/ocp_resources/node_network_configuration_policy.py @@ -1,6 +1,6 @@ import re -from openshift.dynamic.exceptions import ConflictError +from kubernetes.dynamic.exceptions import ConflictError from ocp_resources.constants import TIMEOUT_4MINUTES from ocp_resources.node import Node diff --git a/ocp_resources/node_network_state.py b/ocp_resources/node_network_state.py index dd48a55f7b..d7c5bf14ee 100644 --- a/ocp_resources/node_network_state.py +++ b/ocp_resources/node_network_state.py @@ -1,6 +1,6 @@ import time -from openshift.dynamic.exceptions import ConflictError +from kubernetes.dynamic.exceptions import ConflictError from ocp_resources.constants import TIMEOUT_4MINUTES from ocp_resources.resource import Resource diff --git a/ocp_resources/resource.py b/ocp_resources/resource.py index c02a8ddc57..9d1517affb 100644 --- a/ocp_resources/resource.py +++ b/ocp_resources/resource.py @@ -10,10 +10,14 @@ import kubernetes import yaml from benedict import benedict -from kubernetes.dynamic.exceptions import ForbiddenError, MethodNotAllowedError -from openshift.dynamic import DynamicClient -from openshift.dynamic.exceptions import ConflictError, NotFoundError -from openshift.dynamic.resource import ResourceField +from kubernetes.dynamic import DynamicClient +from kubernetes.dynamic.exceptions import ( + ConflictError, + ForbiddenError, + MethodNotAllowedError, + NotFoundError, +) +from kubernetes.dynamic.resource import ResourceField from packaging.version import Version from simple_logger.logger import get_logger @@ -1106,8 +1110,8 @@ def get( dyn_client (DynamicClient): Open connection to remote cluster config_file (str): Path to config file for connecting to remote cluster. context (str): Context name for connecting to remote cluster. - singular_name (str): Resource kind (in lowercase), in use where we have multiple matches for resource - raw (bool): If True return raw object from openshift-restclient-python + singular_name (str): Resource kind (in lowercase), in use where we have multiple matches for resource. + raw (bool): If True return raw object. Returns: diff --git a/ocp_resources/virtual_machine_instance.py b/ocp_resources/virtual_machine_instance.py index 047543c17b..3fdd4f7359 100644 --- a/ocp_resources/virtual_machine_instance.py +++ b/ocp_resources/virtual_machine_instance.py @@ -1,7 +1,7 @@ import shlex import xmltodict -from openshift.dynamic.exceptions import ResourceNotFoundError +from kubernetes.dynamic.exceptions import ResourceNotFoundError from ocp_resources.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES from ocp_resources.node import Node diff --git a/ocp_resources/virtual_machine_restore.py b/ocp_resources/virtual_machine_restore.py index 213c263a56..b8c378170e 100644 --- a/ocp_resources/virtual_machine_restore.py +++ b/ocp_resources/virtual_machine_restore.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from openshift.dynamic.exceptions import ResourceNotFoundError +from kubernetes.dynamic.exceptions import ResourceNotFoundError from ocp_resources.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES from ocp_resources.resource import NamespacedResource diff --git a/ocp_resources/virtual_machine_snapshot.py b/ocp_resources/virtual_machine_snapshot.py index c3dc7929ef..aaa2157666 100644 --- a/ocp_resources/virtual_machine_snapshot.py +++ b/ocp_resources/virtual_machine_snapshot.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from openshift.dynamic.exceptions import ResourceNotFoundError +from kubernetes.dynamic.exceptions import ResourceNotFoundError from ocp_resources.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES from ocp_resources.resource import NamespacedResource diff --git a/poetry.lock b/poetry.lock index a854e62d3f..c89a1dd2c4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1019,22 +1019,6 @@ rsa = ["cryptography (>=3.0.0)"] signals = ["blinker (>=1.4.0)"] signedtoken = ["cryptography (>=3.0.0)", "pyjwt (>=2.0.0,<3)"] -[[package]] -name = "openshift" -version = "0.13.2" -description = "OpenShift python client" -optional = false -python-versions = "*" -files = [ - {file = "openshift-0.13.2-py3-none-any.whl", hash = "sha256:f1459006fc7f96ff7d2f6c0c00bdef5cb2e75a1b466f601997d9084a816a8949"}, - {file = "openshift-0.13.2.tar.gz", hash = "sha256:f55789fce56fcbf7e2cd9377a68c4a99ab406074d3324b9abcca98477d101471"}, -] - -[package.dependencies] -kubernetes = ">=12.0" -python-string-utils = "*" -six = "*" - [[package]] name = "packaging" version = "23.1" @@ -1399,17 +1383,6 @@ text-unidecode = ">=1.3" [package.extras] unidecode = ["Unidecode (>=1.1.1)"] -[[package]] -name = "python-string-utils" -version = "1.0.0" -description = "Utility functions for strings validation and manipulation." -optional = false -python-versions = ">=3.5" -files = [ - {file = "python-string-utils-1.0.0.tar.gz", hash = "sha256:dcf9060b03f07647c0a603408dc8b03f807f3b54a05c6e19eb14460256fac0cb"}, - {file = "python_string_utils-1.0.0-py3-none-any.whl", hash = "sha256:f1a88700baf99db1a9b6953f44181ad9ca56623c81e257e6009707e2e7851fa4"}, -] - [[package]] name = "pywin32-ctypes" version = "0.2.2" @@ -2075,4 +2048,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "295eb7a1327ce130f120706df284b17d600c5f14a26246eee5e7fbc591686788" +content-hash = "1d8fb7ba26ac8a154dc34eae82defc562c7057b99d3027cc58850020a1614ca0" diff --git a/pyproject.toml b/pyproject.toml index 52f684f0e3..8cbe99f61d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ profile = "black" [tool.poetry] name = "openshift-python-wrapper" version = "0.0.0" -description = "Wrapper around https://github.com/openshift/openshift-restclient-python" +description = "Wrapper around https://github.com/kubernetes-client/python" authors = ["Meni Yakove ", "Ruth Netser "] readme = "README.md" license = "Apache-2.0" @@ -52,7 +52,6 @@ build-backend = "poetry_dynamic_versioning.backend" [tool.poetry.dependencies] python = "^3.8" -openshift = "^0.13.2" xmltodict = "^0.13.0" colorlog = "^6.7.0" kubernetes = "^27.2.0"