-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmixins.py
More file actions
97 lines (67 loc) · 2.74 KB
/
mixins.py
File metadata and controls
97 lines (67 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from mpt_api_client.models.model import ResourceData
class TerminateMixin[Model]:
"""Terminate resource mixin."""
def terminate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Terminate resource.
Args:
resource_id: Resource ID
resource_data: Resource data
Returns:
Terminated resource.
"""
return self._resource_action(resource_id, "POST", "terminate", json=resource_data) # type: ignore[attr-defined, no-any-return]
class RenderMixin[Model]:
"""Render resource mixin."""
def render(self, resource_id: str) -> str:
"""Render resource.
Args:
resource_id: Resource ID
Returns:
Rendered resource.
"""
response = self._resource_do_request(resource_id, action="render") # type: ignore[attr-defined]
return response.text # type: ignore[no-any-return]
class TemplateMixin[Model]:
"""Template resource mixin."""
def template(self, resource_id: str) -> str:
"""Get resource template.
Args:
resource_id: Resource ID
Returns:
Resource template.
"""
response = self._resource_do_request(resource_id, action="template") # type: ignore[attr-defined]
return response.text # type: ignore[no-any-return]
class AsyncTerminateMixin[Model]:
"""Asynchronous terminate resource mixin."""
async def terminate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Terminate resource.
Args:
resource_id: Resource ID
resource_data: Resource data
Returns:
Terminated resource.
"""
return await self._resource_action(resource_id, "POST", "terminate", json=resource_data) # type: ignore[attr-defined, no-any-return]
class AsyncRenderMixin[Model]:
"""Asynchronous render resource mixin."""
async def render(self, resource_id: str) -> str:
"""Render resource.
Args:
resource_id: Resource ID
Returns:
Rendered resource.
"""
response = await self._resource_do_request(resource_id, action="render") # type: ignore[attr-defined]
return response.text # type: ignore[no-any-return]
class AsyncTemplateMixin[Model]:
"""Asynchronous template resource mixin."""
async def template(self, resource_id: str) -> str:
"""Get resource template.
Args:
resource_id: Resource ID
Returns:
Resource template.
"""
response = await self._resource_do_request(resource_id, action="template") # type: ignore[attr-defined]
return response.text # type: ignore[no-any-return]