-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathload_balancer.py
More file actions
286 lines (260 loc) · 13.1 KB
/
load_balancer.py
File metadata and controls
286 lines (260 loc) · 13.1 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
# coding: utf-8
"""
Application Load Balancer API
This API offers an interface to provision and manage load balancing servers in your STACKIT project. It also has the possibility of pooling target servers for load balancing purposes. For each application load balancer provided, two VMs are deployed in your OpenStack project subject to a fee.
The version of the OpenAPI document: 2beta2.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import json
import pprint
import re # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set
from pydantic import (
BaseModel,
ConfigDict,
Field,
StrictBool,
StrictStr,
field_validator,
)
from typing_extensions import Annotated, Self
from stackit.alb.models.listener import Listener
from stackit.alb.models.load_balancer_error import LoadBalancerError
from stackit.alb.models.load_balancer_options import LoadBalancerOptions
from stackit.alb.models.network import Network
from stackit.alb.models.security_group import SecurityGroup
from stackit.alb.models.target_pool import TargetPool
class LoadBalancer(BaseModel):
"""
LoadBalancer
""" # noqa: E501
disable_target_security_group_assignment: Optional[StrictBool] = Field(
default=None,
description="Disable target security group assignemt to allow targets outside of the given network. Connectivity to targets need to be ensured by the customer, including routing and Security Groups (targetSecurityGroup can be assigned). Not changeable after creation.",
alias="disableTargetSecurityGroupAssignment",
)
errors: Optional[List[LoadBalancerError]] = Field(
default=None, description="Reports all errors a application load balancer has."
)
external_address: Optional[StrictStr] = Field(
default=None,
description="External application load balancer IP address where this application load balancer is exposed. Not changeable after creation.",
alias="externalAddress",
)
labels: Optional[Dict[str, StrictStr]] = Field(
default=None,
description="Labels represent user-defined metadata as key-value pairs. Label count should not exceed 64 per ALB. **Key Formatting Rules:** Length: 1-63 characters. Characters: Must begin and end with [a-zA-Z0-9]. May contain dashes (-), underscores (_), dots (.), and alphanumerics in between. Keys starting with 'stackit-' are system-reserved; users MUST NOT manage them. **Value Formatting Rules:** Length: 0-63 characters (empty string explicitly allowed). Characters (for non-empty values): Must begin and end with [a-zA-Z0-9]. May contain dashes (-), underscores (_), dots (.), and alphanumerics in between. ",
)
listeners: Optional[List[Listener]] = Field(default=None, description="There is a maximum listener count of 20. ")
load_balancer_security_group: Optional[SecurityGroup] = Field(
default=None,
description="Security Group permitting network traffic from the LoadBalancer to the targets. Useful when disableTargetSecurityGroupAssignment=true to manually assign target security groups to targets.",
alias="loadBalancerSecurityGroup",
)
name: Optional[Annotated[str, Field(strict=True)]] = Field(
default=None, description="Application Load Balancer name. Not changeable after creation."
)
networks: Optional[List[Network]] = Field(
default=None,
description="List of networks that listeners and targets reside in. Currently limited to one. Not changeable after creation.",
)
options: Optional[LoadBalancerOptions] = None
plan_id: Optional[StrictStr] = Field(
default=None,
description="Service Plan configures the size of the Application Load Balancer. Currently supported plans are p10, p50, p250 and p750. This list can change in the future where plan ids will be removed and new plans by added. That is the reason this is not an enum.",
alias="planId",
)
private_address: Optional[StrictStr] = Field(
default=None,
description="Transient private application load balancer IP address that can change any time.",
alias="privateAddress",
)
region: Optional[StrictStr] = Field(default=None, description="Region of the LoadBalancer.")
status: Optional[StrictStr] = None
target_pools: Optional[List[TargetPool]] = Field(
default=None,
description="List of all target pools which will be used in the application load balancer. Limited to 20.",
alias="targetPools",
)
target_security_group: Optional[SecurityGroup] = Field(
default=None,
description="Security Group that allows the targets to receive traffic from the LoadBalancer. Useful when disableTargetSecurityGroupAssignment=true to manually assign target security groups to targets.",
alias="targetSecurityGroup",
)
version: Optional[StrictStr] = Field(
default=None,
description="Application Load Balancer resource version. Must be empty or unset for creating load balancers, non-empty for updating load balancers. Semantics: While retrieving load balancers, this is the current version of this application load balancer resource that changes during updates of the load balancers. On updates this field specified the application load balancer version you calculated your update for instead of the future version to enable concurrency safe updates. Update calls will then report the new version in their result as you would see with a application load balancer retrieval call later. There exist no total order of the version, so you can only compare it for equality, but not for less/greater than another version. Since the creation of application load balancer is always intended to create the first version of it, there should be no existing version. That's why this field must by empty of not present in that case.",
)
__properties: ClassVar[List[str]] = [
"disableTargetSecurityGroupAssignment",
"errors",
"externalAddress",
"labels",
"listeners",
"loadBalancerSecurityGroup",
"name",
"networks",
"options",
"planId",
"privateAddress",
"region",
"status",
"targetPools",
"targetSecurityGroup",
"version",
]
@field_validator("name")
def name_validate_regular_expression(cls, value):
"""Validates the regular expression"""
if value is None:
return value
if not re.match(r"^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$", value):
raise ValueError(r"must validate the regular expression /^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$/")
return value
@field_validator("status")
def status_validate_enum(cls, value):
"""Validates the enum"""
if value is None:
return value
if value not in set(
["STATUS_UNSPECIFIED", "STATUS_PENDING", "STATUS_READY", "STATUS_ERROR", "STATUS_TERMINATING"]
):
raise ValueError(
"must be one of enum values ('STATUS_UNSPECIFIED', 'STATUS_PENDING', 'STATUS_READY', 'STATUS_ERROR', 'STATUS_TERMINATING')"
)
return value
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of LoadBalancer from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
"""
excluded_fields: Set[str] = set(
[
"errors",
"load_balancer_security_group",
"private_address",
"region",
"status",
"target_security_group",
]
)
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of each item in errors (list)
_items = []
if self.errors:
for _item in self.errors:
if _item:
_items.append(_item.to_dict())
_dict["errors"] = _items
# override the default output from pydantic by calling `to_dict()` of each item in listeners (list)
_items = []
if self.listeners:
for _item in self.listeners:
if _item:
_items.append(_item.to_dict())
_dict["listeners"] = _items
# override the default output from pydantic by calling `to_dict()` of load_balancer_security_group
if self.load_balancer_security_group:
_dict["loadBalancerSecurityGroup"] = self.load_balancer_security_group.to_dict()
# override the default output from pydantic by calling `to_dict()` of each item in networks (list)
_items = []
if self.networks:
for _item in self.networks:
if _item:
_items.append(_item.to_dict())
_dict["networks"] = _items
# override the default output from pydantic by calling `to_dict()` of options
if self.options:
_dict["options"] = self.options.to_dict()
# override the default output from pydantic by calling `to_dict()` of each item in target_pools (list)
_items = []
if self.target_pools:
for _item in self.target_pools:
if _item:
_items.append(_item.to_dict())
_dict["targetPools"] = _items
# override the default output from pydantic by calling `to_dict()` of target_security_group
if self.target_security_group:
_dict["targetSecurityGroup"] = self.target_security_group.to_dict()
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of LoadBalancer from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate(
{
"disableTargetSecurityGroupAssignment": obj.get("disableTargetSecurityGroupAssignment"),
"errors": (
[LoadBalancerError.from_dict(_item) for _item in obj["errors"]]
if obj.get("errors") is not None
else None
),
"externalAddress": obj.get("externalAddress"),
"labels": obj.get("labels"),
"listeners": (
[Listener.from_dict(_item) for _item in obj["listeners"]]
if obj.get("listeners") is not None
else None
),
"loadBalancerSecurityGroup": (
SecurityGroup.from_dict(obj["loadBalancerSecurityGroup"])
if obj.get("loadBalancerSecurityGroup") is not None
else None
),
"name": obj.get("name"),
"networks": (
[Network.from_dict(_item) for _item in obj["networks"]] if obj.get("networks") is not None else None
),
"options": LoadBalancerOptions.from_dict(obj["options"]) if obj.get("options") is not None else None,
"planId": obj.get("planId"),
"privateAddress": obj.get("privateAddress"),
"region": obj.get("region"),
"status": obj.get("status"),
"targetPools": (
[TargetPool.from_dict(_item) for _item in obj["targetPools"]]
if obj.get("targetPools") is not None
else None
),
"targetSecurityGroup": (
SecurityGroup.from_dict(obj["targetSecurityGroup"])
if obj.get("targetSecurityGroup") is not None
else None
),
"version": obj.get("version"),
}
)
return _obj