intelion-cloud 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- intelion_cloud-0.2.0/LICENSE +21 -0
- intelion_cloud-0.2.0/PKG-INFO +134 -0
- intelion_cloud-0.2.0/README.md +106 -0
- intelion_cloud-0.2.0/intelion_cloud/__init__.py +82 -0
- intelion_cloud-0.2.0/intelion_cloud/_client.py +108 -0
- intelion_cloud-0.2.0/intelion_cloud/_pagination.py +66 -0
- intelion_cloud-0.2.0/intelion_cloud/_transport.py +342 -0
- intelion_cloud-0.2.0/intelion_cloud/constants.py +74 -0
- intelion_cloud-0.2.0/intelion_cloud/exceptions.py +92 -0
- intelion_cloud-0.2.0/intelion_cloud/models/__init__.py +33 -0
- intelion_cloud-0.2.0/intelion_cloud/models/_base.py +39 -0
- intelion_cloud-0.2.0/intelion_cloud/models/components.py +218 -0
- intelion_cloud-0.2.0/intelion_cloud/models/flavors.py +44 -0
- intelion_cloud-0.2.0/intelion_cloud/models/servers.py +247 -0
- intelion_cloud-0.2.0/intelion_cloud/models/users.py +73 -0
- intelion_cloud-0.2.0/intelion_cloud/resources/__init__.py +17 -0
- intelion_cloud-0.2.0/intelion_cloud/resources/_base.py +152 -0
- intelion_cloud-0.2.0/intelion_cloud/resources/cloud_servers.py +293 -0
- intelion_cloud-0.2.0/intelion_cloud/resources/flavors.py +42 -0
- intelion_cloud-0.2.0/intelion_cloud/resources/os_images.py +66 -0
- intelion_cloud-0.2.0/intelion_cloud/resources/users.py +100 -0
- intelion_cloud-0.2.0/intelion_cloud.egg-info/PKG-INFO +134 -0
- intelion_cloud-0.2.0/intelion_cloud.egg-info/SOURCES.txt +32 -0
- intelion_cloud-0.2.0/intelion_cloud.egg-info/dependency_links.txt +1 -0
- intelion_cloud-0.2.0/intelion_cloud.egg-info/requires.txt +6 -0
- intelion_cloud-0.2.0/intelion_cloud.egg-info/top_level.txt +1 -0
- intelion_cloud-0.2.0/pyproject.toml +43 -0
- intelion_cloud-0.2.0/setup.cfg +4 -0
- intelion_cloud-0.2.0/tests/test_client.py +57 -0
- intelion_cloud-0.2.0/tests/test_cloud_servers.py +258 -0
- intelion_cloud-0.2.0/tests/test_flavors.py +33 -0
- intelion_cloud-0.2.0/tests/test_models.py +232 -0
- intelion_cloud-0.2.0/tests/test_transport.py +182 -0
- intelion_cloud-0.2.0/tests/test_users.py +49 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Intelion.Cloud
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: intelion-cloud
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python client for the Intelion Cloud API
|
|
5
|
+
Author-email: Intelion Cloud <support@intelion.cloud>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://intelion.cloud
|
|
8
|
+
Project-URL: Documentation, https://intelion.cloud/swagger/
|
|
9
|
+
Project-URL: Repository, https://github.com/IntelionCloud/ic_python_client
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: httpx>=0.24
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
26
|
+
Requires-Dist: respx>=0.20; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# Intelion Cloud Python Client
|
|
30
|
+
|
|
31
|
+
[](https://pypi.org/project/intelion-cloud/)
|
|
32
|
+
[](https://pypi.org/project/intelion-cloud/)
|
|
33
|
+
[](https://github.com/IntelionCloud/ic_python_client/blob/main/LICENSE)
|
|
34
|
+
|
|
35
|
+
Official Python SDK for the [Intelion Cloud](https://intelion.cloud) GPU cloud API (`/api/v2/`).
|
|
36
|
+
|
|
37
|
+
Pure `httpx` — no Django dependency. Sync and async clients, typed dataclass models, automatic pagination, retries with exponential backoff.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install intelion-cloud
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Requires Python 3.9+.
|
|
46
|
+
|
|
47
|
+
## Quickstart
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from intelion_cloud import IntelionCloud
|
|
51
|
+
|
|
52
|
+
client = IntelionCloud(token="your_api_token")
|
|
53
|
+
|
|
54
|
+
# List your cloud servers
|
|
55
|
+
for server in client.cloud_servers.list():
|
|
56
|
+
print(server.id, server.name, server.status)
|
|
57
|
+
|
|
58
|
+
# Start / stop a server
|
|
59
|
+
client.cloud_servers.start(server_id=42)
|
|
60
|
+
client.cloud_servers.stop(server_id=42)
|
|
61
|
+
|
|
62
|
+
# Create a new server
|
|
63
|
+
new_server = client.cloud_servers.create(
|
|
64
|
+
name="my-h100-box",
|
|
65
|
+
flavor_id=1, # FlavorConfig PK
|
|
66
|
+
ssd_count=100, # network disk size, GB (min 30)
|
|
67
|
+
os_id=1, # OperationalSystemImage PK
|
|
68
|
+
price_plan=0, # 0 = hourly, 1 = monthly, ...
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
client.close()
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Async client
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import asyncio
|
|
78
|
+
from intelion_cloud import AsyncIntelionCloud
|
|
79
|
+
|
|
80
|
+
async def main():
|
|
81
|
+
async with AsyncIntelionCloud(token="your_api_token") as client:
|
|
82
|
+
me = await client.users.me()
|
|
83
|
+
print(me.username, me.current_balance_rub_cents)
|
|
84
|
+
|
|
85
|
+
asyncio.run(main())
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Context manager
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
with IntelionCloud(token="...") as client:
|
|
92
|
+
servers = client.cloud_servers.list()
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Available resources
|
|
96
|
+
|
|
97
|
+
| Resource | Methods |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `client.cloud_servers` | `list()`, `get()`, `create()`, `update()`, `start()`, `stop()`, `reboot()`, `delete()`, `get_status()`, `get_password()`, `clone()`, `migrate()` |
|
|
100
|
+
| `client.flavors` | `list()` |
|
|
101
|
+
| `client.os_images` | `list(flavor_id=, gpu_id=)` |
|
|
102
|
+
| `client.users` | `me()`, `get()`, `update()` |
|
|
103
|
+
|
|
104
|
+
## Authentication
|
|
105
|
+
|
|
106
|
+
Get your API token from the [Intelion Cloud dashboard](https://intelion.cloud). The client sends it as `Authorization: Token {token}`.
|
|
107
|
+
|
|
108
|
+
## Error handling
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from intelion_cloud import (
|
|
112
|
+
AuthenticationError, NotFoundError, ConflictError,
|
|
113
|
+
RateLimitError, ValidationError, ServerError,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
try:
|
|
117
|
+
server = client.cloud_servers.get(999)
|
|
118
|
+
except NotFoundError:
|
|
119
|
+
print("Server not found")
|
|
120
|
+
except AuthenticationError:
|
|
121
|
+
print("Invalid token")
|
|
122
|
+
except ValidationError as e:
|
|
123
|
+
print("Field errors:", e.field_errors)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Links
|
|
127
|
+
|
|
128
|
+
- **Homepage:** https://intelion.cloud
|
|
129
|
+
- **API docs (Swagger):** https://intelion.cloud/api/
|
|
130
|
+
- **Source:** https://github.com/IntelionCloud/ic_python_client
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Intelion Cloud Python Client
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/intelion-cloud/)
|
|
4
|
+
[](https://pypi.org/project/intelion-cloud/)
|
|
5
|
+
[](https://github.com/IntelionCloud/ic_python_client/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
Official Python SDK for the [Intelion Cloud](https://intelion.cloud) GPU cloud API (`/api/v2/`).
|
|
8
|
+
|
|
9
|
+
Pure `httpx` — no Django dependency. Sync and async clients, typed dataclass models, automatic pagination, retries with exponential backoff.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install intelion-cloud
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Requires Python 3.9+.
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from intelion_cloud import IntelionCloud
|
|
23
|
+
|
|
24
|
+
client = IntelionCloud(token="your_api_token")
|
|
25
|
+
|
|
26
|
+
# List your cloud servers
|
|
27
|
+
for server in client.cloud_servers.list():
|
|
28
|
+
print(server.id, server.name, server.status)
|
|
29
|
+
|
|
30
|
+
# Start / stop a server
|
|
31
|
+
client.cloud_servers.start(server_id=42)
|
|
32
|
+
client.cloud_servers.stop(server_id=42)
|
|
33
|
+
|
|
34
|
+
# Create a new server
|
|
35
|
+
new_server = client.cloud_servers.create(
|
|
36
|
+
name="my-h100-box",
|
|
37
|
+
flavor_id=1, # FlavorConfig PK
|
|
38
|
+
ssd_count=100, # network disk size, GB (min 30)
|
|
39
|
+
os_id=1, # OperationalSystemImage PK
|
|
40
|
+
price_plan=0, # 0 = hourly, 1 = monthly, ...
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
client.close()
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Async client
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import asyncio
|
|
50
|
+
from intelion_cloud import AsyncIntelionCloud
|
|
51
|
+
|
|
52
|
+
async def main():
|
|
53
|
+
async with AsyncIntelionCloud(token="your_api_token") as client:
|
|
54
|
+
me = await client.users.me()
|
|
55
|
+
print(me.username, me.current_balance_rub_cents)
|
|
56
|
+
|
|
57
|
+
asyncio.run(main())
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Context manager
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
with IntelionCloud(token="...") as client:
|
|
64
|
+
servers = client.cloud_servers.list()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Available resources
|
|
68
|
+
|
|
69
|
+
| Resource | Methods |
|
|
70
|
+
|---|---|
|
|
71
|
+
| `client.cloud_servers` | `list()`, `get()`, `create()`, `update()`, `start()`, `stop()`, `reboot()`, `delete()`, `get_status()`, `get_password()`, `clone()`, `migrate()` |
|
|
72
|
+
| `client.flavors` | `list()` |
|
|
73
|
+
| `client.os_images` | `list(flavor_id=, gpu_id=)` |
|
|
74
|
+
| `client.users` | `me()`, `get()`, `update()` |
|
|
75
|
+
|
|
76
|
+
## Authentication
|
|
77
|
+
|
|
78
|
+
Get your API token from the [Intelion Cloud dashboard](https://intelion.cloud). The client sends it as `Authorization: Token {token}`.
|
|
79
|
+
|
|
80
|
+
## Error handling
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from intelion_cloud import (
|
|
84
|
+
AuthenticationError, NotFoundError, ConflictError,
|
|
85
|
+
RateLimitError, ValidationError, ServerError,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
try:
|
|
89
|
+
server = client.cloud_servers.get(999)
|
|
90
|
+
except NotFoundError:
|
|
91
|
+
print("Server not found")
|
|
92
|
+
except AuthenticationError:
|
|
93
|
+
print("Invalid token")
|
|
94
|
+
except ValidationError as e:
|
|
95
|
+
print("Field errors:", e.field_errors)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Links
|
|
99
|
+
|
|
100
|
+
- **Homepage:** https://intelion.cloud
|
|
101
|
+
- **API docs (Swagger):** https://intelion.cloud/api/
|
|
102
|
+
- **Source:** https://github.com/IntelionCloud/ic_python_client
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""Intelion Cloud Python client.
|
|
2
|
+
|
|
3
|
+
Usage::
|
|
4
|
+
|
|
5
|
+
from intelion_cloud import IntelionCloud
|
|
6
|
+
|
|
7
|
+
client = IntelionCloud(token="your_api_token")
|
|
8
|
+
servers = client.cloud_servers.list()
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from ._client import AsyncIntelionCloud, IntelionCloud
|
|
12
|
+
from .constants import BillingPeriod, PricePlan, ServerState
|
|
13
|
+
from .constants import ServerStatus as ServerStatusEnum
|
|
14
|
+
from .exceptions import (
|
|
15
|
+
APIError,
|
|
16
|
+
AuthenticationError,
|
|
17
|
+
ConflictError,
|
|
18
|
+
ConnectionError,
|
|
19
|
+
ForbiddenError,
|
|
20
|
+
IntelionCloudError,
|
|
21
|
+
NotFoundError,
|
|
22
|
+
RateLimitError,
|
|
23
|
+
ServerError,
|
|
24
|
+
ValidationError,
|
|
25
|
+
)
|
|
26
|
+
from .models import (
|
|
27
|
+
CPU,
|
|
28
|
+
GPU,
|
|
29
|
+
OSImage,
|
|
30
|
+
RAM,
|
|
31
|
+
SSD,
|
|
32
|
+
CloudServer,
|
|
33
|
+
DebtInfo,
|
|
34
|
+
Flavor,
|
|
35
|
+
PhysicalServer,
|
|
36
|
+
Promocode,
|
|
37
|
+
ServerStatus,
|
|
38
|
+
SoftwareAddonInstance,
|
|
39
|
+
UsageAct,
|
|
40
|
+
User,
|
|
41
|
+
WhiteIP,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
__version__ = "0.2.0"
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
# Clients
|
|
48
|
+
"IntelionCloud",
|
|
49
|
+
"AsyncIntelionCloud",
|
|
50
|
+
# Models
|
|
51
|
+
"CloudServer",
|
|
52
|
+
"ServerStatus",
|
|
53
|
+
"Flavor",
|
|
54
|
+
"User",
|
|
55
|
+
"GPU",
|
|
56
|
+
"CPU",
|
|
57
|
+
"RAM",
|
|
58
|
+
"SSD",
|
|
59
|
+
"OSImage",
|
|
60
|
+
"UsageAct",
|
|
61
|
+
"DebtInfo",
|
|
62
|
+
"Promocode",
|
|
63
|
+
"WhiteIP",
|
|
64
|
+
"PhysicalServer",
|
|
65
|
+
"SoftwareAddonInstance",
|
|
66
|
+
# Constants
|
|
67
|
+
"ServerStatusEnum",
|
|
68
|
+
"ServerState",
|
|
69
|
+
"PricePlan",
|
|
70
|
+
"BillingPeriod",
|
|
71
|
+
# Exceptions
|
|
72
|
+
"IntelionCloudError",
|
|
73
|
+
"APIError",
|
|
74
|
+
"AuthenticationError",
|
|
75
|
+
"ForbiddenError",
|
|
76
|
+
"NotFoundError",
|
|
77
|
+
"ConflictError",
|
|
78
|
+
"RateLimitError",
|
|
79
|
+
"ValidationError",
|
|
80
|
+
"ServerError",
|
|
81
|
+
"ConnectionError",
|
|
82
|
+
]
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Main client classes: IntelionCloud (sync) and AsyncIntelionCloud (async)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from .constants import DEFAULT_BASE_URL, DEFAULT_CONNECT_TIMEOUT, DEFAULT_TIMEOUT
|
|
8
|
+
from ._transport import AsyncTransport, SyncTransport
|
|
9
|
+
from .resources.cloud_servers import AsyncCloudServers, CloudServers
|
|
10
|
+
from .resources.flavors import AsyncFlavors, Flavors
|
|
11
|
+
from .resources.os_images import AsyncOSImages, OSImages
|
|
12
|
+
from .resources.users import AsyncUsers, Users
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class IntelionCloud:
|
|
16
|
+
"""Synchronous client for the Intelion Cloud API.
|
|
17
|
+
|
|
18
|
+
Usage::
|
|
19
|
+
|
|
20
|
+
client = IntelionCloud(token="your_api_token")
|
|
21
|
+
servers = client.cloud_servers.list()
|
|
22
|
+
client.close()
|
|
23
|
+
|
|
24
|
+
Or as a context manager::
|
|
25
|
+
|
|
26
|
+
with IntelionCloud(token="your_api_token") as client:
|
|
27
|
+
servers = client.cloud_servers.list()
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
token: API authentication token (``Authorization: Token <token>``).
|
|
31
|
+
base_url: Base URL of the Intelion Cloud instance.
|
|
32
|
+
timeout: Overall request timeout in seconds.
|
|
33
|
+
connect_timeout: Connection establishment timeout in seconds.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
token: str,
|
|
39
|
+
*,
|
|
40
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
41
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
42
|
+
connect_timeout: float = DEFAULT_CONNECT_TIMEOUT,
|
|
43
|
+
) -> None:
|
|
44
|
+
self._transport = SyncTransport(
|
|
45
|
+
token=token,
|
|
46
|
+
base_url=base_url,
|
|
47
|
+
timeout=timeout,
|
|
48
|
+
connect_timeout=connect_timeout,
|
|
49
|
+
)
|
|
50
|
+
self.cloud_servers = CloudServers(self._transport)
|
|
51
|
+
self.flavors = Flavors(self._transport)
|
|
52
|
+
self.os_images = OSImages(self._transport)
|
|
53
|
+
self.users = Users(self._transport)
|
|
54
|
+
|
|
55
|
+
def close(self) -> None:
|
|
56
|
+
"""Close the underlying HTTP connection pool."""
|
|
57
|
+
self._transport.close()
|
|
58
|
+
|
|
59
|
+
def __enter__(self) -> IntelionCloud:
|
|
60
|
+
return self
|
|
61
|
+
|
|
62
|
+
def __exit__(self, *args: object) -> None:
|
|
63
|
+
self.close()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class AsyncIntelionCloud:
|
|
67
|
+
"""Asynchronous client for the Intelion Cloud API.
|
|
68
|
+
|
|
69
|
+
Usage::
|
|
70
|
+
|
|
71
|
+
async with AsyncIntelionCloud(token="your_api_token") as client:
|
|
72
|
+
servers = await client.cloud_servers.list()
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
token: API authentication token (``Authorization: Token <token>``).
|
|
76
|
+
base_url: Base URL of the Intelion Cloud instance.
|
|
77
|
+
timeout: Overall request timeout in seconds.
|
|
78
|
+
connect_timeout: Connection establishment timeout in seconds.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
def __init__(
|
|
82
|
+
self,
|
|
83
|
+
token: str,
|
|
84
|
+
*,
|
|
85
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
86
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
87
|
+
connect_timeout: float = DEFAULT_CONNECT_TIMEOUT,
|
|
88
|
+
) -> None:
|
|
89
|
+
self._transport = AsyncTransport(
|
|
90
|
+
token=token,
|
|
91
|
+
base_url=base_url,
|
|
92
|
+
timeout=timeout,
|
|
93
|
+
connect_timeout=connect_timeout,
|
|
94
|
+
)
|
|
95
|
+
self.cloud_servers = AsyncCloudServers(self._transport)
|
|
96
|
+
self.flavors = AsyncFlavors(self._transport)
|
|
97
|
+
self.os_images = AsyncOSImages(self._transport)
|
|
98
|
+
self.users = AsyncUsers(self._transport)
|
|
99
|
+
|
|
100
|
+
async def close(self) -> None:
|
|
101
|
+
"""Close the underlying async HTTP connection pool."""
|
|
102
|
+
await self._transport.close()
|
|
103
|
+
|
|
104
|
+
async def __aenter__(self) -> AsyncIntelionCloud:
|
|
105
|
+
return self
|
|
106
|
+
|
|
107
|
+
async def __aexit__(self, *args: object) -> None:
|
|
108
|
+
await self.close()
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Pagination helpers for DRF paginated responses."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any, Dict, Generic, List, Optional, Tuple, TypeVar
|
|
7
|
+
from urllib.parse import parse_qs, urlparse
|
|
8
|
+
|
|
9
|
+
T = TypeVar("T")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class PaginatedResponse(Generic[T]):
|
|
14
|
+
"""A single page of results from the API."""
|
|
15
|
+
|
|
16
|
+
count: int
|
|
17
|
+
results: List[T]
|
|
18
|
+
next_url: Optional[str] = None
|
|
19
|
+
previous_url: Optional[str] = None
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def has_next(self) -> bool:
|
|
23
|
+
return self.next_url is not None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def parse_paginated(data: Dict[str, Any]) -> Dict[str, Any]:
|
|
27
|
+
"""Extract pagination metadata from a DRF response.
|
|
28
|
+
|
|
29
|
+
Returns dict with 'count', 'next', 'previous', 'results'.
|
|
30
|
+
If the response is not paginated (plain list), wraps it.
|
|
31
|
+
"""
|
|
32
|
+
if isinstance(data, list):
|
|
33
|
+
return {"count": len(data), "next": None, "previous": None, "results": data}
|
|
34
|
+
return {
|
|
35
|
+
"count": data.get("count", 0),
|
|
36
|
+
"next": data.get("next"),
|
|
37
|
+
"previous": data.get("previous"),
|
|
38
|
+
"results": data.get("results", []),
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def extract_next_page(url: Optional[str]) -> Optional[Tuple[str, Dict[str, str]]]:
|
|
43
|
+
"""Convert an absolute next/previous URL to (path, params) for the transport.
|
|
44
|
+
|
|
45
|
+
Returns None if URL is None, otherwise (relative_path, query_params).
|
|
46
|
+
|
|
47
|
+
Example:
|
|
48
|
+
'https://intelion.cloud/api/v2/flavors/?page=2'
|
|
49
|
+
-> ('flavors/', {'page': '2'})
|
|
50
|
+
"""
|
|
51
|
+
if url is None:
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
parsed = urlparse(url)
|
|
55
|
+
|
|
56
|
+
# Extract relative path after /api/v2/
|
|
57
|
+
path = parsed.path
|
|
58
|
+
marker = "/api/v2/"
|
|
59
|
+
idx = path.find(marker)
|
|
60
|
+
if idx >= 0:
|
|
61
|
+
path = path[idx + len(marker) :]
|
|
62
|
+
|
|
63
|
+
# Parse query string into flat dict (take first value of each key)
|
|
64
|
+
params = {k: v[0] for k, v in parse_qs(parsed.query).items()}
|
|
65
|
+
|
|
66
|
+
return path, params
|