From 26ac2c4a12cb69daa81cc5fab321e190217f5040 Mon Sep 17 00:00:00 2001 From: mbohlool Date: Tue, 22 Nov 2016 17:52:46 -0800 Subject: [PATCH] Separate package util into config and watch package --- README.md | 14 +++++++------- examples/example1.py | 4 ++-- examples/example2.py | 10 +++++----- examples/example3.py | 4 ++-- kubernetes/__init__.py | 3 ++- kubernetes/{util => config}/__init__.py | 1 - kubernetes/{util => config}/kube_config.py | 0 kubernetes/watch/__init__.py | 15 +++++++++++++++ kubernetes/{util => watch}/watch.py | 4 ++-- kubernetes/{util => watch}/watch_test.py | 0 setup.py | 5 +++-- 11 files changed, 38 insertions(+), 22 deletions(-) rename kubernetes/{util => config}/__init__.py (96%) rename kubernetes/{util => config}/kube_config.py (100%) create mode 100644 kubernetes/watch/__init__.py rename kubernetes/{util => watch}/watch.py (97%) rename kubernetes/{util => watch}/watch_test.py (100%) diff --git a/README.md b/README.md index dc35d36b1..6d9abcac2 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,10 @@ list all pods: ```python import os -from kubernetes import client, util +from kubernetes import client, config # Configs can be set in Configuration class directly or using helper utility -util.load_kube_config(os.environ["HOME"] + '/.kube/config') +config.load_kube_config(os.environ["HOME"] + '/.kube/config') v1=client.CoreV1Api() print("Listing pods with their IPs:") @@ -28,19 +28,19 @@ watch on namespace object: ```python import os -from kubernetes import client, util +from kubernetes import client, config, watch # Configs can be set in Configuration class directly or using helper utility -util.load_kube_config(os.environ["HOME"] + '/.kube/config') +config.load_kube_config(os.environ["HOME"] + '/.kube/config') v1 = client.CoreV1Api() count = 10 -watch = util.Watch() -for event in watch.stream(v1.list_namespace, _request_timeout=60): +w = watch.Watch() +for event in w.stream(v1.list_namespace, _request_timeout=60): print("Event: %s %s" % (event['type'], event['object'].metadata.name)) count -= 1 if not count: - watch.stop() + w.stop() print("Ended.") ``` diff --git a/examples/example1.py b/examples/example1.py index 9dfd0f287..0aeed2016 100644 --- a/examples/example1.py +++ b/examples/example1.py @@ -14,13 +14,13 @@ import os -from kubernetes import client, util +from kubernetes import client, config def main(): # Configs can be set in Configuration class directly or using helper # utility - util.load_kube_config(os.environ["HOME"] + '/.kube/config') + config.load_kube_config(os.environ["HOME"] + '/.kube/config') v1 = client.CoreV1Api() print("Listing pods with their IPs:") diff --git a/examples/example2.py b/examples/example2.py index be0f29676..f594407d8 100644 --- a/examples/example2.py +++ b/examples/example2.py @@ -14,22 +14,22 @@ import os -from kubernetes import client, util +from kubernetes import client, config, watch def main(): # Configs can be set in Configuration class directly or using helper # utility - util.load_kube_config(os.environ["HOME"] + '/.kube/config') + config.load_kube_config(os.environ["HOME"] + '/.kube/config') v1 = client.CoreV1Api() count = 10 - watch = util.Watch() - for event in watch.stream(v1.list_namespace, timeout_seconds=10): + w = watch.Watch() + for event in w.stream(v1.list_namespace, timeout_seconds=10): print("Event: %s %s" % (event['type'], event['object'].metadata.name)) count -= 1 if not count: - watch.stop() + w.stop() print("Ended.") diff --git a/examples/example3.py b/examples/example3.py index 1f637f2c8..25aab6962 100644 --- a/examples/example3.py +++ b/examples/example3.py @@ -14,13 +14,13 @@ import os -from kubernetes import client, util +from kubernetes import client, config def main(): # Configs can be set in Configuration class directly or using helper # utility - util.load_kube_config(os.environ["HOME"] + '/.kube/config') + config.load_kube_config(os.environ["HOME"] + '/.kube/config') print("Supported APIs (* is preferred version):") print("%-20s %s" % diff --git a/kubernetes/__init__.py b/kubernetes/__init__.py index 0706c9f7c..0b613223f 100644 --- a/kubernetes/__init__.py +++ b/kubernetes/__init__.py @@ -13,4 +13,5 @@ # limitations under the License. import kubernetes.client -import kubernetes.util +import kubernetes.config +import kubernetes.watch diff --git a/kubernetes/util/__init__.py b/kubernetes/config/__init__.py similarity index 96% rename from kubernetes/util/__init__.py rename to kubernetes/config/__init__.py index 02f19b0e8..bceafecbf 100644 --- a/kubernetes/util/__init__.py +++ b/kubernetes/config/__init__.py @@ -13,4 +13,3 @@ # limitations under the License. from .kube_config import load_kube_config -from .watch import Watch diff --git a/kubernetes/util/kube_config.py b/kubernetes/config/kube_config.py similarity index 100% rename from kubernetes/util/kube_config.py rename to kubernetes/config/kube_config.py diff --git a/kubernetes/watch/__init__.py b/kubernetes/watch/__init__.py new file mode 100644 index 000000000..ca9ac0698 --- /dev/null +++ b/kubernetes/watch/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .watch import Watch diff --git a/kubernetes/util/watch.py b/kubernetes/watch/watch.py similarity index 97% rename from kubernetes/util/watch.py rename to kubernetes/watch/watch.py index 9b4080bfe..9dd7af79e 100644 --- a/kubernetes/util/watch.py +++ b/kubernetes/watch/watch.py @@ -98,8 +98,8 @@ class Watch(object): 'object' value will be the same as 'raw_object'. Example: - v1 = client.CoreV1Api() - watch = util.Watch() + v1 = kubernetes.client.CoreV1Api() + watch = kubernetes.watch.Watch() for e in watch.stream(v1.list_namespace, resource_version=1127): type = e['type'] object = e['object'] # object is one of type return_type diff --git a/kubernetes/util/watch_test.py b/kubernetes/watch/watch_test.py similarity index 100% rename from kubernetes/util/watch_test.py rename to kubernetes/watch/watch_test.py diff --git a/setup.py b/setup.py index 74783ddd6..bfaceed3f 100644 --- a/setup.py +++ b/setup.py @@ -45,8 +45,9 @@ setup( url="http://kubernetes.io", keywords=["Swagger", "OpenAPI", "Kubernetes"], install_requires=REQUIRES, - packages=['kubernetes', 'kubernetes.client', 'kubernetes.util', - 'kubernetes.client.apis', 'kubernetes.client.models'], + packages=['kubernetes', 'kubernetes.client', 'kubernetes.config', + 'kubernetes.watch', 'kubernetes.client.apis', + 'kubernetes.client.models'], include_package_data=True, long_description="""\ Python client for talk to a kubernetes cluster.