-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathdomain.py
More file actions
468 lines (394 loc) · 11.6 KB
/
domain.py
File metadata and controls
468 lines (394 loc) · 11.6 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
from __future__ import annotations
from typing import TYPE_CHECKING, Any, Literal
from ..actions import BoundAction
from ..core import BaseDomain, DomainIdentityMixin
from ..locations import BoundLocation, Location
from ..storage_box_types import BoundStorageBoxType, StorageBoxType
if TYPE_CHECKING:
from .client import (
BoundStorageBox,
BoundStorageBoxSnapshot,
BoundStorageBoxSubaccount,
)
StorageBoxStatus = Literal[
"active",
"initializing",
"locked",
]
class StorageBox(BaseDomain, DomainIdentityMixin):
"""
Storage Box Domain.
See https://docs.hetzner.cloud/reference/hetzner#storage-boxes.
"""
STATUS_ACTIVE = "active"
STATUS_INITIALIZING = "initializing"
STATUS_LOCKED = "locked"
__api_properties__ = (
"id",
"name",
"storage_box_type",
"location",
"system",
"server",
"username",
"labels",
"protection",
"snapshot_plan",
"access_settings",
"stats",
"status",
"created",
)
__slots__ = __api_properties__
def __init__(
self,
id: int | None = None,
name: str | None = None,
storage_box_type: BoundStorageBoxType | StorageBoxType | None = None,
location: BoundLocation | Location | None = None,
system: str | None = None,
server: str | None = None,
username: str | None = None,
labels: dict[str, str] | None = None,
protection: dict[str, bool] | None = None,
snapshot_plan: StorageBoxSnapshotPlan | None = None,
access_settings: StorageBoxAccessSettings | None = None,
stats: StorageBoxStats | None = None,
status: StorageBoxStatus | None = None,
created: str | None = None,
):
self.id = id
self.name = name
self.storage_box_type = storage_box_type
self.location = location
self.system = system
self.server = server
self.username = username
self.labels = labels
self.protection = protection
self.snapshot_plan = snapshot_plan
self.access_settings = access_settings
self.stats = stats
self.status = status
self.created = self._parse_datetime(created)
class StorageBoxAccessSettings(BaseDomain):
"""
Storage Box Access Settings Domain.
"""
__api_properties__ = (
"reachable_externally",
"samba_enabled",
"ssh_enabled",
"webdav_enabled",
"zfs_enabled",
)
__slots__ = __api_properties__
def __init__(
self,
reachable_externally: bool | None = None,
samba_enabled: bool | None = None,
ssh_enabled: bool | None = None,
webdav_enabled: bool | None = None,
zfs_enabled: bool | None = None,
):
self.reachable_externally = reachable_externally
self.samba_enabled = samba_enabled
self.ssh_enabled = ssh_enabled
self.webdav_enabled = webdav_enabled
self.zfs_enabled = zfs_enabled
def to_payload(self) -> dict[str, Any]:
"""
Generates the request payload from this domain object.
"""
payload: dict[str, Any] = {}
if self.reachable_externally is not None:
payload["reachable_externally"] = self.reachable_externally
if self.samba_enabled is not None:
payload["samba_enabled"] = self.samba_enabled
if self.ssh_enabled is not None:
payload["ssh_enabled"] = self.ssh_enabled
if self.webdav_enabled is not None:
payload["webdav_enabled"] = self.webdav_enabled
if self.zfs_enabled is not None:
payload["zfs_enabled"] = self.zfs_enabled
return payload
class StorageBoxStats(BaseDomain):
"""
Storage Box Stats Domain.
"""
__api_properties__ = (
"size",
"size_data",
"size_snapshots",
)
__slots__ = __api_properties__
def __init__(
self,
size: int | None = None,
size_data: int | None = None,
size_snapshots: int | None = None,
):
self.size = size
self.size_data = size_data
self.size_snapshots = size_snapshots
class StorageBoxSnapshotPlan(BaseDomain):
"""
Storage Box Snapshot Plan Domain.
"""
__api_properties__ = (
"max_snapshots",
"hour",
"minute",
"day_of_week",
"day_of_month",
)
__slots__ = __api_properties__
def __init__(
self,
max_snapshots: int,
hour: int,
minute: int,
day_of_week: int | None = None,
day_of_month: int | None = None,
):
self.max_snapshots = max_snapshots
self.hour = hour
self.minute = minute
self.day_of_week = day_of_week
self.day_of_month = day_of_month
def to_payload(self) -> dict[str, Any]:
"""
Generates the request payload from this domain object.
"""
payload: dict[str, Any] = {
"max_snapshots": self.max_snapshots,
"hour": self.hour,
"minute": self.minute,
"day_of_week": self.day_of_week, # API default is null
"day_of_month": self.day_of_month, # API default is null
}
return payload
class CreateStorageBoxResponse(BaseDomain):
"""
Create Storage Box Response Domain.
"""
__api_properties__ = (
"storage_box",
"action",
)
__slots__ = __api_properties__
def __init__(
self,
storage_box: BoundStorageBox,
action: BoundAction,
):
self.storage_box = storage_box
self.action = action
class DeleteStorageBoxResponse(BaseDomain):
"""
Delete Storage Box Response Domain.
"""
__api_properties__ = ("action",)
__slots__ = __api_properties__
def __init__(
self,
action: BoundAction,
):
self.action = action
class StorageBoxFoldersResponse(BaseDomain):
"""
Storage Box Folders Response Domain.
"""
__api_properties__ = ("folders",)
__slots__ = __api_properties__
def __init__(
self,
folders: list[str],
):
self.folders = folders
# Snapshots
###############################################################################
class StorageBoxSnapshot(BaseDomain, DomainIdentityMixin):
"""
Storage Box Snapshot Domain.
"""
__api_properties__ = (
"id",
"name",
"description",
"is_automatic",
"labels",
"storage_box",
"created",
"stats",
)
__slots__ = __api_properties__
def __init__(
self,
id: int | None = None,
name: str | None = None,
description: str | None = None,
is_automatic: bool | None = None,
labels: dict[str, str] | None = None,
storage_box: BoundStorageBox | StorageBox | None = None,
created: str | None = None,
stats: StorageBoxSnapshotStats | None = None,
):
self.id = id
self.name = name
self.description = description
self.is_automatic = is_automatic
self.labels = labels
self.storage_box = storage_box
self.created = self._parse_datetime(created)
self.stats = stats
class StorageBoxSnapshotStats(BaseDomain):
"""
Storage Box Snapshot Stats Domain.
"""
__api_properties__ = (
"size",
"size_filesystem",
)
__slots__ = __api_properties__
def __init__(
self,
size: int,
size_filesystem: int,
):
self.size = size
self.size_filesystem = size_filesystem
class CreateStorageBoxSnapshotResponse(BaseDomain):
"""
Create Storage Box Snapshot Response Domain.
"""
__api_properties__ = (
"snapshot",
"action",
)
__slots__ = __api_properties__
def __init__(
self,
snapshot: BoundStorageBoxSnapshot,
action: BoundAction,
):
self.snapshot = snapshot
self.action = action
class DeleteStorageBoxSnapshotResponse(BaseDomain):
"""
Delete Storage Box Snapshot Response Domain.
"""
__api_properties__ = ("action",)
__slots__ = __api_properties__
def __init__(
self,
action: BoundAction,
):
self.action = action
# Subaccounts
###############################################################################
class StorageBoxSubaccount(BaseDomain, DomainIdentityMixin):
"""
Storage Box Subaccount Domain.
"""
__api_properties__ = (
"id",
"username",
"description",
"server",
"home_directory",
"access_settings",
"labels",
"storage_box",
"created",
)
__slots__ = __api_properties__
def __init__(
self,
id: int | None = None,
username: str | None = None,
description: str | None = None,
server: str | None = None,
home_directory: str | None = None,
access_settings: StorageBoxSubaccountAccessSettings | None = None,
labels: dict[str, str] | None = None,
storage_box: BoundStorageBox | StorageBox | None = None,
created: str | None = None,
):
self.id = id
self.username = username
self.description = description
self.server = server
self.home_directory = home_directory
self.access_settings = access_settings
self.labels = labels
self.storage_box = storage_box
self.created = self._parse_datetime(created)
class StorageBoxSubaccountAccessSettings(BaseDomain):
"""
Storage Box Subaccount Access Settings Domain.
"""
__api_properties__ = (
"reachable_externally",
"samba_enabled",
"ssh_enabled",
"webdav_enabled",
"readonly",
)
__slots__ = __api_properties__
def __init__(
self,
reachable_externally: bool | None = None,
samba_enabled: bool | None = None,
ssh_enabled: bool | None = None,
webdav_enabled: bool | None = None,
readonly: bool | None = None,
):
self.reachable_externally = reachable_externally
self.samba_enabled = samba_enabled
self.ssh_enabled = ssh_enabled
self.webdav_enabled = webdav_enabled
self.readonly = readonly
def to_payload(self) -> dict[str, Any]:
"""
Generates the request payload from this domain object.
"""
payload: dict[str, Any] = {}
if self.reachable_externally is not None:
payload["reachable_externally"] = self.reachable_externally
if self.samba_enabled is not None:
payload["samba_enabled"] = self.samba_enabled
if self.ssh_enabled is not None:
payload["ssh_enabled"] = self.ssh_enabled
if self.webdav_enabled is not None:
payload["webdav_enabled"] = self.webdav_enabled
if self.readonly is not None:
payload["readonly"] = self.readonly
return payload
class CreateStorageBoxSubaccountResponse(BaseDomain):
"""
Create Storage Box Subaccount Response Domain.
"""
__api_properties__ = (
"subaccount",
"action",
)
__slots__ = __api_properties__
def __init__(
self,
subaccount: BoundStorageBoxSubaccount,
action: BoundAction,
):
self.subaccount = subaccount
self.action = action
class DeleteStorageBoxSubaccountResponse(BaseDomain):
"""
Delete Storage Box Subaccount Response Domain.
"""
__api_properties__ = ("action",)
__slots__ = __api_properties__
def __init__(
self,
action: BoundAction,
):
self.action = action