Skip to content

Commit

Permalink
Adding examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mbohlool committed Nov 12, 2016
1 parent f5db00f commit 9094775
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 26 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,32 @@ Python clients for talking to a [kubernetes](http://kubernetes.io/) cluster.
```python
from __future__ import absolute_import

import k8sutil
import k8sclient
import os

# Configs can be set in Configuration class directly or using helper utility
k8sutil.load_kube_config(os.environ["HOME"] + '/.kube/config')

# Prior to python 3.4 hosts with ip-addresses cannot be verified for SSL. this
# utility function fixes that.
k8sutil.fix_ssl_hosts_with_ipaddress()

v1=k8sclient.CoreV1Api()
print "Listing pods with their IPs:"
ret = v1.list_pod_for_all_namespaces(watch=False)
ret = v1.list_pod_for_all_namespaces()
for i in ret.items:
print "%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name)
```

More examples can be found in [examples](examples/) folder. To run examples, run this command:

```shell
python -m examples.example1
```

(replace example1 with the example base filename)

# Generated client README

for generated client documentation, refer to [generated README](GEN_README.md).
Expand Down
15 changes: 15 additions & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -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.

# Empty init file to make examples folder a python module.
33 changes: 33 additions & 0 deletions examples/example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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 __future__ import absolute_import

import k8sutil
import k8sclient
import os

# Configs can be set in Configuration class directly or using helper utility
k8sutil.load_kube_config(os.environ["HOME"] + '/.kube/config')

# Prior to python 3.4 hosts with ip-addresses cannot be verified for SSL. this
# utility function fixes that.
k8sutil.fix_ssl_hosts_with_ipaddress()

v1=k8sclient.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))

42 changes: 42 additions & 0 deletions examples/example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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 __future__ import absolute_import

import k8sutil
import k8sclient
import os


def main():
# Configs can be set in Configuration class directly or using helper utility
k8sutil.load_kube_config(os.environ["HOME"] + '/.kube/config')

# Prior to python 3.4 hosts with ip-addresses cannot be verified for SSL. this
# utility function fixes that.
k8sutil.fix_ssl_hosts_with_ipaddress()

v1 = k8sclient.CoreV1Api()
count = 10
watch = k8sutil.Watch()
for event in watch.stream(v1.list_namespace, _request_timeout=60):
print("--------------\n%s:\n%s" % (event['type'], event['object']))
count -= 1
if not count:
watch.stop()

print("Ended.")


main()
23 changes: 0 additions & 23 deletions scripts/ROOT_README.md

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ echo "--- Generating client ..."
mvn -f "${SCRIPT_ROOT}/pom.xml" clean generate-sources -Dgenerator.spec.path="${SCRIPT_ROOT}/swagger.json" -Dgenerator.output.path="${CLIENT_ROOT}" -Dgenerator.package.name=${PACKAGE_NAME}

echo "--- Patching generated code..."
cp "${CLIENT_ROOT}/README.md" "${CLIENT_ROOT}/GEN_README.md"
cp "${SCRIPT_ROOT}/ROOT_README.md" "${CLIENT_ROOT}/README.md"
mv "${CLIENT_ROOT}/README.md" "${CLIENT_ROOT}/GEN_README.md"
mv "${CLIENT_ROOT}/ROOT_README.md" "${CLIENT_ROOT}/README.md"
cp "${SCRIPT_ROOT}/LICENSE" "${CLIENT_ROOT}"
rm -rf "${CLIENT_ROOT}/test"

Expand Down
1 change: 1 addition & 0 deletions scripts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<configuration>
<inputSpec>${generator.spec.path}</inputSpec>
<language>python</language>
<templateDirectory>/Users/mehdy/projects/swagger-codegen/modules/swagger-codegen/src/main/resources/python</templateDirectory>
<configOptions>
<packageName>${generator.package.name}</packageName>
<sortParamsByRequiredFlag>true</sortParamsByRequiredFlag>
Expand Down

0 comments on commit 9094775

Please sign in to comment.