0
# Common Models and Types
1
2
Shared types, enums, exceptions, and patterns used across all Azure RDBMS services (MySQL, PostgreSQL, MariaDB) in both single server and flexible server deployments.
3
4
## Core Resource Models
5
6
### Base Resource Types
7
8
Common base models used across all RDBMS services for consistent resource representation.
9
10
```python { .api }
11
class Resource:
12
"""Base Azure resource representation."""
13
id: str
14
name: str
15
type: str
16
17
class TrackedResource(Resource):
18
"""Tracked Azure resource with location and tags."""
19
location: str
20
tags: Dict[str, str]
21
22
class ProxyResource(Resource):
23
"""Proxy resource without location (child resources)."""
24
pass
25
26
class SystemData:
27
"""System metadata for Azure resources."""
28
created_by: str
29
created_by_type: str # User, Application, ManagedIdentity, Key
30
created_at: datetime
31
last_modified_by: str
32
last_modified_by_type: str
33
last_modified_at: datetime
34
```
35
36
## Server Creation Models
37
38
### Server Creation Parameters
39
40
Common patterns for server creation across all RDBMS services.
41
42
```python { .api }
43
class ServerForCreate:
44
"""Base server creation model."""
45
location: str
46
tags: Dict[str, str]
47
properties: ServerPropertiesForCreate
48
49
class ServerPropertiesForCreate:
50
"""Base server properties for creation."""
51
pass
52
53
class ServerPropertiesForDefaultCreate(ServerPropertiesForCreate):
54
"""Server properties for default creation mode."""
55
administrator_login: str
56
administrator_login_password: str
57
version: str
58
ssl_enforcement: SslEnforcementEnum
59
minimal_tls_version: MinimalTlsVersionEnum
60
infrastructure_encryption: InfrastructureEncryption
61
public_network_access: PublicNetworkAccessEnum
62
storage_profile: StorageProfile
63
64
class ServerPropertiesForRestore(ServerPropertiesForCreate):
65
"""Server properties for restore creation mode."""
66
source_server_id: str
67
restore_point_in_time: datetime
68
69
class ServerPropertiesForGeoRestore(ServerPropertiesForCreate):
70
"""Server properties for geo-restore creation mode."""
71
source_server_id: str
72
73
class ServerPropertiesForReplica(ServerPropertiesForCreate):
74
"""Server properties for replica creation mode."""
75
source_server_id: str
76
```
77
78
## Common Enumerations
79
80
### SSL and TLS Configuration
81
82
```python { .api }
83
class SslEnforcementEnum(str, Enum):
84
"""SSL enforcement options for database servers."""
85
ENABLED = "Enabled"
86
DISABLED = "Disabled"
87
88
class MinimalTlsVersionEnum(str, Enum):
89
"""Minimum TLS version requirements."""
90
TLS1_0 = "TLS1_0"
91
TLS1_1 = "TLS1_1"
92
TLS1_2 = "TLS1_2"
93
TLS_ENFORCEMENT_DISABLED = "TLSEnforcementDisabled"
94
```
95
96
### Server States and Visibility
97
98
```python { .api }
99
class ServerState(str, Enum):
100
"""Server operational states."""
101
READY = "Ready"
102
DROPPING = "Dropping"
103
DISABLED = "Disabled"
104
STARTING = "Starting"
105
STOPPING = "Stopping"
106
STOPPED = "Stopped"
107
UPDATING = "Updating"
108
INACCESSIBLE = "Inaccessible"
109
110
class ServerVersion(str, Enum):
111
"""Database server versions."""
112
# MySQL versions
113
MYSQL_5_6 = "5.6"
114
MYSQL_5_7 = "5.7"
115
MYSQL_8_0 = "8.0"
116
117
# PostgreSQL versions
118
POSTGRESQL_9_5 = "9.5"
119
POSTGRESQL_9_6 = "9.6"
120
POSTGRESQL_10 = "10"
121
POSTGRESQL_11 = "11"
122
POSTGRESQL_12 = "12"
123
POSTGRESQL_13 = "13"
124
POSTGRESQL_14 = "14"
125
POSTGRESQL_15 = "15"
126
127
# MariaDB versions
128
MARIADB_10_2 = "10.2"
129
MARIADB_10_3 = "10.3"
130
131
class PublicNetworkAccessEnum(str, Enum):
132
"""Public network access configuration."""
133
ENABLED = "Enabled"
134
DISABLED = "Disabled"
135
136
class InfrastructureEncryption(str, Enum):
137
"""Infrastructure encryption options."""
138
ENABLED = "Enabled"
139
DISABLED = "Disabled"
140
```
141
142
### Storage and Backup Configuration
143
144
```python { .api }
145
class StorageAutogrow(str, Enum):
146
"""Storage auto-grow options."""
147
ENABLED = "Enabled"
148
DISABLED = "Disabled"
149
150
class GeoRedundantBackup(str, Enum):
151
"""Geo-redundant backup options."""
152
ENABLED = "Enabled"
153
DISABLED = "Disabled"
154
155
class BackupRetentionDays:
156
"""Backup retention validation."""
157
MIN_DAYS = 7
158
MAX_DAYS = 35
159
```
160
161
## Storage Models
162
163
### Storage Configuration
164
165
Common storage models used across single server deployments.
166
167
```python { .api }
168
class StorageProfile:
169
"""Storage configuration for database servers."""
170
backup_retention_days: int # 7-35 days
171
geo_redundant_backup: GeoRedundantBackup
172
storage_mb: int
173
storage_autogrow: StorageAutogrow
174
175
class StorageMB:
176
"""Storage size validation and common values."""
177
MIN_VALUE = 5120 # 5 GB
178
MAX_VALUE = 4194304 # 4 TB
179
180
# Common storage sizes
181
BASIC_5GB = 5120
182
BASIC_10GB = 10240
183
GENERAL_PURPOSE_100GB = 102400
184
GENERAL_PURPOSE_1TB = 1048576
185
MEMORY_OPTIMIZED_1TB = 1048576
186
```
187
188
## Performance and Monitoring Models
189
190
### Performance Tier Configuration
191
192
```python { .api }
193
class PerformanceTierProperties:
194
"""Performance tier definition."""
195
id: str
196
max_backup_retention_days: int
197
min_backup_retention_days: int
198
max_storage_mb: int
199
min_large_storage_mb: int
200
max_large_storage_mb: int
201
min_storage_mb: int
202
203
class ServiceObjective:
204
"""Service objective for performance tiers."""
205
service_objective_name: str
206
id: str
207
unit: str # DTU, vCore
208
last_observed_time: datetime
209
metric_name: str
210
metric_display_name: str
211
metric_current_value: float
212
metric_limit: float
213
metric_unit: str
214
```
215
216
## Security Models
217
218
### Firewall and Network Access
219
220
```python { .api }
221
class FirewallRule(ProxyResource):
222
"""IP-based firewall rule for database servers."""
223
start_ip_address: str
224
end_ip_address: str
225
system_data: SystemData
226
227
class VirtualNetworkRule(ProxyResource):
228
"""Virtual network rule for database servers."""
229
virtual_network_subnet_id: str
230
ignore_missing_vnet_service_endpoint: bool
231
state: VirtualNetworkRuleState
232
233
class VirtualNetworkRuleState(str, Enum):
234
"""Virtual network rule states."""
235
INITIALIZING = "Initializing"
236
IN_PROGRESS = "InProgress"
237
READY = "Ready"
238
DELETING = "Deleting"
239
UNKNOWN = "Unknown"
240
```
241
242
### Authentication and Access Control
243
244
```python { .api }
245
class ServerAdministratorResource(ProxyResource):
246
"""Azure Active Directory administrator."""
247
administrator_type: AdministratorType
248
login: str
249
sid: str
250
tenant_id: str
251
252
class AdministratorType(str, Enum):
253
"""Administrator types."""
254
ACTIVE_DIRECTORY = "ActiveDirectory"
255
256
class ServerKey(ProxyResource):
257
"""Customer-managed encryption key."""
258
kind: str
259
server_key_type: ServerKeyType
260
uri: str
261
creation_date: datetime
262
263
class ServerKeyType(str, Enum):
264
"""Server key types."""
265
AZURE_KEY_VAULT = "AzureKeyVault"
266
```
267
268
## Configuration Models
269
270
### Server Configuration Parameters
271
272
```python { .api }
273
class Configuration(ProxyResource):
274
"""Database server configuration parameter."""
275
value: str
276
description: str
277
default_value: str
278
data_type: str
279
allowed_values: str
280
source: str
281
is_dynamic: bool
282
is_read_only: bool
283
is_config_pending_restart: bool
284
system_data: SystemData
285
286
class ConfigurationSource(str, Enum):
287
"""Configuration parameter sources."""
288
SYSTEM_DEFAULT = "system-default"
289
USER_OVERRIDE = "user-override"
290
```
291
292
## Error Models and Exception Handling
293
294
### Common Error Types
295
296
```python { .api }
297
class ErrorResponse:
298
"""Standard error response format."""
299
error: ErrorDefinition
300
301
class ErrorDefinition:
302
"""Error definition details."""
303
code: str
304
message: str
305
target: str
306
details: List[ErrorDefinition]
307
308
class CloudError(Exception):
309
"""Base cloud error for RDBMS operations."""
310
error: ErrorResponse
311
312
class ResourceNotFoundError(CloudError):
313
"""Resource not found error."""
314
pass
315
316
class BadRequestError(CloudError):
317
"""Bad request error."""
318
pass
319
320
class ConflictError(CloudError):
321
"""Resource conflict error."""
322
pass
323
324
class InternalServerError(CloudError):
325
"""Internal server error."""
326
pass
327
```
328
329
## Long Running Operations (LRO)
330
331
### Operation Status and Polling
332
333
```python { .api }
334
class LROPoller:
335
"""Long running operation poller."""
336
def result(self, timeout: int = None):
337
"""Wait for operation completion and return result."""
338
pass
339
340
def status(self) -> str:
341
"""Get current operation status."""
342
pass
343
344
def done(self) -> bool:
345
"""Check if operation is completed."""
346
pass
347
348
def wait(self, timeout: int = None):
349
"""Wait for operation completion without returning result."""
350
pass
351
352
class OperationStatus(str, Enum):
353
"""Operation status values."""
354
IN_PROGRESS = "InProgress"
355
SUCCEEDED = "Succeeded"
356
FAILED = "Failed"
357
CANCELED = "Canceled"
358
```
359
360
## Pagination Models
361
362
### Paged Results
363
364
```python { .api }
365
class PagedResult:
366
"""Paged result collection."""
367
value: List[Any]
368
next_link: str
369
370
class ItemPaged:
371
"""Iterable paged collection."""
372
def __iter__(self):
373
"""Iterate through all items across pages."""
374
pass
375
376
def by_page(self):
377
"""Iterate page by page."""
378
pass
379
```
380
381
## Validation Models
382
383
### Name Availability
384
385
```python { .api }
386
class NameAvailabilityRequest:
387
"""Name availability check request."""
388
name: str
389
type: str # Microsoft.DBforMySQL/servers, Microsoft.DBforPostgreSQL/servers
390
391
class NameAvailability:
392
"""Name availability check result."""
393
name_available: bool
394
reason: UnavailabilityReason
395
message: str
396
397
class UnavailabilityReason(str, Enum):
398
"""Reasons for name unavailability."""
399
INVALID = "Invalid"
400
ALREADY_EXISTS = "AlreadyExists"
401
```
402
403
## Flexible Server Specific Models
404
405
### Enhanced Storage and Backup
406
407
```python { .api }
408
class FlexibleServerStorage:
409
"""Enhanced storage for flexible servers."""
410
storage_size_gb: int
411
iops: int
412
auto_grow: StorageAutogrow
413
storage_sku: str # Premium_LRS, Standard_LRS
414
tier: str # P4, P6, P10, etc.
415
416
class FlexibleServerBackup:
417
"""Enhanced backup configuration for flexible servers."""
418
backup_retention_days: int
419
geo_redundant_backup: GeoRedundantBackup
420
earliest_restore_date: datetime
421
422
class HighAvailability:
423
"""High availability configuration for flexible servers."""
424
mode: HighAvailabilityMode
425
state: HighAvailabilityState
426
standby_availability_zone: str
427
428
class HighAvailabilityMode(str, Enum):
429
"""High availability modes."""
430
DISABLED = "Disabled"
431
ZONE_REDUNDANT = "ZoneRedundant"
432
SAME_ZONE = "SameZone"
433
434
class HighAvailabilityState(str, Enum):
435
"""High availability states."""
436
NOT_ENABLED = "NotEnabled"
437
CREATING_STANDBY = "CreatingStandby"
438
REPLICATING_DATA = "ReplicatingData"
439
FAILING_OVER = "FailingOver"
440
HEALTHY = "Healthy"
441
REMOVING_STANDBY = "RemovingStandby"
442
```
443
444
### Network Configuration
445
446
```python { .api }
447
class Network:
448
"""Network configuration for flexible servers."""
449
public_network_access: PublicNetworkAccessEnum
450
delegated_subnet_resource_id: str
451
private_dns_zone_resource_id: str
452
453
class MaintenanceWindow:
454
"""Maintenance window configuration."""
455
custom_window: str # Enabled, Disabled
456
start_hour: int # 0-23
457
start_minute: int # 0, 30
458
day_of_week: int # 0-6 (Sunday-Saturday)
459
```
460
461
## Common Usage Patterns
462
463
### Authentication Setup
464
465
```python
466
from azure.identity import DefaultAzureCredential, ClientSecretCredential
467
468
# Using default credential chain
469
credential = DefaultAzureCredential()
470
471
# Using service principal
472
credential = ClientSecretCredential(
473
tenant_id="tenant-id",
474
client_id="client-id",
475
client_secret="client-secret"
476
)
477
```
478
479
### Error Handling Pattern
480
481
```python
482
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
483
484
try:
485
server = client.servers.get("resource-group", "server-name")
486
except ResourceNotFoundError:
487
print("Server not found")
488
except HttpResponseError as e:
489
print(f"HTTP error: {e.status_code} - {e.message}")
490
except Exception as e:
491
print(f"Unexpected error: {e}")
492
```
493
494
### Long Running Operation Pattern
495
496
```python
497
# Async operation with polling
498
operation = client.servers.begin_create("rg", "server", parameters)
499
500
# Wait for completion
501
try:
502
server = operation.result(timeout=1800) # 30 minutes
503
print(f"Server created: {server.name}")
504
except Exception as e:
505
print(f"Operation failed: {e}")
506
507
# Check status without waiting
508
if operation.done():
509
result = operation.result()
510
else:
511
print(f"Operation status: {operation.status()}")
512
```
513
514
### Pagination Pattern
515
516
```python
517
# Iterate through all items
518
for server in client.servers.list():
519
print(f"Server: {server.name}")
520
521
# Page-by-page iteration
522
paged_result = client.servers.list()
523
for page in paged_result.by_page():
524
for server in page:
525
print(f"Server: {server.name}")
526
```