stackit-automation 0.1.0__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.
Files changed (52) hide show
  1. stackit/automation/__init__.py +187 -0
  2. stackit/automation/api/__init__.py +4 -0
  3. stackit/automation/api/default_api.py +2971 -0
  4. stackit/automation/api_client.py +650 -0
  5. stackit/automation/api_response.py +22 -0
  6. stackit/automation/configuration.py +163 -0
  7. stackit/automation/exceptions.py +218 -0
  8. stackit/automation/models/__init__.py +73 -0
  9. stackit/automation/models/automation_schedule_trigger.py +85 -0
  10. stackit/automation/models/automation_triggers.py +101 -0
  11. stackit/automation/models/create_snapshots_result.py +85 -0
  12. stackit/automation/models/create_volume_automation_payload.py +125 -0
  13. stackit/automation/models/error_info_detail.py +93 -0
  14. stackit/automation/models/error_response.py +90 -0
  15. stackit/automation/models/error_response_content.py +108 -0
  16. stackit/automation/models/error_response_content_details.py +99 -0
  17. stackit/automation/models/event_create_response.py +83 -0
  18. stackit/automation/models/get_volume_ids_result.py +85 -0
  19. stackit/automation/models/get_volume_template_response.py +125 -0
  20. stackit/automation/models/help_error_detail.py +87 -0
  21. stackit/automation/models/list_automations_item.py +146 -0
  22. stackit/automation/models/list_automations_response.py +106 -0
  23. stackit/automation/models/list_executions_item.py +129 -0
  24. stackit/automation/models/list_executions_response.py +106 -0
  25. stackit/automation/models/list_templates_response.py +104 -0
  26. stackit/automation/models/localized_message_error_detail.py +87 -0
  27. stackit/automation/models/partial_update_volume_automation_payload.py +122 -0
  28. stackit/automation/models/schedule.py +84 -0
  29. stackit/automation/models/schedule_details.py +87 -0
  30. stackit/automation/models/schedule_patch_request.py +87 -0
  31. stackit/automation/models/schedule_request.py +87 -0
  32. stackit/automation/models/snapshot_retention_policy.py +99 -0
  33. stackit/automation/models/template.py +108 -0
  34. stackit/automation/models/volume_automation.py +165 -0
  35. stackit/automation/models/volume_automation_input.py +99 -0
  36. stackit/automation/models/volume_execution_automation.py +162 -0
  37. stackit/automation/models/volume_execution_details.py +100 -0
  38. stackit/automation/models/volume_execution_output.py +102 -0
  39. stackit/automation/models/volume_execution_output_step.py +105 -0
  40. stackit/automation/models/volume_execution_response.py +138 -0
  41. stackit/automation/models/volume_output.py +100 -0
  42. stackit/automation/models/volume_output_step.py +94 -0
  43. stackit/automation/models/volume_output_step_result.py +99 -0
  44. stackit/automation/models/volume_recovery_point_management_input.py +118 -0
  45. stackit/automation/models/volume_template_automation_input.py +90 -0
  46. stackit/automation/py.typed +0 -0
  47. stackit/automation/rest.py +164 -0
  48. stackit_automation-0.1.0.dist-info/METADATA +46 -0
  49. stackit_automation-0.1.0.dist-info/RECORD +52 -0
  50. stackit_automation-0.1.0.dist-info/WHEEL +4 -0
  51. stackit_automation-0.1.0.dist-info/licenses/LICENSE.md +201 -0
  52. stackit_automation-0.1.0.dist-info/licenses/NOTICE.txt +2 -0
