k8s-router.py: add initial script for accessing routers
This commit is contained in:
parent
1495d7c235
commit
163ec9f791
1 changed files with 50 additions and 0 deletions
50
k8s/k8s-router.py
Executable file
50
k8s/k8s-router.py
Executable file
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
# Connect to the router pod
|
||||
# On Alpine: nb3:~# apk add py3-kubernetes
|
||||
|
||||
|
||||
import sys
|
||||
import os
|
||||
from kubernetes import client, config
|
||||
|
||||
# ~/k8s contains the config files
|
||||
K8SCONFIGDIR=os.path.join(os.environ['HOME'], "k8s")
|
||||
|
||||
routermap = {
|
||||
"p5-r1": "server137",
|
||||
"p5-r2": "server138",
|
||||
"p6-r1": "server139",
|
||||
"p6-r2": "server140",
|
||||
"p10-r1": "server122",
|
||||
"p10-r2": "server123",
|
||||
"p15-r1": "server120",
|
||||
"p15-r2": "server121",
|
||||
}
|
||||
|
||||
|
||||
if not len(sys.argv) == 2:
|
||||
print(f"{sys.argv[0]} <pX-r1|r2>")
|
||||
sys.exit(1)
|
||||
|
||||
router=sys.argv[1]
|
||||
|
||||
|
||||
if not router in routermap:
|
||||
print(f"Router {router} not known")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
k8sconfig = os.path.join(K8SCONFIGDIR, f"{routermap[router]}.conf")
|
||||
|
||||
if not os.path.exists(k8sconfig):
|
||||
print(f"You need to have {k8sconfig} for accessing {router}")
|
||||
sys.exit(1)
|
||||
|
||||
config.load_kube_config(config_file=k8sconfig)
|
||||
|
||||
#app.kubernetes.io/instance=bird-router-server120
|
||||
|
||||
#POD=$(kubectl -n rook-ceph get pods \
|
||||
# -l app=rook-ceph-tools --output=jsonpath={.items..metadata.name})
|
||||
#
|
||||
#kubectl -n rook-ceph exec -ti $POD -- bash
|
Loading…
Reference in a new issue