Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions runpod/api/queries/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@
}
"""

QUERY_ENDPOINT_SNAPSHOT = """
query EndpointSnapshot($id: String!) {
myself {
endpoint(id: $id) {
id name type instanceIds gpuIds gpuCount locations
workersMin workersMax workersPFBTarget idleTimeout
scalerType scalerValue executionTimeoutMs workerInitTimeoutMs
flashBootType minCudaVersion allowedCudaVersions
modelReferences env { key value }
networkVolumeIds { networkVolumeId }
volumes { volumeId volumeType }
template {
name imageName containerDiskInGb dockerArgs
env { key value }
ports containerRegistryAuthId advancedStart startScript config
}
}
}
}
"""

QUERY_FLASH_APP_BY_NAME = """
query getFlashAppByName($flashAppName: String!) {
flashAppByName(flashAppName: $flashAppName) {
Expand Down
34 changes: 34 additions & 0 deletions runpod/apps/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
absent from rest. management verbs for the wider sdk stay in runpod.api.ctl_commands.
"""

from copy import deepcopy
from typing import Any, Dict, List, Optional, Set

import aiohttp
Expand Down Expand Up @@ -245,6 +246,39 @@ async def _execute(
)
return response["data"]

async def snapshot_endpoint(self, endpoint_id: str) -> Dict[str, Any]:
"""capture a saveable endpoint configuration in memory for rollback."""
data = await self._execute(
app_queries.QUERY_ENDPOINT_SNAPSHOT, {"id": endpoint_id}, retry=True
)
endpoint = (data.get("myself") or {}).get("endpoint")
template = (endpoint or {}).get("template")
if (
not endpoint
or endpoint.get("id") != endpoint_id
or not template
or not template.get("imageName")
):
raise RuntimeError(
f"endpoint {endpoint_id} has no restorable configuration"
)
snapshot = deepcopy(endpoint)
template = snapshot["template"]
snapshot["template"]["containerRegistryAuthId"] = (
template.get("containerRegistryAuthId") or ""
)
snapshot["template"]["dockerArgs"] = template.get("dockerArgs") or ""
snapshot["template"]["env"] = template.get("env") or []
snapshot["env"] = snapshot.get("env") or []
snapshot["modelReferences"] = snapshot.get("modelReferences") or []
snapshot["networkVolumeIds"] = snapshot.get("networkVolumeIds") or []
snapshot["volumes"] = [
volume
for volume in snapshot.get("volumes") or []
if volume["volumeType"] == "OBJECT_STORE_VOLUME"
]
return snapshot

async def save_endpoint(self, endpoint_input: Dict[str, Any]) -> Dict[str, Any]:
"""save via rest unless the input requires an unsupported capability."""
body = _rest_endpoint_input(endpoint_input)
Expand Down
Loading
Loading