@@ -0,0 +1,163 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Automation Service API
5
+
6
+ API endpoints for automation management .
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
14
+
15
+ import sys
16
+ from typing import Dict, List, Optional, TypedDict
17
+
18
+ from typing_extensions import NotRequired
19
+
20
+ import os
21
+
22
+ ServerVariablesT = Dict[str, str]
23
+
24
+
25
+ class HostSettingVariable(TypedDict):
26
+ description: str
27
+ default_value: str
28
+ enum_values: List[str]
29
+
30
+
31
+ class HostSetting(TypedDict):
32
+ url: str
33
+ description: str
34
+ variables: NotRequired[Dict[str, HostSettingVariable]]
35
+
36
+
37
+ class HostConfiguration:
38
+ def __init__(
39
+ self,
40
+ region=None,
41
+ server_index=None,
42
+ server_variables=None,
43
+ server_operation_index=None,
44
+ server_operation_variables=None,
45
+ ignore_operation_servers=False,
46
+ ) -> None:
47
+ print(
48
+ "WARNING: STACKIT will move to a new way of specifying regions, where the region is provided\n",
49
+ "as a function argument instead of being set in the client configuration.\n"
50
+ "Once all services have migrated, the methods to specify the region in the client configuration "
51
+ "will be removed.",
52
+ file=sys.stderr,
53
+ )
54
+ """Constructor
55
+ """
56
+ self._base_path = "https://automation-service.api.stackit.cloud"
57
+ """Default Base url
58
+ """
59
+ self.server_index = 0 if server_index is None else server_index
60
+ self.server_operation_index = server_operation_index or {}
61
+ """Default server index
62
+ """
63
+ self.server_variables = server_variables or {}
64
+ if region:
65
+ self.server_variables["region"] = "{}.".format(region)
66
+ self.server_operation_variables = server_operation_variables or {}
67
+ """Default server variables
68
+ """
69
+ self.ignore_operation_servers = ignore_operation_servers
70
+ """Ignore operation servers
71
+ """
72
+
73
+ def get_host_settings(self) -> List[HostSetting]:
74
+ """Gets an array of host settings
75
+
76
+ :return: An array of host settings
77
+ """
78
+ return [
79
+ {
80
+ "url": "https://automation-service.api.stackit.cloud",
81
+ "description": "No description provided",
82
+ "variables": {
83
+ "region": {
84
+ "description": "No description provided",
85
+ "default_value": "global",
86
+ }
87
+ },
88
+ }
89
+ ]
90
+
91
+ def get_host_from_settings(
92
+ self,
93
+ index: Optional[int],
94
+ variables: Optional[ServerVariablesT] = None,
95
+ servers: Optional[List[HostSetting]] = None,
96
+ ) -> str:
97
+ """Gets host URL based on the index and variables
98
+ :param index: array index of the host settings
99
+ :param variables: hash of variable and the corresponding value
100
+ :param servers: an array of host settings or None
101
+ :error: if a region is given for a global url
102
+ :return: URL based on host settings
103
+ """
104
+ if index is None:
105
+ return self._base_path
106
+
107
+ variables = {} if variables is None else variables
108
+ servers = self.get_host_settings() if servers is None else servers
109
+
110
+ try:
111
+ server = servers[index]
112
+ except IndexError:
113
+ raise ValueError(
114
+ "Invalid index {0} when selecting the host settings. "
115
+ "Must be less than {1}".format(index, len(servers))
116
+ )
117
+
118
+ url = server["url"]
119
+
120
+ # check if environment variable was provided for region
121
+ # if nothing was set this is None
122
+ region_env = os.environ.get("STACKIT_REGION")
123
+
124
+ # go through variables and replace placeholders
125
+ for variable_name, variable in server.get("variables", {}).items():
126
+ # If a region is provided by the user for a global url
127
+ # return an error (except for providing via environment variable).
128
+ # The region is provided as a function argument instead of being set in the client configuration.
129
+ if (
130
+ variable_name == "region"
131
+ and (variable["default_value"] == "global" or variable["default_value"] == "")
132
+ and region_env is None
133
+ and variables.get(variable_name) is not None
134
+ ):
135
+ raise ValueError(
136
+ "this API does not support setting a region in the client configuration, "
137
+ "please check if the region can be specified as a function parameter"
138
+ )
139
+ used_value = variables.get(variable_name, variable["default_value"])
140
+
141
+ if "enum_values" in variable and used_value not in variable["enum_values"]:
142
+ given_value = variables[variable_name].replace(".", "")
143
+ valid_values = [v.replace(".", "") for v in variable["enum_values"]]
144
+ raise ValueError(
145
+ "The variable `{0}` in the host URL has invalid value '{1}'. Must be '{2}'.".format(
146
+ variable_name, given_value, valid_values
147
+ )
148
+ )
149
+
150
+ url = url.replace("{" + variable_name + "}", used_value)
151
+
152
+ return url
153
+
154
+ @property
155
+ def host(self) -> str:
156
+ """Return generated host."""
157
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
158
+
159
+ @host.setter
160
+ def host(self, value: str) -> None:
161
+ """Fix base path."""
162
+ self._base_path = value
163
+ self.server_index = None
@@ -0,0 +1,218 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Automation Service API
5
+
6
+ API endpoints for automation management .
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
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.headers
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
+ # Added new conditions for 409 and 422
156
+ if http_resp.status == 409:
157
+ raise ConflictException(http_resp=http_resp, body=body, data=data)
158
+
159
+ if http_resp.status == 422:
160
+ raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data)
161
+
162
+ if 500 <= http_resp.status <= 599:
163
+ raise ServiceException(http_resp=http_resp, body=body, data=data)
164
+ raise ApiException(http_resp=http_resp, body=body, data=data)
165
+
166
+ def __str__(self):
167
+ """Custom error messages for exception"""
168
+ error_message = "({0})\n" "Reason: {1}\n".format(self.status, self.reason)
169
+ if self.headers:
170
+ error_message += "HTTP response headers: {0}\n".format(self.headers)
171
+
172
+ if self.data or self.body:
173
+ error_message += "HTTP response body: {0}\n".format(self.data or self.body)
174
+
175
+ return error_message
176
+
177
+
178
+ class BadRequestException(ApiException):
179
+ pass
180
+
181
+
182
+ class NotFoundException(ApiException):
183
+ pass
184
+
185
+
186
+ class UnauthorizedException(ApiException):
187
+ pass
188
+
189
+
190
+ class ForbiddenException(ApiException):
191
+ pass
192
+
193
+
194
+ class ServiceException(ApiException):
195
+ pass
196
+
197
+
198
+ class ConflictException(ApiException):
199
+ """Exception for HTTP 409 Conflict."""
200
+
201
+ pass
202
+
203
+
204
+ class UnprocessableEntityException(ApiException):
205
+ """Exception for HTTP 422 Unprocessable Entity."""
206
+
207
+ pass
208
+
209
+
210
+ def render_path(path_to_item):
211
+ """Returns a string representation of a path"""
212
+ result = ""
213
+ for pth in path_to_item:
214
+ if isinstance(pth, int):
215
+ result += "[{0}]".format(pth)
216
+ else:
217
+ result += "['{0}']".format(pth)
218
+ return result
@@ -0,0 +1,73 @@
1
+ # coding: utf-8
2
+
3
+ # flake8: noqa
4
+ """
5
+ STACKIT Automation Service API
6
+
7
+ API endpoints for automation management .
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
15
+
16
+ # import models into model package
17
+ from stackit.automation.models.automation_schedule_trigger import (
18
+ AutomationScheduleTrigger,
19
+ )
20
+ from stackit.automation.models.automation_triggers import AutomationTriggers
21
+ from stackit.automation.models.create_snapshots_result import CreateSnapshotsResult
22
+ from stackit.automation.models.create_volume_automation_payload import (
23
+ CreateVolumeAutomationPayload,
24
+ )
25
+ from stackit.automation.models.error_info_detail import ErrorInfoDetail
26
+ from stackit.automation.models.error_response import ErrorResponse
27
+ from stackit.automation.models.error_response_content import ErrorResponseContent
28
+ from stackit.automation.models.error_response_content_details import (
29
+ ErrorResponseContentDetails,
30
+ )
31
+ from stackit.automation.models.event_create_response import EventCreateResponse
32
+ from stackit.automation.models.get_volume_ids_result import GetVolumeIDsResult
33
+ from stackit.automation.models.get_volume_template_response import (
34
+ GetVolumeTemplateResponse,
35
+ )
36
+ from stackit.automation.models.help_error_detail import HelpErrorDetail
37
+ from stackit.automation.models.list_automations_item import ListAutomationsItem
38
+ from stackit.automation.models.list_automations_response import ListAutomationsResponse
39
+ from stackit.automation.models.list_executions_item import ListExecutionsItem
40
+ from stackit.automation.models.list_executions_response import ListExecutionsResponse
41
+ from stackit.automation.models.list_templates_response import ListTemplatesResponse
42
+ from stackit.automation.models.localized_message_error_detail import (
43
+ LocalizedMessageErrorDetail,
44
+ )
45
+ from stackit.automation.models.partial_update_volume_automation_payload import (
46
+ PartialUpdateVolumeAutomationPayload,
47
+ )
48
+ from stackit.automation.models.schedule import Schedule
49
+ from stackit.automation.models.schedule_details import ScheduleDetails
50
+ from stackit.automation.models.schedule_patch_request import SchedulePatchRequest
51
+ from stackit.automation.models.schedule_request import ScheduleRequest
52
+ from stackit.automation.models.snapshot_retention_policy import SnapshotRetentionPolicy
53
+ from stackit.automation.models.template import Template
54
+ from stackit.automation.models.volume_automation import VolumeAutomation
55
+ from stackit.automation.models.volume_automation_input import VolumeAutomationInput
56
+ from stackit.automation.models.volume_execution_automation import (
57
+ VolumeExecutionAutomation,
58
+ )
59
+ from stackit.automation.models.volume_execution_details import VolumeExecutionDetails
60
+ from stackit.automation.models.volume_execution_output import VolumeExecutionOutput
61
+ from stackit.automation.models.volume_execution_output_step import (
62
+ VolumeExecutionOutputStep,
63
+ )
64
+ from stackit.automation.models.volume_execution_response import VolumeExecutionResponse
65
+ from stackit.automation.models.volume_output import VolumeOutput
66
+ from stackit.automation.models.volume_output_step import VolumeOutputStep
67
+ from stackit.automation.models.volume_output_step_result import VolumeOutputStepResult
68
+ from stackit.automation.models.volume_recovery_point_management_input import (
69
+ VolumeRecoveryPointManagementInput,
70
+ )
71
+ from stackit.automation.models.volume_template_automation_input import (
72
+ VolumeTemplateAutomationInput,
73
+ )
@@ -0,0 +1,85 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Automation Service API
5
+
6
+ API endpoints for automation management .
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
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 pydantic_core import to_jsonable_python
23
+ from typing_extensions import Self
24
+
25
+
26
+ class AutomationScheduleTrigger(BaseModel):
27
+ """
28
+ AutomationScheduleTrigger
29
+ """ # noqa: E501
30
+
31
+ rrule: StrictStr = Field(
32
+ description="An rrule (Recurrence Rule) is a standardized string format used in iCalendar (RFC 5545) to define repeating events, and you can generate one by using a dedicated library or by using online generator tools to specify parameters like frequency, interval, and end dates"
33
+ )
34
+ __properties: ClassVar[List[str]] = ["rrule"]
35
+
36
+ model_config = ConfigDict(
37
+ validate_by_name=True,
38
+ validate_by_alias=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
+ return json.dumps(to_jsonable_python(self.to_dict()))
50
+
51
+ @classmethod
52
+ def from_json(cls, json_str: str) -> Optional[Self]:
53
+ """Create an instance of AutomationScheduleTrigger from a JSON string"""
54
+ return cls.from_dict(json.loads(json_str))
55
+
56
+ def to_dict(self) -> Dict[str, Any]:
57
+ """Return the dictionary representation of the model using alias.
58
+
59
+ This has the following differences from calling pydantic's
60
+ `self.model_dump(by_alias=True)`:
61
+
62
+ * `None` is only added to the output dict for nullable fields that
63
+ were set at model initialization. Other fields with value `None`
64
+ are ignored.
65
+ """
66
+ excluded_fields: Set[str] = set([])
67
+
68
+ _dict = self.model_dump(
69
+ by_alias=True,
70
+ exclude=excluded_fields,
71
+ exclude_none=True,
72
+ )
73
+ return _dict
74
+
75
+ @classmethod
76
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
77
+ """Create an instance of AutomationScheduleTrigger from a dict"""
78
+ if obj is None:
79
+ return None
80
+
81
+ if not isinstance(obj, dict):
82
+ return cls.model_validate(obj)
83
+
84
+ _obj = cls.model_validate({"rrule": obj.get("rrule")})
85
+ return _obj
@@ -0,0 +1,101 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Automation Service API
5
+
6
+ API endpoints for automation management .
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
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
22
+ from pydantic_core import to_jsonable_python
23
+ from typing_extensions import Self
24
+
25
+ from stackit.automation.models.automation_schedule_trigger import (
26
+ AutomationScheduleTrigger,
27
+ )
28
+
29
+
30
+ class AutomationTriggers(BaseModel):
31
+ """
32
+ AutomationTriggers
33
+ """ # noqa: E501
34
+
35
+ schedule: Optional[AutomationScheduleTrigger] = None
36
+ __properties: ClassVar[List[str]] = ["schedule"]
37
+
38
+ model_config = ConfigDict(
39
+ validate_by_name=True,
40
+ validate_by_alias=True,
41
+ validate_assignment=True,
42
+ protected_namespaces=(),
43
+ )
44
+
45
+ def to_str(self) -> str:
46
+ """Returns the string representation of the model using alias"""
47
+ return pprint.pformat(self.model_dump(by_alias=True))
48
+
49
+ def to_json(self) -> str:
50
+ """Returns the JSON representation of the model using alias"""
51
+ return json.dumps(to_jsonable_python(self.to_dict()))
52
+
53
+ @classmethod
54
+ def from_json(cls, json_str: str) -> Optional[Self]:
55
+ """Create an instance of AutomationTriggers from a JSON string"""
56
+ return cls.from_dict(json.loads(json_str))
57
+
58
+ def to_dict(self) -> Dict[str, Any]:
59
+ """Return the dictionary representation of the model using alias.
60
+
61
+ This has the following differences from calling pydantic's
62
+ `self.model_dump(by_alias=True)`:
63
+
64
+ * `None` is only added to the output dict for nullable fields that
65
+ were set at model initialization. Other fields with value `None`
66
+ are ignored.
67
+ """
68
+ excluded_fields: Set[str] = set([])
69
+
70
+ _dict = self.model_dump(
71
+ by_alias=True,
72
+ exclude=excluded_fields,
73
+ exclude_none=True,
74
+ )
75
+ # override the default output from pydantic by calling `to_dict()` of schedule
76
+ if self.schedule:
77
+ _dict["schedule"] = self.schedule.to_dict()
78
+ # set to None if schedule (nullable) is None
79
+ # and model_fields_set contains the field
80
+ if self.schedule is None and "schedule" in self.model_fields_set:
81
+ _dict["schedule"] = None
82
+
83
+ return _dict
84
+
85
+ @classmethod
86
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
87
+ """Create an instance of AutomationTriggers from a dict"""
88
+ if obj is None:
89
+ return None
90
+
91
+ if not isinstance(obj, dict):
92
+ return cls.model_validate(obj)
93
+
94
+ _obj = cls.model_validate(
95
+ {
96
+ "schedule": (
97
+ AutomationScheduleTrigger.from_dict(obj["schedule"]) if obj.get("schedule") is not None else None
98
+ )
99
+ }
100
+ )
101
+ return _obj