Skip to content

Instantly share code, notes, and snippets.

@kadel
Created January 8, 2016 17:25
Show Gist options
  • Save kadel/6322bf8a1ba8e7f3bb73 to your computer and use it in GitHub Desktop.
Save kadel/6322bf8a1ba8e7f3bb73 to your computer and use it in GitHub Desktop.
Kubernets: exec using API
# https://pypi.python.org/pypi/websocket-client/
import websocket
import ssl
def on_message(ws, message):
print message
args = {"token": "",
"namespace": "testing",
"pod": "nonroot-nginx-1-pftqg",
"container": "nonroot-nginx",
"command": "ls"}
url = "wss://console.engint.openshift.com:443/api/v1/namespaces/{namespace}/pods/{pod}/exec?access_token={token}&container={container}&command={command}&stdout=1&stderr=1&stdin=1&tty=1".format(**args)
ws = websocket.WebSocketApp(url, on_message=on_message)
# sslopt disables ssl/tls verification
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment