-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_on_demand_pod.py
executable file
·50 lines (40 loc) · 1.39 KB
/
start_on_demand_pod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import argparse
import sys
import runpod
import time
def get_args():
parser = argparse.ArgumentParser(
description='Start an on-demand RunPod pod',
)
parser.add_argument(
'--pod_id', '-pod_id', '--pod', '-pod', '--p', '-p',
type=str,
required=True,
help='pod id (eg. dg31b9aqtupn2z)'
)
return parser.parse_args()
def start_pod(pod_id):
response = runpod.start_on_demand_pod(pod_id)
resp_json = response.json()
if response.status_code == 200:
if 'errors' in resp_json:
for error in resp_json['errors']:
if error['message'] == 'There are not enough free GPUs on the host machine to start this pod.':
print('No available GPU, sleeping for 10 seconds....')
time.sleep(10)
start_pod(pod_id)
else:
print(f"ERROR: {error['message']}")
else:
pod = resp_json['data']['podResume']
print(f"id: {pod['id']}")
print(f"status: {pod['desiredStatus']}")
print(f"image: {pod['imageName']}")
print(f"machine id: {pod['machineId']}")
print(f"host id: {pod['machine']['podHostId']}")
sys.exit()
if __name__ == '__main__':
runpod = runpod.API()
args = get_args()
start_pod(args.pod_id)