Skip to content

Commit

Permalink
Add watch notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
djkonro committed Jul 5, 2017
1 parent 5e268fb commit 36cb2da
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions examples/notebooks/watch_notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"from kubernetes import client, config, watch"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"config.load_kube_config()\n",
"v1 = client.CoreV1Api()\n",
"v1ext = client.ExtensionsV1beta1Api()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"def pods():\n",
" count = len(v1.list_pod_for_all_namespaces().items)\n",
" w = watch.Watch()\n",
" for event in w.stream(v1.list_pod_for_all_namespaces):\n",
" print(\"Event: %s %s %s\" % (event['type'],event['object'].kind, event['object'].metadata.name))\n",
" count -= 1\n",
" if not count:\n",
" w.stop()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"def deployments():\n",
" count = len(v1ext.list_deployment_for_all_namespaces().items)\n",
" w = watch.Watch()\n",
" for event in w.stream(v1ext.list_deployment_for_all_namespaces):\n",
" print(\"Event: %s %s %s\" % (event['type'],event['object'].kind, event['object'].metadata.name))\n",
" count -= 1\n",
" if not count:\n",
" w.stop()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"pods()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"deployments()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 36cb2da

Please sign in to comment.