worker_manager_clients.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from gpustack.api.exceptions import raise_if_response_error
  2. from gpustack.schemas.workers import (
  3. WorkerStatusPublic,
  4. WorkerCreate,
  5. WorkerRegistrationPublic,
  6. )
  7. from .generated_http_client import HTTPClient
  8. class WorkerStatusClient:
  9. def __init__(self, client: HTTPClient):
  10. self._client = client
  11. self._url = "/worker-status"
  12. def create(self, model_create: WorkerStatusPublic):
  13. response = self._client.get_httpx_client().post(
  14. self._url,
  15. content=model_create.model_dump_json(),
  16. headers={"Content-Type": "application/json"},
  17. )
  18. raise_if_response_error(response)
  19. return None
  20. async def create_async(self, model_create: WorkerStatusPublic):
  21. response = await self._client.get_async_httpx_client().post(
  22. self._url,
  23. content=model_create.model_dump_json(),
  24. headers={"Content-Type": "application/json"},
  25. )
  26. raise_if_response_error(response)
  27. return None
  28. class WorkerRegistrationClient:
  29. def __init__(self, client: HTTPClient):
  30. self._client = client
  31. self._url = "/workers"
  32. def create(self, model_create: WorkerCreate):
  33. response = self._client.get_httpx_client().post(
  34. self._url,
  35. content=model_create.model_dump_json(),
  36. headers={"Content-Type": "application/json"},
  37. )
  38. raise_if_response_error(response)
  39. return WorkerRegistrationPublic.model_validate(response.json())
  40. async def create_async(self, model_create: WorkerCreate):
  41. response = await self._client.get_async_httpx_client().post(
  42. self._url,
  43. content=model_create.model_dump_json(),
  44. headers={"Content-Type": "application/json"},
  45. )
  46. raise_if_response_error(response)
  47. return WorkerRegistrationPublic.model_validate(response.json())