Skip to content

Commit 4067066

Browse files
Merge pull request #224 from runpod/main
update branch
2 parents 2222320 + 3d78e39 commit 4067066

File tree

17 files changed

+413
-146
lines changed

17 files changed

+413
-146
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Change Log
22

3+
## Release 1.3.4 (11/14/23)
4+
5+
### Changed
6+
7+
- Logs are now JSON formatted
8+
- Exposed logging `job_id` now `request_id`
9+
10+
### Added
11+
12+
- `get_endpoints` exposed to return all endpoints for a given user
13+
14+
---
15+
316
## Release 1.3.3 (11/8/23)
417

518
### Added

examples/api/get_endpoints.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
""" Get all endpoints from the API """
2+
3+
4+
import runpod
5+
6+
endpoints = runpod.get_endpoints()
7+
8+
print(endpoints)

examples/serverless/logger.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
# ERROR | An error message
1919

2020

21-
log.debug('A debug message', job_id=JOB_ID)
22-
log.info('An info message', job_id=JOB_ID)
23-
log.warn('A warning message', job_id=JOB_ID)
24-
log.error('An error message', job_id=JOB_ID)
21+
log.debug('A debug message', request_id=JOB_ID)
22+
log.info('An info message', request_id=JOB_ID)
23+
log.warn('A warning message', request_id=JOB_ID)
24+
log.error('An error message', request_id=JOB_ID)
2525

2626
# Output:
2727
# {"requestId": "1234567890", "message": "A debug message", "level": "DEBUG"}

runpod/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
get_gpu, get_gpus,
1414
get_pod, get_pods, create_pod, stop_pod, resume_pod, terminate_pod,
1515
create_template,
16-
create_endpoint
16+
get_endpoints, create_endpoint, update_endpoint_template
1717
)
1818
from .cli.groups.config.functions import set_credentials, check_credentials, get_credentials
1919

runpod/api/ctl_commands.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .mutations import user as user_mutations
1010
from .queries import gpus
1111
from .queries import pods as pod_queries
12+
from .queries import endpoints as endpoint_queries
1213
from .graphql import run_graphql_query
1314
from .mutations import pods as pod_mutations
1415
from .mutations import endpoints as endpoint_mutations
@@ -228,6 +229,14 @@ def create_template(
228229

229230
return raw_response["data"]["saveTemplate"]
230231

232+
def get_endpoints() -> dict:
233+
'''
234+
Get all endpoints
235+
'''
236+
raw_return = run_graphql_query(endpoint_queries.QUERY_ENDPOINT)
237+
cleaned_return = raw_return["data"]["myself"]["endpoints"]
238+
return cleaned_return
239+
231240
def create_endpoint(
232241
name:str, template_id:str, gpu_ids:str="AMPERE_16",
233242
network_volume_id:str=None, locations:str=None,
@@ -262,3 +271,25 @@ def create_endpoint(
262271
)
263272

264273
return raw_response["data"]["saveEndpoint"]
274+
275+
276+
def update_endpoint_template(
277+
endpoint_id:str, template_id:str
278+
):
279+
'''
280+
Update an endpoint template
281+
282+
:param endpoint_id: the id of the endpoint
283+
:param template_id: the id of the template to use for the endpoint
284+
285+
:example:
286+
287+
>>> endpoint_id = runpod.update_endpoint_template("test", "template_id")
288+
'''
289+
raw_response = run_graphql_query(
290+
endpoint_mutations.update_endpoint_template_mutation(
291+
endpoint_id, template_id
292+
)
293+
)
294+
295+
return raw_response["data"]["updateEndpointTemplate"]

runpod/api/mutations/endpoints.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# pylint: disable=too-many-arguments
44

5+
56
def generate_endpoint_mutation(
6-
name:str, template_id:str, gpu_ids:str="AMPERE_16",
7-
network_volume_id:str=None, locations:str=None,
8-
idle_timeout:int=5, scaler_type:str="QUEUE_DELAY", scaler_value:int=4,
9-
workers_min:int=0, workers_max:int=3
7+
name: str, template_id: str, gpu_ids: str = "AMPERE_16",
8+
network_volume_id: str = None, locations: str = None,
9+
idle_timeout: int = 5, scaler_type: str = "QUEUE_DELAY", scaler_value: int = 4,
10+
workers_min: int = 0, workers_max: int = 3
1011
):
1112
""" Generate a string for a GraphQL mutation to create a new endpoint. """
1213
input_fields = []
@@ -57,3 +58,26 @@ def generate_endpoint_mutation(
5758
}}
5859
}}
5960
"""
61+
62+
63+
def update_endpoint_template_mutation(
64+
endpoint_id: str, template_id: str
65+
):
66+
""" Generate a string for a GraphQL mutation to update an existing endpoint's template. """
67+
input_fields = []
68+
69+
# ------------------------------ Required Fields ----------------------------- #
70+
input_fields.append(f'templateId: "{template_id}"')
71+
input_fields.append(f'endpointId: "{endpoint_id}"')
72+
73+
# Format the input fields into a string
74+
input_fields_string = ", ".join(input_fields)
75+
result = f"""
76+
mutation {{
77+
updateEndpointTemplate(input: {{{input_fields_string}}}) {{
78+
id
79+
templateId
80+
}}
81+
}}
82+
"""
83+
return result

runpod/api/queries/endpoints.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
""" GraphQL queries for endpoints. """
2+
3+
QUERY_ENDPOINT = """
4+
query Query {
5+
myself {
6+
endpoints {
7+
aiKey
8+
gpuIds
9+
id
10+
idleTimeout
11+
name
12+
networkVolumeId
13+
locations
14+
scalerType
15+
scalerValue
16+
templateId
17+
type
18+
userId
19+
version
20+
workersMax
21+
workersMin
22+
workersStandby
23+
gpuCount
24+
env {
25+
key
26+
value
27+
}
28+
createdAt
29+
networkVolume {
30+
id
31+
dataCenterId
32+
}
33+
}
34+
}
35+
}
36+
"""

0 commit comments

Comments
 (0)