Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(serverless_jobs): include ListJobsResources method to sdk #547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
6 changes: 6 additions & 0 deletions scaleway-async/scaleway_async/jobs/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .types import CreateJobDefinitionRequestCronScheduleConfig
from .types import JobDefinition
from .types import JobRun
from .types import Resource
from .types import UpdateJobDefinitionRequestCronScheduleConfig
from .types import CreateJobDefinitionRequest
from .types import DeleteJobDefinitionRequest
Expand All @@ -17,6 +18,8 @@
from .types import ListJobDefinitionsResponse
from .types import ListJobRunsRequest
from .types import ListJobRunsResponse
from .types import ListJobsResourcesRequest
from .types import ListJobsResourcesResponse
from .types import StartJobDefinitionRequest
from .types import StartJobDefinitionResponse
from .types import StopJobRunRequest
Expand All @@ -32,6 +35,7 @@
"CreateJobDefinitionRequestCronScheduleConfig",
"JobDefinition",
"JobRun",
"Resource",
"UpdateJobDefinitionRequestCronScheduleConfig",
"CreateJobDefinitionRequest",
"DeleteJobDefinitionRequest",
Expand All @@ -41,6 +45,8 @@
"ListJobDefinitionsResponse",
"ListJobRunsRequest",
"ListJobRunsResponse",
"ListJobsResourcesRequest",
"ListJobsResourcesResponse",
"StartJobDefinitionRequest",
"StartJobDefinitionResponse",
"StopJobRunRequest",
Expand Down
30 changes: 30 additions & 0 deletions scaleway-async/scaleway_async/jobs/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
JobRun,
ListJobDefinitionsResponse,
ListJobRunsResponse,
ListJobsResourcesResponse,
StartJobDefinitionRequest,
StartJobDefinitionResponse,
UpdateJobDefinitionRequest,
Expand All @@ -31,6 +32,7 @@
unmarshal_JobRun,
unmarshal_ListJobDefinitionsResponse,
unmarshal_ListJobRunsResponse,
unmarshal_ListJobsResourcesResponse,
unmarshal_StartJobDefinitionResponse,
marshal_CreateJobDefinitionRequest,
marshal_StartJobDefinitionRequest,
Expand Down Expand Up @@ -551,3 +553,31 @@ async def list_job_runs_all(
"organization_id": organization_id,
},
)

async def list_jobs_resources(
self,
*,
region: Optional[Region] = None,
) -> ListJobsResourcesResponse:
"""
List jobs resources for the console.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`ListJobsResourcesResponse <ListJobsResourcesResponse>`

Usage:
::

result = await api.list_jobs_resources()
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)

res = self._request(
"GET",
f"/serverless-jobs/v1alpha1/regions/{param_region}/jobs-resources",
)

self._throw_on_error(res)
return unmarshal_ListJobsResourcesResponse(res.json())
38 changes: 38 additions & 0 deletions scaleway-async/scaleway_async/jobs/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
JobRun,
ListJobDefinitionsResponse,
ListJobRunsResponse,
Resource,
ListJobsResourcesResponse,
StartJobDefinitionResponse,
CreateJobDefinitionRequestCronScheduleConfig,
CreateJobDefinitionRequest,
Expand Down Expand Up @@ -249,6 +251,42 @@ def unmarshal_ListJobRunsResponse(data: Any) -> ListJobRunsResponse:
return ListJobRunsResponse(**args)


def unmarshal_Resource(data: Any) -> Resource:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'Resource' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("cpu_limit", None)
if field is not None:
args["cpu_limit"] = field

field = data.get("memory_limit", None)
if field is not None:
args["memory_limit"] = field

return Resource(**args)


def unmarshal_ListJobsResourcesResponse(data: Any) -> ListJobsResourcesResponse:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'ListJobsResourcesResponse' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("resources", None)
if field is not None:
args["resources"] = (
[unmarshal_Resource(v) for v in field] if field is not None else None
)

return ListJobsResourcesResponse(**args)


def unmarshal_StartJobDefinitionResponse(data: Any) -> StartJobDefinitionResponse:
if not isinstance(data, dict):
raise TypeError(
Expand Down
20 changes: 20 additions & 0 deletions scaleway-async/scaleway_async/jobs/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ class JobRun:
started_at: Optional[datetime]


@dataclass
class Resource:
cpu_limit: int

memory_limit: int


@dataclass
class UpdateJobDefinitionRequestCronScheduleConfig:
schedule: Optional[str]
Expand Down Expand Up @@ -297,6 +304,19 @@ class ListJobRunsResponse:
total_count: int


@dataclass
class ListJobsResourcesRequest:
region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
"""


@dataclass
class ListJobsResourcesResponse:
resources: List[Resource]


