0
# Disk and Storage Management
1
2
Management of managed disks, snapshots, disk encryption, and disk access controls for persistent storage solutions. This includes operations for creating, configuring, and managing Azure managed disks, snapshots for backup and recovery, disk encryption sets for security, and disk access controls for private endpoints.
3
4
## Capabilities
5
6
### Managed Disk Operations
7
8
Core operations for managing Azure managed disks.
9
10
```python { .api }
11
def begin_create_or_update(
12
resource_group_name: str,
13
disk_name: str,
14
disk: Disk
15
) -> LROPoller[Disk]:
16
"""
17
Create or update a managed disk.
18
19
Args:
20
resource_group_name: Name of the resource group
21
disk_name: Name of the disk
22
disk: Disk configuration parameters
23
24
Returns:
25
Long-running operation poller for Disk
26
"""
27
28
def begin_delete(resource_group_name: str, disk_name: str) -> LROPoller[None]:
29
"""
30
Delete a managed disk.
31
32
Args:
33
resource_group_name: Name of the resource group
34
disk_name: Name of the disk
35
36
Returns:
37
Long-running operation poller
38
"""
39
40
def get(resource_group_name: str, disk_name: str) -> Disk:
41
"""
42
Get managed disk details.
43
44
Args:
45
resource_group_name: Name of the resource group
46
disk_name: Name of the disk
47
48
Returns:
49
Disk details
50
"""
51
52
def list() -> Iterable[Disk]:
53
"""
54
List all managed disks in the subscription.
55
56
Returns:
57
Iterable of all disks in the subscription
58
"""
59
60
def list_by_resource_group(resource_group_name: str) -> Iterable[Disk]:
61
"""
62
List managed disks in a resource group.
63
64
Args:
65
resource_group_name: Name of the resource group
66
67
Returns:
68
Iterable of disks in the resource group
69
"""
70
```
71
72
### Disk Access and Export
73
74
Operations for granting access to disks and exporting disk data.
75
76
```python { .api }
77
def begin_grant_access(
78
resource_group_name: str,
79
disk_name: str,
80
grant_access_data: GrantAccessData
81
) -> LROPoller[AccessUri]:
82
"""
83
Grant access to a managed disk for export or backup.
84
85
Args:
86
resource_group_name: Name of the resource group
87
disk_name: Name of the disk
88
grant_access_data: Access grant parameters including duration and access level
89
90
Returns:
91
Long-running operation poller for AccessUri
92
"""
93
94
def begin_revoke_access(resource_group_name: str, disk_name: str) -> LROPoller[None]:
95
"""
96
Revoke access to a managed disk.
97
98
Args:
99
resource_group_name: Name of the resource group
100
disk_name: Name of the disk
101
102
Returns:
103
Long-running operation poller
104
"""
105
```
106
107
### Snapshot Operations
108
109
Operations for managing disk snapshots.
110
111
```python { .api }
112
class SnapshotsOperations:
113
def begin_create_or_update(
114
resource_group_name: str,
115
snapshot_name: str,
116
snapshot: Snapshot
117
) -> LROPoller[Snapshot]:
118
"""
119
Create or update a snapshot.
120
121
Args:
122
resource_group_name: Name of the resource group
123
snapshot_name: Name of the snapshot
124
snapshot: Snapshot configuration
125
126
Returns:
127
Long-running operation poller for Snapshot
128
"""
129
130
def begin_delete(resource_group_name: str, snapshot_name: str) -> LROPoller[None]:
131
"""
132
Delete a snapshot.
133
134
Args:
135
resource_group_name: Name of the resource group
136
snapshot_name: Name of the snapshot
137
138
Returns:
139
Long-running operation poller
140
"""
141
142
def get(resource_group_name: str, snapshot_name: str) -> Snapshot:
143
"""
144
Get snapshot details.
145
146
Args:
147
resource_group_name: Name of the resource group
148
snapshot_name: Name of the snapshot
149
150
Returns:
151
Snapshot details
152
"""
153
154
def list() -> Iterable[Snapshot]:
155
"""
156
List all snapshots in the subscription.
157
158
Returns:
159
Iterable of all snapshots
160
"""
161
162
def list_by_resource_group(resource_group_name: str) -> Iterable[Snapshot]:
163
"""
164
List snapshots in a resource group.
165
166
Args:
167
resource_group_name: Name of the resource group
168
169
Returns:
170
Iterable of snapshots in the resource group
171
"""
172
```
173
174
### Disk Encryption Sets
175
176
Operations for managing disk encryption sets for enhanced security.
177
178
```python { .api }
179
class DiskEncryptionSetsOperations:
180
def begin_create_or_update(
181
resource_group_name: str,
182
disk_encryption_set_name: str,
183
disk_encryption_set: DiskEncryptionSet
184
) -> LROPoller[DiskEncryptionSet]:
185
"""
186
Create or update a disk encryption set.
187
188
Args:
189
resource_group_name: Name of the resource group
190
disk_encryption_set_name: Name of the disk encryption set
191
disk_encryption_set: Encryption set configuration
192
193
Returns:
194
Long-running operation poller for DiskEncryptionSet
195
"""
196
197
def begin_delete(resource_group_name: str, disk_encryption_set_name: str) -> LROPoller[None]:
198
"""
199
Delete a disk encryption set.
200
201
Args:
202
resource_group_name: Name of the resource group
203
disk_encryption_set_name: Name of the disk encryption set
204
205
Returns:
206
Long-running operation poller
207
"""
208
209
def get(resource_group_name: str, disk_encryption_set_name: str) -> DiskEncryptionSet:
210
"""
211
Get disk encryption set details.
212
213
Args:
214
resource_group_name: Name of the resource group
215
disk_encryption_set_name: Name of the disk encryption set
216
217
Returns:
218
Disk encryption set details
219
"""
220
221
def list() -> Iterable[DiskEncryptionSet]:
222
"""
223
List all disk encryption sets in the subscription.
224
225
Returns:
226
Iterable of all disk encryption sets
227
"""
228
229
def list_by_resource_group(resource_group_name: str) -> Iterable[DiskEncryptionSet]:
230
"""
231
List disk encryption sets in a resource group.
232
233
Args:
234
resource_group_name: Name of the resource group
235
236
Returns:
237
Iterable of disk encryption sets in the resource group
238
"""
239
```
240
241
### Disk Access Controls
242
243
Operations for managing private endpoints and network access to disks.
244
245
```python { .api }
246
class DiskAccessesOperations:
247
def begin_create_or_update(
248
resource_group_name: str,
249
disk_access_name: str,
250
disk_access: DiskAccess
251
) -> LROPoller[DiskAccess]:
252
"""
253
Create or update a disk access resource for private endpoints.
254
255
Args:
256
resource_group_name: Name of the resource group
257
disk_access_name: Name of the disk access resource
258
disk_access: Disk access configuration
259
260
Returns:
261
Long-running operation poller for DiskAccess
262
"""
263
264
def begin_delete(resource_group_name: str, disk_access_name: str) -> LROPoller[None]:
265
"""
266
Delete a disk access resource.
267
268
Args:
269
resource_group_name: Name of the resource group
270
disk_access_name: Name of the disk access resource
271
272
Returns:
273
Long-running operation poller
274
"""
275
276
def get(resource_group_name: str, disk_access_name: str) -> DiskAccess:
277
"""
278
Get disk access resource details.
279
280
Args:
281
resource_group_name: Name of the resource group
282
disk_access_name: Name of the disk access resource
283
284
Returns:
285
Disk access resource details
286
"""
287
288
def list() -> Iterable[DiskAccess]:
289
"""
290
List all disk access resources in the subscription.
291
292
Returns:
293
Iterable of all disk access resources
294
"""
295
```
296
297
## Data Types
298
299
```python { .api }
300
class Disk:
301
"""Disk resource."""
302
id: Optional[str]
303
name: Optional[str]
304
type: Optional[str]
305
location: str
306
tags: Optional[Dict[str, str]]
307
managed_by: Optional[str]
308
managed_by_extended: Optional[List[str]]
309
sku: Optional[DiskSku]
310
zones: Optional[List[str]]
311
extended_location: Optional[ExtendedLocation]
312
time_created: Optional[datetime]
313
os_type: Optional[OperatingSystemTypes]
314
hyper_v_generation: Optional[HyperVGeneration]
315
purchase_plan: Optional[PurchasePlan]
316
creation_data: CreationData
317
disk_size_gb: Optional[int]
318
disk_size_bytes: Optional[int]
319
unique_id: Optional[str]
320
encryption_settings_collection: Optional[EncryptionSettingsCollection]
321
provisioning_state: Optional[str]
322
disk_iops_read_write: Optional[int]
323
disk_m_bps_read_write: Optional[int]
324
disk_iops_read_only: Optional[int]
325
disk_m_bps_read_only: Optional[int]
326
disk_state: Optional[DiskState]
327
encryption: Optional[Encryption]
328
max_shares: Optional[int]
329
share_info: Optional[List[ShareInfoElement]]
330
network_access_policy: Optional[NetworkAccessPolicy]
331
disk_access_id: Optional[str]
332
tier: Optional[str]
333
bursting_enabled: Optional[bool]
334
property_updates_in_progress: Optional[PropertyUpdatesInProgress]
335
supports_hibernation: Optional[bool]
336
security_profile: Optional[DiskSecurityProfile]
337
completion_percent: Optional[float]
338
public_network_access: Optional[PublicNetworkAccess]
339
data_access_auth_mode: Optional[DataAccessAuthMode]
340
optimized_for_frequent_attach: Optional[bool]
341
342
class DiskSku:
343
"""The disks sku name."""
344
name: Optional[DiskStorageAccountTypes]
345
tier: Optional[str]
346
347
class CreationData:
348
"""Data for creating a disk."""
349
create_option: DiskCreateOption
350
storage_account_id: Optional[str]
351
image_reference: Optional[ImageDiskReference]
352
gallery_image_reference: Optional[ImageDiskReference]
353
source_uri: Optional[str]
354
source_resource_id: Optional[str]
355
source_unique_id: Optional[str]
356
upload_size_bytes: Optional[int]
357
logical_sector_size: Optional[int]
358
security_data_uri: Optional[str]
359
perform_copy_completion: Optional[bool]
360
elastic_san_resource_id: Optional[str]
361
provisioned_bandwidth_copy_speed: Optional[ProvisionedBandwidthCopyOption]
362
363
class Snapshot:
364
"""Snapshot resource."""
365
id: Optional[str]
366
name: Optional[str]
367
type: Optional[str]
368
location: str
369
tags: Optional[Dict[str, str]]
370
managed_by: Optional[str]
371
sku: Optional[SnapshotSku]
372
extended_location: Optional[ExtendedLocation]
373
time_created: Optional[datetime]
374
os_type: Optional[OperatingSystemTypes]
375
hyper_v_generation: Optional[HyperVGeneration]
376
purchase_plan: Optional[PurchasePlan]
377
creation_data: CreationData
378
disk_size_gb: Optional[int]
379
disk_size_bytes: Optional[int]
380
disk_state: Optional[DiskState]
381
unique_id: Optional[str]
382
encryption_settings_collection: Optional[EncryptionSettingsCollection]
383
provisioning_state: Optional[str]
384
incremental: Optional[bool]
385
encryption: Optional[Encryption]
386
network_access_policy: Optional[NetworkAccessPolicy]
387
disk_access_id: Optional[str]
388
security_profile: Optional[DiskSecurityProfile]
389
supports_hibernation: Optional[bool]
390
public_network_access: Optional[PublicNetworkAccess]
391
completion_percent: Optional[float]
392
copy_completion_error: Optional[CopyCompletionError]
393
data_access_auth_mode: Optional[DataAccessAuthMode]
394
395
class DiskEncryptionSet:
396
"""Disk encryption set resource."""
397
id: Optional[str]
398
name: Optional[str]
399
type: Optional[str]
400
location: str
401
tags: Optional[Dict[str, str]]
402
identity: Optional[EncryptionSetIdentity]
403
encryption_type: Optional[DiskEncryptionSetType]
404
active_key: Optional[KeyForDiskEncryptionSet]
405
previous_keys: Optional[List[KeyForDiskEncryptionSet]]
406
provisioning_state: Optional[str]
407
rotation_to_latest_key_version_enabled: Optional[bool]
408
last_key_rotation_timestamp: Optional[datetime]
409
auto_key_rotation_error: Optional[ApiError]
410
federated_client_id: Optional[str]
411
412
class DiskAccess:
413
"""Disk access resource."""
414
id: Optional[str]
415
name: Optional[str]
416
type: Optional[str]
417
location: str
418
tags: Optional[Dict[str, str]]
419
extended_location: Optional[ExtendedLocation]
420
private_endpoint_connections: Optional[List[PrivateEndpointConnection]]
421
provisioning_state: Optional[str]
422
time_created: Optional[datetime]
423
disk_access_id: Optional[str]
424
425
class GrantAccessData:
426
"""Data for granting access to a disk."""
427
access: AccessLevel
428
duration_in_seconds: int
429
get_secure_vm_guest_state_sas: Optional[bool]
430
431
class AccessUri:
432
"""A disk access SAS uri."""
433
access_sas: Optional[str]
434
security_data_access_sas: Optional[str]
435
```
436
437
## Usage Examples
438
439
### Create a Managed Disk
440
441
```python
442
from azure.identity import DefaultAzureCredential
443
from azure.mgmt.compute import ComputeManagementClient
444
445
credential = DefaultAzureCredential()
446
compute_client = ComputeManagementClient(credential, "subscription-id")
447
448
disk_parameters = {
449
'location': 'East US',
450
'sku': {
451
'name': 'Premium_LRS'
452
},
453
'creation_data': {
454
'create_option': 'Empty'
455
},
456
'disk_size_gb': 128,
457
'tags': {
458
'environment': 'production',
459
'project': 'myapp'
460
}
461
}
462
463
operation = compute_client.disks.begin_create_or_update(
464
'myResourceGroup',
465
'myDataDisk',
466
disk_parameters
467
)
468
disk = operation.result()
469
print(f"Disk {disk.name} created with size {disk.disk_size_gb} GB")
470
```
471
472
### Create Disk from Snapshot
473
474
```python
475
# First create a snapshot from an existing disk
476
snapshot_parameters = {
477
'location': 'East US',
478
'creation_data': {
479
'create_option': 'Copy',
480
'source_resource_id': '/subscriptions/.../disks/sourceDisk'
481
}
482
}
483
484
operation = compute_client.snapshots.begin_create_or_update(
485
'myResourceGroup',
486
'mySnapshot',
487
snapshot_parameters
488
)
489
snapshot = operation.result()
490
491
# Create a new disk from the snapshot
492
disk_from_snapshot = {
493
'location': 'East US',
494
'sku': {
495
'name': 'Standard_LRS'
496
},
497
'creation_data': {
498
'create_option': 'Copy',
499
'source_resource_id': snapshot.id
500
}
501
}
502
503
operation = compute_client.disks.begin_create_or_update(
504
'myResourceGroup',
505
'diskFromSnapshot',
506
disk_from_snapshot
507
)
508
new_disk = operation.result()
509
print(f"New disk created from snapshot: {new_disk.name}")
510
```
511
512
### Setup Disk Encryption
513
514
```python
515
# Create disk encryption set
516
encryption_set_parameters = {
517
'location': 'East US',
518
'identity': {
519
'type': 'SystemAssigned'
520
},
521
'encryption_type': 'EncryptionAtRestWithCustomerKey',
522
'active_key': {
523
'source_vault': {
524
'id': '/subscriptions/.../vaults/myKeyVault'
525
},
526
'key_url': 'https://mykeyvault.vault.azure.net/keys/mykey/version'
527
}
528
}
529
530
operation = compute_client.disk_encryption_sets.begin_create_or_update(
531
'myResourceGroup',
532
'myEncryptionSet',
533
encryption_set_parameters
534
)
535
encryption_set = operation.result()
536
537
# Create encrypted disk
538
encrypted_disk_parameters = {
539
'location': 'East US',
540
'sku': {
541
'name': 'Premium_LRS'
542
},
543
'creation_data': {
544
'create_option': 'Empty'
545
},
546
'disk_size_gb': 256,
547
'encryption': {
548
'disk_encryption_set_id': encryption_set.id,
549
'type': 'EncryptionAtRestWithCustomerKey'
550
}
551
}
552
553
operation = compute_client.disks.begin_create_or_update(
554
'myResourceGroup',
555
'myEncryptedDisk',
556
encrypted_disk_parameters
557
)
558
encrypted_disk = operation.result()
559
print(f"Encrypted disk created: {encrypted_disk.name}")
560
```
561
562
### Export Disk Data
563
564
```python
565
# Grant read access to disk for export
566
grant_access_data = {
567
'access': 'Read',
568
'duration_in_seconds': 3600 # 1 hour
569
}
570
571
operation = compute_client.disks.begin_grant_access(
572
'myResourceGroup',
573
'myDisk',
574
grant_access_data
575
)
576
access_uri = operation.result()
577
578
print(f"Disk export URL: {access_uri.access_sas}")
579
580
# Later, revoke access
581
operation = compute_client.disks.begin_revoke_access(
582
'myResourceGroup',
583
'myDisk'
584
)
585
operation.result()
586
print("Disk access revoked")
587
```
588
589
### Monitor Disk Performance
590
591
```python
592
# List disks and check their performance characteristics
593
disks = compute_client.disks.list_by_resource_group('myResourceGroup')
594
595
for disk in disks:
596
print(f"Disk: {disk.name}")
597
print(f" SKU: {disk.sku.name}")
598
print(f" Size: {disk.disk_size_gb} GB")
599
print(f" IOPS: {disk.disk_iops_read_write}")
600
print(f" Throughput: {disk.disk_m_bps_read_write} MBps")
601
print(f" State: {disk.disk_state}")
602
print(f" Provisioning State: {disk.provisioning_state}")
603
if disk.share_info:
604
print(f" Shared with {len(disk.share_info)} VMs")
605
print()
606
```