Skip to content

Commit edb4bd4

Browse files
Merge pull request #98 from alexeevit/feature/getPodQuery
Add get_pod() API method
2 parents 4118877 + ff55df1 commit edb4bd4

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ runpod.api_key = "your_runpod_api_key_found_under_settings"
134134
# Get all my pods
135135
pods = runpod.get_pods()
136136

137+
# Get a specific pod
138+
pod = runpod.get_pod(pod.id)
139+
137140
# Create a pod
138141
pod = runpod.create_pod("test", "runpod/stack", "NVIDIA GeForce RTX 3070")
139142

runpod/api_wrapper/ctl_commands.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ def get_pods() -> dict:
3838
cleaned_return = raw_return["data"]["myself"]["pods"]
3939
return cleaned_return
4040

41+
def get_pod(pod_id : str):
42+
'''
43+
Get a specific pod
44+
45+
:param pod_id: the id of the pod
46+
'''
47+
raw_response = run_graphql_query(pod_queries.generate_pod_query(pod_id))
48+
return raw_response["data"]["pod"]
49+
4150
def create_pod(name : str, image_name : str, gpu_type_id : str, cloud_type : str="ALL",
4251
data_center_id : Optional[str]=None, country_code:Optional[str]=None,
4352
gpu_count:int=1, volume_in_gb:int=0, container_disk_in_gb:int=5,

runpod/api_wrapper/queries/pods.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,38 @@
3333
}}
3434
}}
3535
"""
36+
37+
def generate_pod_query(pod_id):
38+
'''
39+
Generate a query for a specific GPU type
40+
'''
41+
42+
return f"""
43+
query pod {{
44+
pod(input: {{podId: "{pod_id}"}}) {{
45+
id
46+
containerDiskInGb
47+
costPerHr
48+
desiredStatus
49+
dockerArgs
50+
dockerId
51+
env
52+
gpuCount
53+
imageName
54+
lastStatusChange
55+
machineId
56+
memoryInGb
57+
name
58+
podType
59+
port
60+
ports
61+
uptimeSeconds
62+
vcpuCount
63+
volumeInGb
64+
volumeMountPath
65+
machine {{
66+
gpuDisplayName
67+
}}
68+
}}
69+
}}
70+
"""

tests/test_api_wrapper/test_ctl_commands.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,40 @@ def test_get_pods(self):
193193

194194
self.assertEqual(len(pods), 1)
195195
self.assertEqual(pods[0]["id"], "POD_ID")
196+
197+
def test_get_pod(self):
198+
'''
199+
Tests get_pods
200+
'''
201+
with patch("runpod.api_wrapper.graphql.requests.post") as patch_request:
202+
patch_request.return_value.json.return_value = {
203+
"data": {
204+
"pod": {
205+
"id": "POD_ID",
206+
"containerDiskInGb": 5,
207+
"costPerHr": 0.34,
208+
"desiredStatus": "RUNNING",
209+
"dockerArgs": None,
210+
"dockerId": None,
211+
"env": [],
212+
"gpuCount": 1,
213+
"imageName": "runpod/pytorch:2.0.1-py3.10-cuda11.8.0-devel",
214+
"lastStatusChange": "Rented by User: Tue Aug 15 2023",
215+
"machineId": "MACHINE_ID",
216+
"memoryInGb": 83,
217+
"name": "POD_NAME",
218+
"podType": "RESERVED",
219+
"port": None,
220+
"ports": "80/http",
221+
"uptimeSeconds": 0,
222+
"vcpuCount": 21,
223+
"volumeInGb": 200,
224+
"volumeMountPath": "/workspace",
225+
"machine": { "gpuDisplayName": "RTX 3090" }
226+
}
227+
}
228+
}
229+
230+
pods = ctl_commands.get_pod("POD_ID")
231+
232+
self.assertEqual(pods["id"], "POD_ID")

0 commit comments

Comments
 (0)