0
# Utility Operations
1
2
Operations for discovering available SKUs, checking usage limits, managing deleted accounts, and retrieving service metadata. These utilities provide essential information for storage account planning and management.
3
4
## Capabilities
5
6
### SKU Information
7
8
Discover available storage account SKUs and their capabilities across Azure regions.
9
10
```python { .api }
11
class SkusOperations:
12
def list(self) -> ItemPaged[SkuInformation]:
13
"""
14
Lists the available SKUs supported by Microsoft.Storage.
15
16
Returns:
17
Paginated list of SkuInformation objects with available SKUs
18
"""
19
```
20
21
Usage example:
22
23
```python
24
# List all available SKUs
25
skus = list(client.skus.list())
26
27
for sku in skus:
28
print(f"SKU: {sku.name}, Tier: {sku.tier}")
29
print(f" Kind: {sku.kind}")
30
print(f" Locations: {sku.locations}")
31
print(f" Capabilities: {[cap.name + '=' + cap.value for cap in sku.capabilities]}")
32
print(f" Restrictions: {len(sku.restrictions)} restriction(s)")
33
print()
34
35
# Filter for specific SKU types
36
premium_skus = [sku for sku in skus if "Premium" in sku.name]
37
standard_skus = [sku for sku in skus if "Standard" in sku.name]
38
39
print(f"Premium SKUs: {len(premium_skus)}")
40
print(f"Standard SKUs: {len(standard_skus)}")
41
```
42
43
### Usage and Limits
44
45
Check current usage and limits for storage resources in specific Azure regions.
46
47
```python { .api }
48
class UsagesOperations:
49
def list_by_location(self, location: str) -> ItemPaged[Usage]:
50
"""
51
Lists storage usage metrics for the specified location.
52
53
Parameters:
54
- location: Azure region name (e.g., "East US", "West Europe")
55
56
Returns:
57
Paginated list of Usage objects showing current usage and limits
58
"""
59
```
60
61
Usage example:
62
63
```python
64
# Check usage in specific regions
65
regions = ["East US", "West Europe", "Southeast Asia"]
66
67
for region in regions:
68
print(f"\nUsage in {region}:")
69
usages = list(client.usages.list_by_location(region))
70
71
for usage in usages:
72
print(f" {usage.name.value}: {usage.current_value}/{usage.limit} {usage.unit}")
73
if usage.current_value > (usage.limit * 0.8):
74
print(f" WARNING: Usage at {(usage.current_value/usage.limit)*100:.1f}% of limit")
75
76
# Find regions with available capacity
77
available_regions = []
78
for region in ["East US", "West US", "Central US", "North Europe", "West Europe"]:
79
usages = list(client.usages.list_by_location(region))
80
storage_account_usage = next((u for u in usages if "StorageAccounts" in u.name.value), None)
81
82
if storage_account_usage and storage_account_usage.current_value < storage_account_usage.limit:
83
available_capacity = storage_account_usage.limit - storage_account_usage.current_value
84
available_regions.append({
85
"region": region,
86
"available": available_capacity,
87
"total": storage_account_usage.limit
88
})
89
90
print(f"\nRegions with available storage account capacity:")
91
for region_info in sorted(available_regions, key=lambda x: x["available"], reverse=True):
92
print(f" {region_info['region']}: {region_info['available']} available")
93
```
94
95
### Deleted Account Recovery
96
97
Manage and recover soft-deleted storage accounts.
98
99
```python { .api }
100
class DeletedAccountsOperations:
101
def list(self) -> ItemPaged[DeletedAccount]:
102
"""
103
Lists deleted accounts under the subscription.
104
105
Returns:
106
Paginated list of DeletedAccount objects that can be restored
107
"""
108
109
def get(self, deleted_account_name: str, location: str) -> DeletedAccount:
110
"""
111
Gets properties of the specified deleted account.
112
113
Parameters:
114
- deleted_account_name: Name of the deleted storage account
115
- location: Location of the deleted account
116
117
Returns:
118
DeletedAccount with restoration details
119
"""
120
```
121
122
Usage example:
123
124
```python
125
# List all deleted accounts that can be restored
126
deleted_accounts = list(client.deleted_accounts.list())
127
128
print(f"Found {len(deleted_accounts)} deleted storage accounts:")
129
for deleted_account in deleted_accounts:
130
print(f" Account: {deleted_account.name}")
131
print(f" Original Location: {deleted_account.location}")
132
print(f" Deletion Time: {deleted_account.deletion_time}")
133
print(f" Remaining Retention Days: {deleted_account.remaining_retention_days}")
134
print(f" Restorable: {'Yes' if deleted_account.remaining_retention_days > 0 else 'No'}")
135
print()
136
137
# Get details for a specific deleted account
138
if deleted_accounts:
139
first_deleted = deleted_accounts[0]
140
account_details = client.deleted_accounts.get(
141
deleted_account_name=first_deleted.name,
142
location=first_deleted.location
143
)
144
145
print(f"Details for {account_details.name}:")
146
print(f" Storage Account Type: {account_details.storage_account_type}")
147
print(f" Creation Time: {account_details.creation_time}")
148
print(f" Can Restore: {account_details.remaining_retention_days > 0}")
149
```
150
151
### Service Operations Metadata
152
153
Retrieve metadata about available Azure Storage management operations.
154
155
```python { .api }
156
class Operations:
157
def list(self) -> ItemPaged[Operation]:
158
"""
159
Lists all available Azure Storage management operations.
160
161
Returns:
162
Paginated list of Operation objects describing available API operations
163
"""
164
```
165
166
Usage example:
167
168
```python
169
# List all available operations
170
operations = list(client.operations.list())
171
172
print(f"Available operations: {len(operations)}")
173
174
# Group operations by resource type
175
operation_groups = {}
176
for op in operations:
177
# Extract resource type from operation name
178
parts = op.name.split('/')
179
if len(parts) >= 2:
180
provider = parts[0] # Microsoft.Storage
181
resource_type = parts[1] # storageAccounts, blobServices, etc.
182
183
if resource_type not in operation_groups:
184
operation_groups[resource_type] = []
185
operation_groups[resource_type].append(op)
186
187
# Display operations by resource type
188
for resource_type, ops in sorted(operation_groups.items()):
189
print(f"\n{resource_type} operations ({len(ops)}):")
190
for op in ops[:5]: # Show first 5 operations
191
print(f" {op.name}")
192
print(f" Display: {op.display.operation}")
193
print(f" Description: {op.display.description}")
194
195
if len(ops) > 5:
196
print(f" ... and {len(ops) - 5} more operations")
197
198
# Find specific operations
199
storage_account_ops = [op for op in operations if "storageAccounts" in op.name]
200
blob_ops = [op for op in operations if "blobServices" or "blobContainers" in op.name]
201
202
print(f"\nStorage Account operations: {len(storage_account_ops)}")
203
print(f"Blob-related operations: {len(blob_ops)}")
204
205
# Check for read vs write operations
206
read_ops = [op for op in operations if any(verb in op.name.lower() for verb in ['read', 'get', 'list'])]
207
write_ops = [op for op in operations if any(verb in op.name.lower() for verb in ['write', 'create', 'update', 'delete'])]
208
209
print(f"Read operations: {len(read_ops)}")
210
print(f"Write operations: {len(write_ops)}")
211
```
212
213
### Checking Service Availability
214
215
Combine utilities to check service availability and capacity planning.
216
217
```python
218
def check_service_availability(regions_to_check, required_sku="Standard_LRS"):
219
"""
220
Check service availability across multiple regions.
221
222
Parameters:
223
- regions_to_check: List of Azure region names
224
- required_sku: SKU name to check availability for
225
226
Returns:
227
Dictionary with availability information per region
228
"""
229
availability = {}
230
231
# Check if SKU is available
232
available_skus = list(client.skus.list())
233
target_sku = next((sku for sku in available_skus if sku.name == required_sku), None)
234
235
if not target_sku:
236
print(f"SKU {required_sku} not found")
237
return availability
238
239
for region in regions_to_check:
240
region_info = {
241
"sku_available": region in target_sku.locations,
242
"usage_info": None,
243
"restrictions": []
244
}
245
246
# Check usage limits
247
try:
248
usages = list(client.usages.list_by_location(region))
249
storage_usage = next((u for u in usages if "StorageAccounts" in u.name.value), None)
250
if storage_usage:
251
region_info["usage_info"] = {
252
"current": storage_usage.current_value,
253
"limit": storage_usage.limit,
254
"available": storage_usage.limit - storage_usage.current_value,
255
"utilization_pct": (storage_usage.current_value / storage_usage.limit) * 100
256
}
257
except Exception as e:
258
region_info["usage_error"] = str(e)
259
260
# Check SKU restrictions for this region
261
for restriction in target_sku.restrictions:
262
if region in restriction.values:
263
region_info["restrictions"].append({
264
"type": restriction.type,
265
"reason": restriction.reason_code
266
})
267
268
availability[region] = region_info
269
270
return availability
271
272
# Example usage
273
regions = ["East US", "West US 2", "North Europe", "Southeast Asia"]
274
availability = check_service_availability(regions, "Standard_GRS")
275
276
for region, info in availability.items():
277
print(f"\n{region}:")
278
print(f" SKU Available: {info['sku_available']}")
279
if info.get('usage_info'):
280
usage = info['usage_info']
281
print(f" Capacity: {usage['available']}/{usage['limit']} available ({usage['utilization_pct']:.1f}% used)")
282
if info['restrictions']:
283
print(f" Restrictions: {len(info['restrictions'])}")
284
for restriction in info['restrictions']:
285
print(f" {restriction['type']}: {restriction['reason']}")
286
```
287
288
### API Operations Discovery
289
290
List all available REST API operations for the Azure Storage service.
291
292
```python { .api }
293
class Operations:
294
def list(self) -> ItemPaged[Operation]:
295
"""
296
Lists all of the available Storage REST API operations.
297
298
Returns:
299
ItemPaged[Operation]: Paginated list of available operations with metadata
300
"""
301
```
302
303
Usage example:
304
305
```python
306
# List all available storage operations
307
operations = list(client.operations.list())
308
309
print(f"Available operations: {len(operations)}")
310
for operation in operations[:5]: # Show first 5
311
print(f"- {operation.name}: {operation.display.description}")
312
print(f" Resource: {operation.display.resource}")
313
print(f" Provider: {operation.display.provider}")
314
```
315
316
## Types
317
318
```python { .api }
319
class SkuInformation:
320
"""Information about a storage SKU."""
321
name: SkuName
322
tier: SkuTier
323
resource_type: str
324
kind: Kind
325
locations: List[str]
326
capabilities: List[SKUCapability]
327
restrictions: List[Restriction]
328
329
class SKUCapability:
330
"""Capability of a storage SKU."""
331
name: str
332
value: str
333
334
class Restriction:
335
"""Restriction on SKU usage."""
336
type_: str
337
values: List[str]
338
reason_code: ReasonCode
339
340
class Usage:
341
"""Storage usage information."""
342
unit: UsageUnit
343
current_value: int
344
limit: int
345
name: UsageName
346
347
class UsageName:
348
"""Name of usage metric."""
349
value: str
350
localized_value: str
351
352
class DeletedAccount:
353
"""Deleted storage account information."""
354
id: str
355
name: str
356
type_: str
357
location: str
358
properties: DeletedAccountProperties
359
360
class DeletedAccountProperties:
361
"""Properties of deleted account."""
362
storage_account_type: str
363
creation_time: str
364
deletion_time: str
365
remaining_retention_days: int
366
367
class Operation:
368
"""Available API operation."""
369
name: str
370
display: OperationDisplay
371
origin: str
372
properties: Dict[str, Any]
373
374
class OperationDisplay:
375
"""Display information for operation."""
376
provider: str
377
resource: str
378
operation: str
379
description: str
380
381
class UsageUnit(str, Enum):
382
"""Unit for usage metrics."""
383
COUNT = "Count"
384
BYTES = "Bytes"
385
SECONDS = "Seconds"
386
PERCENT = "Percent"
387
COUNTS_PER_SECOND = "CountsPerSecond"
388
BYTES_PER_SECOND = "BytesPerSecond"
389
390
class ReasonCode(str, Enum):
391
"""Reason codes for restrictions."""
392
QUOTA_ID = "QuotaId"
393
NOT_AVAILABLE_FOR_SUBSCRIPTION = "NotAvailableForSubscription"
394
```