Skip to content

Commit 327e4e7

Browse files
jinsoojinsoo
authored andcommitted
add: runpod cli script
1 parent 7883aa4 commit 327e4e7

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os
2+
import requests
3+
4+
RUNPOD_TOKEN = os.environ["RUNPOD_API_KEY"] # 환경변수로 넣는 걸 추천
5+
URL = "https://rest.runpod.io/v1/pods"
6+
7+
headers = {
8+
"Authorization": f"Bearer {RUNPOD_TOKEN}",
9+
"Content-Type": "application/json",
10+
}
11+
12+
payload = {
13+
"allowedCudaVersions": ["13.0"],
14+
"cloudType": "SECURE",
15+
"computeType": "GPU",
16+
"containerDiskInGb": 50,
17+
"containerRegistryAuthId": "",
18+
# "countryCodes": ["KR"], # 예: 필요하면 실제 값으로
19+
# "cpuFlavorIds": ["cpu3c"], # GPU면 보통 불필요/자동인 경우도 있음 (스펙 확인)
20+
"cpuFlavorPriority": "availability",
21+
"dataCenterIds": [
22+
"EU-RO-1","CA-MTL-1","EU-SE-1","US-IL-1","EUR-IS-1","EU-CZ-1","US-TX-3","EUR-IS-2",
23+
"US-KS-2","US-GA-2","US-WA-1","US-TX-1","CA-MTL-3","EU-NL-1","US-TX-4","US-CA-2",
24+
"US-NC-1","OC-AU-1","US-DE-1","EUR-IS-3","CA-MTL-2","AP-JP-1","EUR-NO-1","EU-FR-1",
25+
"US-KS-3","US-GA-1"
26+
],
27+
"dataCenterPriority": "availability",
28+
"dockerEntrypoint": [],
29+
"dockerStartCmd": [],
30+
"env": {"ENV_VAR": "value"},
31+
"globalNetworking": False,
32+
"gpuCount": 1,
33+
"gpuTypeIds": ["NVIDIA GeForce RTX 4090"],
34+
"gpuTypePriority": "availability",
35+
"imageName": "jinsoo1218/vllm-pod:latest",
36+
"interruptible": False,
37+
"locked": False,
38+
"minDiskBandwidthMBps": 123,
39+
"minDownloadMbps": 123,
40+
"minRAMPerGPU": 8,
41+
"minUploadMbps": 123,
42+
"minVCPUPerGPU": 2,
43+
"name": "vllm-pod",
44+
"networkVolumeId": "2kn4qj6rql", # <-- 여기 실제 ID로
45+
"ports": ["8888/http", "22/tcp"],
46+
"supportPublicIp": True,
47+
"vcpuCount": 2,
48+
"volumeInGb": 20,
49+
"volumeMountPath": "/workspace",
50+
}
51+
52+
resp = requests.post(URL, headers=headers, json=payload, timeout=60)
53+
print("status:", resp.status_code)
54+
55+
# 에러면 원인 보기 좋게
56+
try:
57+
data = resp.json()
58+
except Exception:
59+
print(resp.text)
60+
raise
61+
62+
print(data)
63+
64+
# 실패 시 예외
65+
resp.raise_for_status()
File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import requests
3+
4+
class RunPodClient:
5+
def __init__(self, token: str):
6+
self.base_url = "https://rest.runpod.io/v1"
7+
self.headers = {
8+
"Authorization": f"Bearer {token}",
9+
"Content-Type": "application/json",
10+
}
11+
12+
def delete_pod(self, pod_id: str):
13+
url = f"{self.base_url}/pods/{pod_id}"
14+
resp = requests.delete(url, headers=self.headers, timeout=30)
15+
16+
if resp.status_code == 404:
17+
return {"status": "already_deleted"}
18+
19+
resp.raise_for_status()
20+
21+
if resp.text.strip():
22+
return resp.json()
23+
return {"status": "deleted"}
24+
25+
26+
if __name__ == "__main__":
27+
token = os.environ["RUNPOD_API_KEY"] # 하나로 통일
28+
client = RunPodClient(token)
29+
print(client.delete_pod("0hs9up7f8mdl41"))

0 commit comments

Comments
 (0)