|
1 | 1 | # Code generated by generate.go. DO NOT EDIT. |
2 | 2 |
|
3 | | -from contextlib import contextmanager |
4 | | -from connecpy.context import ClientContext |
| 3 | +import httpx |
5 | 4 |
|
6 | | -import metalstack.admin.v2.filesystem_connecpy as admin_filesystem_connecpy |
7 | | -import metalstack.admin.v2.image_connecpy as admin_image_connecpy |
8 | | -import metalstack.admin.v2.ip_connecpy as admin_ip_connecpy |
9 | | -import metalstack.admin.v2.network_connecpy as admin_network_connecpy |
10 | | -import metalstack.admin.v2.partition_connecpy as admin_partition_connecpy |
11 | | -import metalstack.admin.v2.size_connecpy as admin_size_connecpy |
12 | | -import metalstack.admin.v2.tenant_connecpy as admin_tenant_connecpy |
13 | | -import metalstack.admin.v2.token_connecpy as admin_token_connecpy |
14 | | - |
15 | | -import metalstack.api.v2.filesystem_connecpy as api_filesystem_connecpy |
16 | | -import metalstack.api.v2.health_connecpy as api_health_connecpy |
17 | | -import metalstack.api.v2.image_connecpy as api_image_connecpy |
18 | 5 | import metalstack.api.v2.ip_connecpy as api_ip_connecpy |
19 | | -import metalstack.api.v2.method_connecpy as api_method_connecpy |
20 | | -import metalstack.api.v2.network_connecpy as api_network_connecpy |
21 | | -import metalstack.api.v2.partition_connecpy as api_partition_connecpy |
22 | | -import metalstack.api.v2.project_connecpy as api_project_connecpy |
23 | | -import metalstack.api.v2.size_connecpy as api_size_connecpy |
24 | | -import metalstack.api.v2.tenant_connecpy as api_tenant_connecpy |
25 | | -import metalstack.api.v2.token_connecpy as api_token_connecpy |
26 | | -import metalstack.api.v2.user_connecpy as api_user_connecpy |
27 | | -import metalstack.api.v2.version_connecpy as api_version_connecpy |
28 | | - |
29 | | -import metalstack.infra.v2.bmc_connecpy as infra_bmc_connecpy |
30 | | - |
| 6 | +import metalstack.admin.v2.network_connecpy as api_network_connecpy |
31 | 7 |
|
32 | 8 |
|
33 | | -class Driver: |
| 9 | +class Client: |
34 | 10 | def __init__(self, baseurl: str, token: str, timeout: int = 10): |
35 | 11 | self.baseurl = baseurl |
36 | | - self.token = token |
37 | 12 | self.timeout = timeout |
38 | 13 |
|
39 | | - def adminv2(self): |
40 | | - return Adminv2(baseurl=self.baseurl, token=self.token, timeout=self.timeout) |
41 | | - |
42 | | - def apiv2(self): |
43 | | - return Apiv2(baseurl=self.baseurl, token=self.token, timeout=self.timeout) |
| 14 | + headers = {} |
| 15 | + if token: |
| 16 | + headers["Authorization"] = "Bearer " + token |
44 | 17 |
|
45 | | - def infrav2(self): |
46 | | - return Infrav2(baseurl=self.baseurl, token=self.token, timeout=self.timeout) |
| 18 | + self._session = httpx.Client(headers=headers, timeout=timeout) |
47 | 19 |
|
| 20 | + def apiv2(self): |
| 21 | + return _Apiv2(baseurl=self.baseurl, session=self._session) |
48 | 22 |
|
49 | | -class Adminv2: |
50 | | - def __init__(self, baseurl: str, token: str, timeout: int = 10): |
51 | | - self.baseurl = baseurl |
52 | | - self.token = token |
53 | | - self.timeout = timeout |
54 | | - |
| 23 | + def adminv2(self): |
| 24 | + return _Adminv2(baseurl=self.baseurl, session=self._session) |
55 | 25 |
|
56 | | - @contextmanager |
57 | | - def filesystem(self): |
58 | | - with admin_filesystem_connecpy.FilesystemServiceClient(self.baseurl, timeout=self.timeout) as client: |
59 | | - yield ClientWrapper(client, self.token) |
60 | 26 |
|
61 | | - @contextmanager |
62 | | - def image(self): |
63 | | - with admin_image_connecpy.ImageServiceClient(self.baseurl, timeout=self.timeout) as client: |
64 | | - yield ClientWrapper(client, self.token) |
| 27 | +class _Apiv2: |
| 28 | + def __init__(self, baseurl: str, session=None): |
| 29 | + self._baseurl = baseurl |
| 30 | + self._session = session |
65 | 31 |
|
66 | | - @contextmanager |
67 | 32 | def ip(self): |
68 | | - with admin_ip_connecpy.IPServiceClient(self.baseurl, timeout=self.timeout) as client: |
69 | | - yield ClientWrapper(client, self.token) |
70 | | - |
71 | | - @contextmanager |
72 | | - def network(self): |
73 | | - with admin_network_connecpy.NetworkServiceClient(self.baseurl, timeout=self.timeout) as client: |
74 | | - yield ClientWrapper(client, self.token) |
75 | | - |
76 | | - @contextmanager |
77 | | - def partition(self): |
78 | | - with admin_partition_connecpy.PartitionServiceClient(self.baseurl, timeout=self.timeout) as client: |
79 | | - yield ClientWrapper(client, self.token) |
80 | | - |
81 | | - @contextmanager |
82 | | - def size(self): |
83 | | - with admin_size_connecpy.SizeServiceClient(self.baseurl, timeout=self.timeout) as client: |
84 | | - yield ClientWrapper(client, self.token) |
85 | | - |
86 | | - @contextmanager |
87 | | - def tenant(self): |
88 | | - with admin_tenant_connecpy.TenantServiceClient(self.baseurl, timeout=self.timeout) as client: |
89 | | - yield ClientWrapper(client, self.token) |
90 | | - |
91 | | - @contextmanager |
92 | | - def token(self): |
93 | | - with admin_token_connecpy.TokenServiceClient(self.baseurl, timeout=self.timeout) as client: |
94 | | - yield ClientWrapper(client, self.token) |
95 | | - |
96 | | -class Apiv2: |
97 | | - def __init__(self, baseurl: str, token: str, timeout: int = 10): |
98 | | - self.baseurl = baseurl |
99 | | - self.token = token |
100 | | - self.timeout = timeout |
| 33 | + return api_ip_connecpy.IPServiceClient(self._baseurl, session=self._session) |
101 | 34 |
|
102 | 35 |
|
103 | | - @contextmanager |
104 | | - def filesystem(self): |
105 | | - with api_filesystem_connecpy.FilesystemServiceClient(self.baseurl, timeout=self.timeout) as client: |
106 | | - yield ClientWrapper(client, self.token) |
| 36 | +class _Adminv2: |
| 37 | + def __init__(self, baseurl: str, session=None): |
| 38 | + self._baseurl = baseurl |
| 39 | + self._session = session |
107 | 40 |
|
108 | | - @contextmanager |
109 | | - def health(self): |
110 | | - with api_health_connecpy.HealthServiceClient(self.baseurl, timeout=self.timeout) as client: |
111 | | - yield ClientWrapper(client, self.token) |
112 | | - |
113 | | - @contextmanager |
114 | | - def image(self): |
115 | | - with api_image_connecpy.ImageServiceClient(self.baseurl, timeout=self.timeout) as client: |
116 | | - yield ClientWrapper(client, self.token) |
117 | | - |
118 | | - @contextmanager |
119 | | - def ip(self): |
120 | | - with api_ip_connecpy.IPServiceClient(self.baseurl, timeout=self.timeout) as client: |
121 | | - yield ClientWrapper(client, self.token) |
122 | | - |
123 | | - @contextmanager |
124 | | - def method(self): |
125 | | - with api_method_connecpy.MethodServiceClient(self.baseurl, timeout=self.timeout) as client: |
126 | | - yield ClientWrapper(client, self.token) |
127 | | - |
128 | | - @contextmanager |
129 | 41 | def network(self): |
130 | | - with api_network_connecpy.NetworkServiceClient(self.baseurl, timeout=self.timeout) as client: |
131 | | - yield ClientWrapper(client, self.token) |
132 | | - |
133 | | - @contextmanager |
134 | | - def partition(self): |
135 | | - with api_partition_connecpy.PartitionServiceClient(self.baseurl, timeout=self.timeout) as client: |
136 | | - yield ClientWrapper(client, self.token) |
137 | | - |
138 | | - @contextmanager |
139 | | - def project(self): |
140 | | - with api_project_connecpy.ProjectServiceClient(self.baseurl, timeout=self.timeout) as client: |
141 | | - yield ClientWrapper(client, self.token) |
142 | | - |
143 | | - @contextmanager |
144 | | - def size(self): |
145 | | - with api_size_connecpy.SizeServiceClient(self.baseurl, timeout=self.timeout) as client: |
146 | | - yield ClientWrapper(client, self.token) |
147 | | - |
148 | | - @contextmanager |
149 | | - def tenant(self): |
150 | | - with api_tenant_connecpy.TenantServiceClient(self.baseurl, timeout=self.timeout) as client: |
151 | | - yield ClientWrapper(client, self.token) |
152 | | - |
153 | | - @contextmanager |
154 | | - def token(self): |
155 | | - with api_token_connecpy.TokenServiceClient(self.baseurl, timeout=self.timeout) as client: |
156 | | - yield ClientWrapper(client, self.token) |
157 | | - |
158 | | - @contextmanager |
159 | | - def user(self): |
160 | | - with api_user_connecpy.UserServiceClient(self.baseurl, timeout=self.timeout) as client: |
161 | | - yield ClientWrapper(client, self.token) |
162 | | - |
163 | | - @contextmanager |
164 | | - def version(self): |
165 | | - with api_version_connecpy.VersionServiceClient(self.baseurl, timeout=self.timeout) as client: |
166 | | - yield ClientWrapper(client, self.token) |
167 | | - |
168 | | -class Infrav2: |
169 | | - def __init__(self, baseurl: str, token: str, timeout: int = 10): |
170 | | - self.baseurl = baseurl |
171 | | - self.token = token |
172 | | - self.timeout = timeout |
173 | | - |
174 | | - |
175 | | - @contextmanager |
176 | | - def bmc(self): |
177 | | - with infra_bmc_connecpy.BMCServiceClient(self.baseurl, timeout=self.timeout) as client: |
178 | | - yield ClientWrapper(client, self.token) |
179 | | - |
180 | | - |
181 | | - |
182 | | -class ClientWrapper: |
183 | | - def __init__(self, client, token): |
184 | | - self._client = client |
185 | | - self._token = token |
186 | | - |
187 | | - def __getattr__(self, name): |
188 | | - attr = getattr(self._client, name) |
189 | | - if callable(attr): |
190 | | - def wrapper(*args, **kwargs): |
191 | | - kwargs.setdefault("ctx", ClientContext()) |
192 | | - headers = kwargs.get("headers", {}) |
193 | | - headers.setdefault("Authorization", "Bearer " + self._token) |
194 | | - kwargs["headers"] = headers |
195 | | - return attr(*args, **kwargs) |
196 | | - return wrapper |
197 | | - return attr |
| 42 | + return api_network_connecpy.NetworkServiceClient(self._baseurl, session=self._session) |
0 commit comments