@dataclass
class StartJobDefinitionRequest:
job_definition_id: str
Expand Down
6 changes: 6 additions & 0 deletions scaleway/scaleway/jobs/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .types import CreateJobDefinitionRequestCronScheduleConfig
from .types import JobDefinition
from .types import JobRun
from .types import Resource
from .types import UpdateJobDefinitionRequestCronScheduleConfig
from .types import CreateJobDefinitionRequest
from .types import DeleteJobDefinitionRequest
Expand All @@ -17,6 +18,8 @@
from .types import ListJobDefinitionsResponse
from .types import ListJobRunsRequest
from .types import ListJobRunsResponse
from .types import ListJobsResourcesRequest
from .types import ListJobsResourcesResponse
from .types import StartJobDefinitionRequest
from .types import StartJobDefinitionResponse
from .types import StopJobRunRequest
Expand All @@ -32,6 +35,7 @@
"CreateJobDefinitionRequestCronScheduleConfig",
"JobDefinition",
"JobRun",
"Resource",
"UpdateJobDefinitionRequestCronScheduleConfig",
"CreateJobDefinitionRequest",
"DeleteJobDefinitionRequest",
Expand All @@ -41,6 +45,8 @@
"ListJobDefinitionsResponse",
"ListJobRunsRequest",
"ListJobRunsResponse",
"ListJobsResourcesRequest",
"ListJobsResourcesResponse",
"StartJobDefinitionRequest",
"StartJobDefinitionResponse",
"StopJobRunRequest",
Expand Down
30 changes: 30 additions & 0 deletions scaleway/scaleway/jobs/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
JobRun,
ListJobDefinitionsResponse,
ListJobRunsResponse,
ListJobsResourcesResponse,
StartJobDefinitionRequest,
StartJobDefinitionResponse,
UpdateJobDefinitionRequest,
Expand All @@ -31,6 +32,7 @@
unmarshal_JobRun,
unmarshal_ListJobDefinitionsResponse,
unmarshal_ListJobRunsResponse,
unmarshal_ListJobsResourcesResponse,
unmarshal_StartJobDefinitionResponse,
marshal_CreateJobDefinitionRequest,
marshal_StartJobDefinitionRequest,
Expand Down Expand Up @@ -551,3 +553,31 @@ def list_job_runs_all(
"organization_id": organization_id,
},
)

def list_jobs_resources(
self,
*,
region: Optional[Region] = None,
) -> ListJobsResourcesResponse:
"""
List jobs resources for the console.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`ListJobsResourcesResponse <ListJobsResourcesResponse>`

Usage:
::

result = api.list_jobs_resources()
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)

res = self._request(
"GET",
f"/serverless-jobs/v1alpha1/regions/{param_region}/jobs-resources",
)

self._throw_on_error(res)
return unmarshal_ListJobsResourcesResponse(res.json())
38 changes: 38 additions & 0 deletions scaleway/scaleway/jobs/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
JobRun,
ListJobDefinitionsResponse,
ListJobRunsResponse,
Resource,
ListJobsResourcesResponse,
StartJobDefinitionResponse,
CreateJobDefinitionRequestCronScheduleConfig,
CreateJobDefinitionRequest,
Expand Down Expand Up @@ -249,6 +251,42 @@ def unmarshal_ListJobRunsResponse(data: Any) -> ListJobRunsResponse:
return ListJobRunsResponse(**args)


def unmarshal_Resource(data: Any) -> Resource:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'Resource' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("cpu_limit", None)
if field is not None:
args["cpu_limit"] = field

field = data.get("memory_limit", None)
if field is not None:
args["memory_limit"] = field

return Resource(**args)


def unmarshal_ListJobsResourcesResponse(data: Any) -> ListJobsResourcesResponse:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'ListJobsResourcesResponse' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("resources", None)
if field is not None:
args["resources"] = (
[unmarshal_Resource(v) for v in field] if field is not None else None
)

return ListJobsResourcesResponse(**args)


def unmarshal_StartJobDefinitionResponse(data: Any) -> StartJobDefinitionResponse:
if not isinstance(data, dict):
raise TypeError(
Expand Down
20 changes: 20 additions & 0 deletions scaleway/scaleway/jobs/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ class JobRun:
started_at: Optional[datetime]


@dataclass
class Resource:
cpu_limit: int

memory_limit: int


@dataclass
class UpdateJobDefinitionRequestCronScheduleConfig:
schedule: Optional[str]
Expand Down Expand Up @@ -297,6 +304,19 @@ class ListJobRunsResponse:
total_count: int


@dataclass
class ListJobsResourcesRequest:
region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
"""


@dataclass
class ListJobsResourcesResponse:
resources: List[Resource]


@dataclass
class StartJobDefinitionRequest:
job_definition_id: str
Expand Down