stackit-serverbackup 0.0.1a0__py3-none-any.whl

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.
@@ -0,0 +1,112 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Server Backup Management API
5
+
6
+ API endpoints for Server Backup Operations on STACKIT Servers.
7
+
8
+ The version of the OpenAPI document: 1.0
9
+ Contact: support@stackit.de
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+
16
+ class HostConfiguration:
17
+ def __init__(
18
+ self,
19
+ region=None,
20
+ server_index=None,
21
+ server_variables=None,
22
+ server_operation_index=None,
23
+ server_operation_variables=None,
24
+ ignore_operation_servers=False,
25
+ ) -> None:
26
+ """Constructor"""
27
+ self._base_path = "https://server-backup.api.eu01.stackit.cloud"
28
+ """Default Base url
29
+ """
30
+ self.server_index = 0 if server_index is None else server_index
31
+ self.server_operation_index = server_operation_index or {}
32
+ """Default server index
33
+ """
34
+ self.server_variables = server_variables or {}
35
+ if region:
36
+ self.server_variables["region"] = "{}.".format(region)
37
+ self.server_operation_variables = server_operation_variables or {}
38
+ """Default server variables
39
+ """
40
+ self.ignore_operation_servers = ignore_operation_servers
41
+ """Ignore operation servers
42
+ """
43
+
44
+ def get_host_settings(self):
45
+ """Gets an array of host settings
46
+
47
+ :return: An array of host settings
48
+ """
49
+ return [
50
+ {
51
+ "url": "https://server-backup.api.{region}stackit.cloud",
52
+ "description": "No description provided",
53
+ "variables": {
54
+ "region": {
55
+ "description": "No description provided",
56
+ "default_value": "eu01.",
57
+ "enum_values": ["eu01."],
58
+ }
59
+ },
60
+ }
61
+ ]
62
+
63
+ def get_host_from_settings(self, index, variables=None, servers=None):
64
+ """Gets host URL based on the index and variables
65
+ :param index: array index of the host settings
66
+ :param variables: hash of variable and the corresponding value
67
+ :param servers: an array of host settings or None
68
+ :return: URL based on host settings
69
+ """
70
+ if index is None:
71
+ return self._base_path
72
+
73
+ variables = {} if variables is None else variables
74
+ servers = self.get_host_settings() if servers is None else servers
75
+
76
+ try:
77
+ server = servers[index]
78
+ except IndexError:
79
+ raise ValueError(
80
+ "Invalid index {0} when selecting the host settings. "
81
+ "Must be less than {1}".format(index, len(servers))
82
+ )
83
+
84
+ url = server["url"]
85
+
86
+ # go through variables and replace placeholders
87
+ for variable_name, variable in server.get("variables", {}).items():
88
+ used_value = variables.get(variable_name, variable["default_value"])
89
+
90
+ if "enum_values" in variable and used_value not in variable["enum_values"]:
91
+ given_value = variables[variable_name].replace(".", "")
92
+ valid_values = [v.replace(".", "") for v in variable["enum_values"]]
93
+ raise ValueError(
94
+ "The variable `{0}` in the host URL has invalid value '{1}'. Must be '{2}'.".format(
95
+ variable_name, given_value, valid_values
96
+ )
97
+ )
98
+
99
+ url = url.replace("{" + variable_name + "}", used_value)
100
+
101
+ return url
102
+
103
+ @property
104
+ def host(self):
105
+ """Return generated host."""
106
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
107
+
108
+ @host.setter
109
+ def host(self, value):
110
+ """Fix base path."""
111
+ self._base_path = value
112
+ self.server_index = None
@@ -0,0 +1,199 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Server Backup Management API
5
+
6
+ API endpoints for Server Backup Operations on STACKIT Servers.
7
+
8
+ The version of the OpenAPI document: 1.0
9
+ Contact: support@stackit.de
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ from typing import Any, Optional
16
+
17
+ from typing_extensions import Self
18
+
19
+
20
+ class OpenApiException(Exception):
21
+ """The base exception class for all OpenAPIExceptions"""
22
+
23
+
24
+ class ApiTypeError(OpenApiException, TypeError):
25
+ def __init__(self, msg, path_to_item=None, valid_classes=None, key_type=None) -> None:
26
+ """Raises an exception for TypeErrors
27
+
28
+ Args:
29
+ msg (str): the exception message
30
+
31
+ Keyword Args:
32
+ path_to_item (list): a list of keys an indices to get to the
33
+ current_item
34
+ None if unset
35
+ valid_classes (tuple): the primitive classes that current item
36
+ should be an instance of
37
+ None if unset
38
+ key_type (bool): False if our value is a value in a dict
39
+ True if it is a key in a dict
40
+ False if our item is an item in a list
41
+ None if unset
42
+ """
43
+ self.path_to_item = path_to_item
44
+ self.valid_classes = valid_classes
45
+ self.key_type = key_type
46
+ full_msg = msg
47
+ if path_to_item:
48
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
49
+ super(ApiTypeError, self).__init__(full_msg)
50
+
51
+
52
+ class ApiValueError(OpenApiException, ValueError):
53
+ def __init__(self, msg, path_to_item=None) -> None:
54
+ """
55
+ Args:
56
+ msg (str): the exception message
57
+
58
+ Keyword Args:
59
+ path_to_item (list) the path to the exception in the
60
+ received_data dict. None if unset
61
+ """
62
+
63
+ self.path_to_item = path_to_item
64
+ full_msg = msg
65
+ if path_to_item:
66
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
67
+ super(ApiValueError, self).__init__(full_msg)
68
+
69
+
70
+ class ApiAttributeError(OpenApiException, AttributeError):
71
+ def __init__(self, msg, path_to_item=None) -> None:
72
+ """
73
+ Raised when an attribute reference or assignment fails.
74
+
75
+ Args:
76
+ msg (str): the exception message
77
+
78
+ Keyword Args:
79
+ path_to_item (None/list) the path to the exception in the
80
+ received_data dict
81
+ """
82
+ self.path_to_item = path_to_item
83
+ full_msg = msg
84
+ if path_to_item:
85
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
86
+ super(ApiAttributeError, self).__init__(full_msg)
87
+
88
+
89
+ class ApiKeyError(OpenApiException, KeyError):
90
+ def __init__(self, msg, path_to_item=None) -> None:
91
+ """
92
+ Args:
93
+ msg (str): the exception message
94
+
95
+ Keyword Args:
96
+ path_to_item (None/list) the path to the exception in the
97
+ received_data dict
98
+ """
99
+ self.path_to_item = path_to_item
100
+ full_msg = msg
101
+ if path_to_item:
102
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
103
+ super(ApiKeyError, self).__init__(full_msg)
104
+
105
+
106
+ class ApiException(OpenApiException):
107
+
108
+ def __init__(
109
+ self,
110
+ status=None,
111
+ reason=None,
112
+ http_resp=None,
113
+ *,
114
+ body: Optional[str] = None,
115
+ data: Optional[Any] = None,
116
+ ) -> None:
117
+ self.status = status
118
+ self.reason = reason
119
+ self.body = body
120
+ self.data = data
121
+ self.headers = None
122
+
123
+ if http_resp:
124
+ if self.status is None:
125
+ self.status = http_resp.status
126
+ if self.reason is None:
127
+ self.reason = http_resp.reason
128
+ if self.body is None:
129
+ try:
130
+ self.body = http_resp.data.decode("utf-8")
131
+ except Exception: # noqa: S110
132
+ pass
133
+ self.headers = http_resp.getheaders()
134
+
135
+ @classmethod
136
+ def from_response(
137
+ cls,
138
+ *,
139
+ http_resp,
140
+ body: Optional[str],
141
+ data: Optional[Any],
142
+ ) -> Self:
143
+ if http_resp.status == 400:
144
+ raise BadRequestException(http_resp=http_resp, body=body, data=data)
145
+
146
+ if http_resp.status == 401:
147
+ raise UnauthorizedException(http_resp=http_resp, body=body, data=data)
148
+
149
+ if http_resp.status == 403:
150
+ raise ForbiddenException(http_resp=http_resp, body=body, data=data)
151
+
152
+ if http_resp.status == 404:
153
+ raise NotFoundException(http_resp=http_resp, body=body, data=data)
154
+
155
+ if 500 <= http_resp.status <= 599:
156
+ raise ServiceException(http_resp=http_resp, body=body, data=data)
157
+ raise ApiException(http_resp=http_resp, body=body, data=data)
158
+
159
+ def __str__(self):
160
+ """Custom error messages for exception"""
161
+ error_message = "({0})\n" "Reason: {1}\n".format(self.status, self.reason)
162
+ if self.headers:
163
+ error_message += "HTTP response headers: {0}\n".format(self.headers)
164
+
165
+ if self.data or self.body:
166
+ error_message += "HTTP response body: {0}\n".format(self.data or self.body)
167
+
168
+ return error_message
169
+
170
+
171
+ class BadRequestException(ApiException):
172
+ pass
173
+
174
+
175
+ class NotFoundException(ApiException):
176
+ pass
177
+
178
+
179
+ class UnauthorizedException(ApiException):
180
+ pass
181
+
182
+
183
+ class ForbiddenException(ApiException):
184
+ pass
185
+
186
+
187
+ class ServiceException(ApiException):
188
+ pass
189
+
190
+
191
+ def render_path(path_to_item):
192
+ """Returns a string representation of a path"""
193
+ result = ""
194
+ for pth in path_to_item:
195
+ if isinstance(pth, int):
196
+ result += "[{0}]".format(pth)
197
+ else:
198
+ result += "['{0}']".format(pth)
199
+ return result
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+
3
+ # flake8: noqa
4
+ """
5
+ STACKIT Server Backup Management API
6
+
7
+ API endpoints for Server Backup Operations on STACKIT Servers.
8
+
9
+ The version of the OpenAPI document: 1.0
10
+ Contact: support@stackit.de
11
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
12
+
13
+ Do not edit the class manually.
14
+ """ # noqa: E501 docstring might be too long
15
+
16
+
17
+ # import models into model package
18
+ from stackit.serverbackup.models.backup import Backup
19
+ from stackit.serverbackup.models.backup_job import BackupJob
20
+ from stackit.serverbackup.models.backup_properties import BackupProperties
21
+ from stackit.serverbackup.models.backup_schedule import BackupSchedule
22
+ from stackit.serverbackup.models.backup_volume_backups_inner import (
23
+ BackupVolumeBackupsInner,
24
+ )
25
+ from stackit.serverbackup.models.create_backup_payload import CreateBackupPayload
26
+ from stackit.serverbackup.models.create_backup_schedule_payload import (
27
+ CreateBackupSchedulePayload,
28
+ )
29
+ from stackit.serverbackup.models.enable_service_payload import EnableServicePayload
30
+ from stackit.serverbackup.models.enable_service_resource_payload import (
31
+ EnableServiceResourcePayload,
32
+ )
33
+ from stackit.serverbackup.models.get_backup_schedules_response import (
34
+ GetBackupSchedulesResponse,
35
+ )
36
+ from stackit.serverbackup.models.get_backups_list_response import GetBackupsListResponse
37
+ from stackit.serverbackup.models.restore_backup_payload import RestoreBackupPayload
38
+ from stackit.serverbackup.models.restore_volume_backup_payload import (
39
+ RestoreVolumeBackupPayload,
40
+ )
41
+ from stackit.serverbackup.models.update_backup_schedule_payload import (
42
+ UpdateBackupSchedulePayload,
43
+ )
@@ -0,0 +1,145 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Server Backup Management API
5
+
6
+ API endpoints for Server Backup Operations on STACKIT Servers.
7
+
8
+ The version of the OpenAPI document: 1.0
9
+ Contact: support@stackit.de
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
22
+ from typing_extensions import Self
23
+
24
+ from stackit.serverbackup.models.backup_volume_backups_inner import (
25
+ BackupVolumeBackupsInner,
26
+ )
27
+
28
+
29
+ class Backup(BaseModel):
30
+ """
31
+ Backup
32
+ """
33
+
34
+ created_at: StrictStr = Field(alias="createdAt")
35
+ expire_at: StrictStr = Field(alias="expireAt")
36
+ id: StrictStr
37
+ last_restored_at: Optional[StrictStr] = Field(default=None, alias="lastRestoredAt")
38
+ name: StrictStr
39
+ size: Optional[StrictInt] = None
40
+ status: StrictStr
41
+ volume_backups: Optional[List[BackupVolumeBackupsInner]] = Field(default=None, alias="volumeBackups")
42
+ __properties: ClassVar[List[str]] = [
43
+ "createdAt",
44
+ "expireAt",
45
+ "id",
46
+ "lastRestoredAt",
47
+ "name",
48
+ "size",
49
+ "status",
50
+ "volumeBackups",
51
+ ]
52
+
53
+ @field_validator("status")
54
+ def status_validate_enum(cls, value):
55
+ """Validates the enum"""
56
+ if value not in set(
57
+ [
58
+ "creating",
59
+ "available",
60
+ "deleting",
61
+ "error",
62
+ "restoring",
63
+ "error_deleting",
64
+ "backing up",
65
+ "inconsistent",
66
+ "error-creating",
67
+ ]
68
+ ):
69
+ raise ValueError(
70
+ "must be one of enum values ('creating', 'available', 'deleting', 'error', 'restoring', 'error_deleting', 'backing up', 'inconsistent', 'error-creating')"
71
+ )
72
+ return value
73
+
74
+ model_config = ConfigDict(
75
+ populate_by_name=True,
76
+ validate_assignment=True,
77
+ protected_namespaces=(),
78
+ )
79
+
80
+ def to_str(self) -> str:
81
+ """Returns the string representation of the model using alias"""
82
+ return pprint.pformat(self.model_dump(by_alias=True))
83
+
84
+ def to_json(self) -> str:
85
+ """Returns the JSON representation of the model using alias"""
86
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
87
+ return json.dumps(self.to_dict())
88
+
89
+ @classmethod
90
+ def from_json(cls, json_str: str) -> Optional[Self]:
91
+ """Create an instance of Backup from a JSON string"""
92
+ return cls.from_dict(json.loads(json_str))
93
+
94
+ def to_dict(self) -> Dict[str, Any]:
95
+ """Return the dictionary representation of the model using alias.
96
+
97
+ This has the following differences from calling pydantic's
98
+ `self.model_dump(by_alias=True)`:
99
+
100
+ * `None` is only added to the output dict for nullable fields that
101
+ were set at model initialization. Other fields with value `None`
102
+ are ignored.
103
+ """
104
+ excluded_fields: Set[str] = set([])
105
+
106
+ _dict = self.model_dump(
107
+ by_alias=True,
108
+ exclude=excluded_fields,
109
+ exclude_none=True,
110
+ )
111
+ # override the default output from pydantic by calling `to_dict()` of each item in volume_backups (list)
112
+ _items = []
113
+ if self.volume_backups:
114
+ for _item in self.volume_backups:
115
+ if _item:
116
+ _items.append(_item.to_dict())
117
+ _dict["volumeBackups"] = _items
118
+ return _dict
119
+
120
+ @classmethod
121
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
122
+ """Create an instance of Backup from a dict"""
123
+ if obj is None:
124
+ return None
125
+
126
+ if not isinstance(obj, dict):
127
+ return cls.model_validate(obj)
128
+
129
+ _obj = cls.model_validate(
130
+ {
131
+ "createdAt": obj.get("createdAt"),
132
+ "expireAt": obj.get("expireAt"),
133
+ "id": obj.get("id"),
134
+ "lastRestoredAt": obj.get("lastRestoredAt"),
135
+ "name": obj.get("name"),
136
+ "size": obj.get("size"),
137
+ "status": obj.get("status"),
138
+ "volumeBackups": (
139
+ [BackupVolumeBackupsInner.from_dict(_item) for _item in obj["volumeBackups"]]
140
+ if obj.get("volumeBackups") is not None
141
+ else None
142
+ ),
143
+ }
144
+ )
145
+ return _obj
@@ -0,0 +1,82 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Server Backup Management API
5
+
6
+ API endpoints for Server Backup Operations on STACKIT Servers.
7
+
8
+ The version of the OpenAPI document: 1.0
9
+ Contact: support@stackit.de
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, StrictStr
22
+ from typing_extensions import Self
23
+
24
+
25
+ class BackupJob(BaseModel):
26
+ """
27
+ BackupJob
28
+ """
29
+
30
+ id: StrictStr
31
+ __properties: ClassVar[List[str]] = ["id"]
32
+
33
+ model_config = ConfigDict(
34
+ populate_by_name=True,
35
+ validate_assignment=True,
36
+ protected_namespaces=(),
37
+ )
38
+
39
+ def to_str(self) -> str:
40
+ """Returns the string representation of the model using alias"""
41
+ return pprint.pformat(self.model_dump(by_alias=True))
42
+
43
+ def to_json(self) -> str:
44
+ """Returns the JSON representation of the model using alias"""
45
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
46
+ return json.dumps(self.to_dict())
47
+
48
+ @classmethod
49
+ def from_json(cls, json_str: str) -> Optional[Self]:
50
+ """Create an instance of BackupJob from a JSON string"""
51
+ return cls.from_dict(json.loads(json_str))
52
+
53
+ def to_dict(self) -> Dict[str, Any]:
54
+ """Return the dictionary representation of the model using alias.
55
+
56
+ This has the following differences from calling pydantic's
57
+ `self.model_dump(by_alias=True)`:
58
+
59
+ * `None` is only added to the output dict for nullable fields that
60
+ were set at model initialization. Other fields with value `None`
61
+ are ignored.
62
+ """
63
+ excluded_fields: Set[str] = set([])
64
+
65
+ _dict = self.model_dump(
66
+ by_alias=True,
67
+ exclude=excluded_fields,
68
+ exclude_none=True,
69
+ )
70
+ return _dict
71
+
72
+ @classmethod
73
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
74
+ """Create an instance of BackupJob from a dict"""
75
+ if obj is None:
76
+ return None
77
+
78
+ if not isinstance(obj, dict):
79
+ return cls.model_validate(obj)
80
+
81
+ _obj = cls.model_validate({"id": obj.get("id")})
82
+ return _obj
@@ -0,0 +1,88 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Server Backup Management API
5
+
6
+ API endpoints for Server Backup Operations on STACKIT Servers.
7
+
8
+ The version of the OpenAPI document: 1.0
9
+ Contact: support@stackit.de
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
22
+ from typing_extensions import Annotated, Self
23
+
24
+
25
+ class BackupProperties(BaseModel):
26
+ """
27
+ BackupProperties
28
+ """
29
+
30
+ name: StrictStr = Field(description="Max 255 characters")
31
+ retention_period: Annotated[int, Field(le=36500, strict=True, ge=1)] = Field(
32
+ description="Values are set in days (1-36500)", alias="retentionPeriod"
33
+ )
34
+ volume_ids: Optional[List[StrictStr]] = Field(default=None, alias="volumeIds")
35
+ __properties: ClassVar[List[str]] = ["name", "retentionPeriod", "volumeIds"]
36
+
37
+ model_config = ConfigDict(
38
+ populate_by_name=True,
39
+ validate_assignment=True,
40
+ protected_namespaces=(),
41
+ )
42
+
43
+ def to_str(self) -> str:
44
+ """Returns the string representation of the model using alias"""
45
+ return pprint.pformat(self.model_dump(by_alias=True))
46
+
47
+ def to_json(self) -> str:
48
+ """Returns the JSON representation of the model using alias"""
49
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
50
+ return json.dumps(self.to_dict())
51
+
52
+ @classmethod
53
+ def from_json(cls, json_str: str) -> Optional[Self]:
54
+ """Create an instance of BackupProperties from a JSON string"""
55
+ return cls.from_dict(json.loads(json_str))
56
+
57
+ def to_dict(self) -> Dict[str, Any]:
58
+ """Return the dictionary representation of the model using alias.
59
+
60
+ This has the following differences from calling pydantic's
61
+ `self.model_dump(by_alias=True)`:
62
+
63
+ * `None` is only added to the output dict for nullable fields that
64
+ were set at model initialization. Other fields with value `None`
65
+ are ignored.
66
+ """
67
+ excluded_fields: Set[str] = set([])
68
+
69
+ _dict = self.model_dump(
70
+ by_alias=True,
71
+ exclude=excluded_fields,
72
+ exclude_none=True,
73
+ )
74
+ return _dict
75
+
76
+ @classmethod
77
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
78
+ """Create an instance of BackupProperties from a dict"""
79
+ if obj is None:
80
+ return None
81
+
82
+ if not isinstance(obj, dict):
83
+ return cls.model_validate(obj)
84
+
85
+ _obj = cls.model_validate(
86
+ {"name": obj.get("name"), "retentionPeriod": obj.get("retentionPeriod"), "volumeIds": obj.get("volumeIds")}
87
+ )
88
+ return _obj