Skip to content

Commit

Permalink
Merge pull request #223 from runpod/main
Browse files Browse the repository at this point in the history
Updating branch
  • Loading branch information
justinmerrell authored Nov 15, 2023
2 parents 57502b0 + 3d78e39 commit c8dc3d7
Show file tree
Hide file tree
Showing 17 changed files with 413 additions and 146 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Change Log

## Release 1.3.4 (11/14/23)

### Changed

- Logs are now JSON formatted
- Exposed logging `job_id` now `request_id`

### Added

- `get_endpoints` exposed to return all endpoints for a given user

---

## Release 1.3.3 (11/8/23)

### Added
Expand Down
8 changes: 8 additions & 0 deletions examples/api/get_endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
""" Get all endpoints from the API """


import runpod

endpoints = runpod.get_endpoints()

print(endpoints)
8 changes: 4 additions & 4 deletions examples/serverless/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
# ERROR | An error message


log.debug('A debug message', job_id=JOB_ID)
log.info('An info message', job_id=JOB_ID)
log.warn('A warning message', job_id=JOB_ID)
log.error('An error message', job_id=JOB_ID)
log.debug('A debug message', request_id=JOB_ID)
log.info('An info message', request_id=JOB_ID)
log.warn('A warning message', request_id=JOB_ID)
log.error('An error message', request_id=JOB_ID)

# Output:
# {"requestId": "1234567890", "message": "A debug message", "level": "DEBUG"}
Expand Down
2 changes: 1 addition & 1 deletion runpod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
get_gpu, get_gpus,
get_pod, get_pods, create_pod, stop_pod, resume_pod, terminate_pod,
create_template,
create_endpoint
get_endpoints, create_endpoint, update_endpoint_template
)
from .cli.groups.config.functions import set_credentials, check_credentials, get_credentials

Expand Down
31 changes: 31 additions & 0 deletions runpod/api/ctl_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .mutations import user as user_mutations
from .queries import gpus
from .queries import pods as pod_queries
from .queries import endpoints as endpoint_queries
from .graphql import run_graphql_query
from .mutations import pods as pod_mutations
from .mutations import endpoints as endpoint_mutations
Expand Down Expand Up @@ -228,6 +229,14 @@ def create_template(

return raw_response["data"]["saveTemplate"]

def get_endpoints() -> dict:
'''
Get all endpoints
'''
raw_return = run_graphql_query(endpoint_queries.QUERY_ENDPOINT)
cleaned_return = raw_return["data"]["myself"]["endpoints"]
return cleaned_return

def create_endpoint(
name:str, template_id:str, gpu_ids:str="AMPERE_16",
network_volume_id:str=None, locations:str=None,
Expand Down Expand Up @@ -262,3 +271,25 @@ def create_endpoint(
)

return raw_response["data"]["saveEndpoint"]


def update_endpoint_template(
endpoint_id:str, template_id:str
):
'''
Update an endpoint template
:param endpoint_id: the id of the endpoint
:param template_id: the id of the template to use for the endpoint
:example:
>>> endpoint_id = runpod.update_endpoint_template("test", "template_id")
'''
raw_response = run_graphql_query(
endpoint_mutations.update_endpoint_template_mutation(
endpoint_id, template_id
)
)

return raw_response["data"]["updateEndpointTemplate"]
32 changes: 28 additions & 4 deletions runpod/api/mutations/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

# pylint: disable=too-many-arguments


def generate_endpoint_mutation(
name:str, template_id:str, gpu_ids:str="AMPERE_16",
network_volume_id:str=None, locations:str=None,
idle_timeout:int=5, scaler_type:str="QUEUE_DELAY", scaler_value:int=4,
workers_min:int=0, workers_max:int=3
name: str, template_id: str, gpu_ids: str = "AMPERE_16",
network_volume_id: str = None, locations: str = None,
idle_timeout: int = 5, scaler_type: str = "QUEUE_DELAY", scaler_value: int = 4,
workers_min: int = 0, workers_max: int = 3
):
""" Generate a string for a GraphQL mutation to create a new endpoint. """
input_fields = []
Expand Down Expand Up @@ -57,3 +58,26 @@ def generate_endpoint_mutation(
}}
}}
"""


def update_endpoint_template_mutation(
endpoint_id: str, template_id: str
):
""" Generate a string for a GraphQL mutation to update an existing endpoint's template. """
input_fields = []

# ------------------------------ Required Fields ----------------------------- #
input_fields.append(f'templateId: "{template_id}"')
input_fields.append(f'endpointId: "{endpoint_id}"')

# Format the input fields into a string
input_fields_string = ", ".join(input_fields)
result = f"""
mutation {{
updateEndpointTemplate(input: {{{input_fields_string}}}) {{
id
templateId
}}
}}
"""
return result
36 changes: 36 additions & 0 deletions runpod/api/queries/endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
""" GraphQL queries for endpoints. """

QUERY_ENDPOINT = """
query Query {
myself {
endpoints {
aiKey
gpuIds
id
idleTimeout
name
networkVolumeId
locations
scalerType
scalerValue
templateId
type
userId
version
workersMax
workersMin
workersStandby
gpuCount
env {
key
value
}
createdAt
networkVolume {
id
dataCenterId
}
}
}
}
"""
Loading

0 comments on commit c8dc3d7

Please sign in to comment.