7
7
API_KEY = os .getenv ("RUNPOD_API_KEY" )
8
8
9
9
URL = f"https://api.runpod.io/graphql?api_key={ API_KEY } "
10
- print (URL )
11
10
HEADERS = {
12
11
'Content-Type' : 'application/json' ,
13
12
}
@@ -23,12 +22,10 @@ def get_all_running_pods():
23
22
json = {'query' : query },
24
23
headers = HEADERS
25
24
)
26
- print (response .json ())
25
+ # print(response.json())
27
26
if response .status_code == 200 :
28
27
pods = response .json ()['data' ]['myself' ]['pods' ]
29
28
for pod in pods :
30
- if 'manav' not in pod ['name' ]:
31
- continue
32
29
ip = None
33
30
port = None
34
31
try :
@@ -38,7 +35,7 @@ def get_all_running_pods():
38
35
ip = p ['ip' ]
39
36
port = p ['publicPort' ]
40
37
break
41
- yield (pod ['id ' ], (ip , port ))
38
+ yield (pod ['name ' ], (ip , port , pod [ "id" ] ))
42
39
except TypeError :
43
40
pass
44
41
else :
@@ -47,22 +44,23 @@ def get_all_running_pods():
47
44
48
45
# Fetch and print all running pods with their IP address and port
49
46
pods = dict (get_all_running_pods ())
47
+ pods = dict (sorted (pods .items (), key = lambda x : x [0 ]))
50
48
51
49
config = """Host %s
52
50
HostName %s
53
51
Port %s
54
52
User root
55
53
IdentitiesOnly yes
56
- IdentityFile /Users/manav/.ssh/run_pod
54
+ IdentityFile /Users/manav/.ssh/runpod
57
55
ForwardX11 yes
58
56
"""
59
57
60
58
configs = []
61
59
i = 1
62
- for pod , (ip , port ) in pods .items ():
60
+ for pod , (ip , port , id ) in pods .items ():
63
61
if ip is not None :
64
- print (f"{ pod } - pod{ i } - { ip } :{ port } " )
65
- configs .append (config % (f"pod { i } " , ip , port ))
62
+ print (f"{ pod } - pod{ i } - { id } - { ip } :{ port } " )
63
+ configs .append (config % (f"{ pod } " , ip , port ))
66
64
i += 1
67
65
68
66
with open ('/Users/manav/.ssh/config' , 'w' ) as f :
0 commit comments