Skip to content

Commit

Permalink
Adding examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mbohlool committed Nov 4, 2016
1 parent 8015623 commit e73968e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 27 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_core_v1_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)
```

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.
32 changes: 32 additions & 0 deletions examples/example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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_core_v1_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)
23 changes: 0 additions & 23 deletions scripts/ROOT_README.md

This file was deleted.

6 changes: 3 additions & 3 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ echo "--- Cleaning up previously generated folders"
rm -rf "${CLIENT_ROOT}/${PACKAGE_NAME}"
rm -rf "${CLIENT_ROOT}/docs"
rm -rf "${CLIENT_ROOT}/test"

mv "${CLIENT_ROOT}/README.md" "${CLIENT_ROOT}/ROOT_README.md"
echo "--- Generating client ..."
mvn -f "${SCRIPT_ROOT}/pom.xml" clean generate-sources -Dgenerator.spec.path="${SWAGGER_FILE}" -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"
echo "---Done."

0 comments on commit e73968e

Please sign in to comment.