@@ -30,23 +30,25 @@ def main():
30
30
return
31
31
contexts = [context ['name' ] for context in contexts ]
32
32
active_index = contexts .index (active_context ['name' ])
33
- option , _ = pick (contexts , title = "Pick the context to load" ,
34
- default_index = active_index )
35
- # Configs can be set in Configuration class directly or using helper
36
- # utility
37
- config .load_kube_config (context = option )
38
-
39
- print ("Active host is %s" % configuration .Configuration ().host )
40
-
41
- v1 = client .CoreV1Api ()
42
- print ("Listing pods with their IPs:" )
43
- ret = v1 .list_pod_for_all_namespaces (watch = False )
44
- for item in ret .items :
45
- print (
46
- "%s\t %s\t %s" %
47
- (item .status .pod_ip ,
48
- item .metadata .namespace ,
49
- item .metadata .name ))
33
+ cluster1 , first_index = pick (contexts , title = "Pick the first context" ,
34
+ default_index = active_index )
35
+ cluster2 , _ = pick (contexts , title = "Pick the second context" ,
36
+ default_index = first_index )
37
+
38
+ client1 = client .CoreV1Api (
39
+ api_client = config .new_client_from_config (context = cluster1 ))
40
+ client2 = client .CoreV1Api (
41
+ api_client = config .new_client_from_config (context = cluster2 ))
42
+
43
+ print ("\n List of pods on %s:" % cluster1 )
44
+ for i in client1 .list_pod_for_all_namespaces ().items :
45
+ print ("%s\t %s\t %s" %
46
+ (i .status .pod_ip , i .metadata .namespace , i .metadata .name ))
47
+
48
+ print ("\n \n List of pods on %s:" % cluster2 )
49
+ for i in client2 .list_pod_for_all_namespaces ().items :
50
+ print ("%s\t %s\t %s" %
51
+ (i .status .pod_ip , i .metadata .namespace , i .metadata .name ))
50
52
51
53
52
54
if __name__ == '__main__' :
0 commit comments