Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit fbf5f18

Browse files
committed
added manage pod files
1 parent ecf3b9d commit fbf5f18

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

init-runpod.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import runpod
2+
3+
runpod.api_key = '1WD030TPD0WW71AKO7SMAB0Q2WIQSYWWUK9T2JVI'
4+
5+
instances = runpod.get_pods()
6+
7+
running_instances = [instance for instance in instances if instance['name'].startswith('runpod-cuda-12.6')]
8+
print(running_instances)
9+
idx = len(running_instances)
10+
11+
print(runpod.get_gpus())
12+
13+
# Create a new instance
14+
instance = runpod.create_pod(
15+
name=f'manav-{idx}',
16+
image_name='runpod-cuda-12.6',
17+
gpu_type_id='NVIDIA A40',
18+
# data_center_id='EU-SE-1',
19+
# template_id='oqfjo3fqxu',
20+
# network_volume_id='w668p2cosp',
21+
# min_memory_in_gb=16,
22+
)
23+
24+
# Print the instance details
25+
print(instance)

pod-info.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import time
2+
import requests
3+
import json
4+
import os
5+
6+
# Set your API key and Pod ID
7+
API_KEY = "1WD030TPD0WW71AKO7SMAB0Q2WIQSYWWUK9T2JVI"
8+
POD_ID = "bs8jyvfzklc0tk"
9+
10+
URL = f"https://api.runpod.io/graphql?api_key={API_KEY}"
11+
print(URL)
12+
HEADERS = {
13+
'Content-Type': 'application/json',
14+
}
15+
16+
# GraphQL query to get all running pods with their IP address and port
17+
def get_all_running_pods():
18+
query = '''
19+
query Pods { myself { pods { id name runtime { uptimeInSeconds ports { ip isIpPublic privatePort publicPort type } gpus { id gpuUtilPercent memoryUtilPercent } container { cpuPercent memoryPercent } } } } }
20+
'''
21+
22+
response = requests.post(
23+
URL,
24+
json={'query': query},
25+
headers=HEADERS
26+
)
27+
print(response.json())
28+
if response.status_code == 200:
29+
pods = response.json()['data']['myself']['pods']
30+
for pod in pods:
31+
if 'manav' not in pod['name']:
32+
continue
33+
ip = None
34+
port = None
35+
try:
36+
ports = pod['runtime']['ports']
37+
for p in ports:
38+
if p['isIpPublic']:
39+
ip = p['ip']
40+
port = p['publicPort']
41+
break
42+
yield (pod['id'], (ip, port))
43+
except TypeError:
44+
pass
45+
else:
46+
print(f"Failed to get running pods: {response.status_code}")
47+
48+
49+
# Fetch and print all running pods with their IP address and port
50+
pods = dict(get_all_running_pods())
51+
52+
config = """Host %s
53+
HostName %s
54+
Port %s
55+
User root
56+
IdentitiesOnly yes
57+
IdentityFile /Users/manav/.ssh/run_pod
58+
ForwardX11 yes
59+
"""
60+
61+
configs = []
62+
i = 1
63+
for pod, (ip, port) in pods.items():
64+
if ip is not None:
65+
print(f"{pod} - pod{i} - {ip}:{port}")
66+
configs.append(config % (f"pod{i}", ip, port))
67+
i += 1
68+
69+
with open('/Users/manav/.ssh/config', 'w') as f:
70+
f.write('\n'.join(configs))
71+

0 commit comments

Comments
 (0)