0
# File Storage Management
1
2
Azure Files service and file share management including SMB/NFS configuration, access tier management, and snapshot operations. Azure Files provides fully managed file shares in the cloud accessible via SMB and NFS protocols.
3
4
## Capabilities
5
6
### File Service Configuration
7
8
Configure file service properties including SMB settings, protocol support, and CORS rules.
9
10
```python { .api }
11
class FileServicesOperations:
12
def get_service_properties(
13
self,
14
resource_group_name: str,
15
account_name: str
16
) -> FileServiceProperties:
17
"""
18
Gets the properties of file services for the specified storage account.
19
20
Parameters:
21
- resource_group_name: Name of the resource group
22
- account_name: Name of the storage account
23
24
Returns:
25
FileServiceProperties with current configuration
26
"""
27
28
def set_service_properties(
29
self,
30
resource_group_name: str,
31
account_name: str,
32
parameters: FileServiceProperties
33
) -> FileServiceProperties:
34
"""
35
Sets the properties of file services for the specified storage account.
36
37
Parameters:
38
- resource_group_name: Name of the resource group
39
- account_name: Name of the storage account
40
- parameters: File service properties to configure
41
42
Returns:
43
Updated FileServiceProperties
44
"""
45
46
def list(
47
self,
48
resource_group_name: str,
49
account_name: str
50
) -> FileServiceItems:
51
"""
52
Lists all file services for a storage account.
53
54
Parameters:
55
- resource_group_name: Name of the resource group
56
- account_name: Name of the storage account
57
58
Returns:
59
FileServiceItems containing file services
60
"""
61
```
62
63
Usage example:
64
65
```python
66
from azure.mgmt.storage.models import (
67
FileServiceProperties, ProtocolSettings, SmbSetting,
68
CorsRules, CorsRule
69
)
70
71
# Configure file service with SMB settings
72
smb_settings = SmbSetting(
73
versions=["SMB2.1", "SMB3.0", "SMB3.1.1"],
74
authentication_methods=["NTLMv2", "Kerberos"],
75
kerberos_ticket_encryption=["RC4-HMAC", "AES-256"],
76
channel_encryption=["AES-128-CCM", "AES-128-GCM", "AES-256-GCM"]
77
)
78
79
protocol_settings = ProtocolSettings(smb=smb_settings)
80
81
# Add CORS rules for web access
82
cors_rule = CorsRule(
83
allowed_origins=["https://portal.azure.com"],
84
allowed_methods=["GET", "HEAD", "POST", "PUT"],
85
allowed_headers=["*"],
86
exposed_headers=["*"],
87
max_age_in_seconds=7200
88
)
89
90
file_properties = FileServiceProperties(
91
properties=FileServicePropertiesProperties(
92
protocol_settings=protocol_settings,
93
cors=CorsRules(cors_rules=[cors_rule]),
94
share_delete_retention_policy=DeleteRetentionPolicy(
95
enabled=True,
96
days=7
97
)
98
)
99
)
100
101
updated_service = client.file_services.set_service_properties(
102
resource_group_name="my-resource-group",
103
account_name="mystorageaccount123",
104
parameters=file_properties
105
)
106
```
107
108
### File Share Management
109
110
Create, configure, and manage Azure file shares with quota settings, access tiers, and metadata.
111
112
```python { .api }
113
class FileSharesOperations:
114
def create(
115
self,
116
resource_group_name: str,
117
account_name: str,
118
share_name: str,
119
file_share: FileShare,
120
expand: Optional[str] = None
121
) -> FileShare:
122
"""
123
Creates a new share under the specified account.
124
125
Parameters:
126
- resource_group_name: Name of the resource group
127
- account_name: Name of the storage account
128
- share_name: Name of the file share (3-63 chars, lowercase)
129
- file_share: File share properties and configuration
130
- expand: Optional expansion of properties
131
132
Returns:
133
Created FileShare
134
"""
135
136
def update(
137
self,
138
resource_group_name: str,
139
account_name: str,
140
share_name: str,
141
file_share: FileShare
142
) -> FileShare:
143
"""
144
Updates share properties or metadata.
145
146
Parameters:
147
- resource_group_name: Name of the resource group
148
- account_name: Name of the storage account
149
- share_name: Name of the file share
150
- file_share: Updated file share properties
151
152
Returns:
153
Updated FileShare
154
"""
155
156
def get(
157
self,
158
resource_group_name: str,
159
account_name: str,
160
share_name: str,
161
expand: Optional[str] = None,
162
x_ms_snapshot: Optional[str] = None
163
) -> FileShare:
164
"""
165
Gets properties of a specified share.
166
167
Parameters:
168
- resource_group_name: Name of the resource group
169
- account_name: Name of the storage account
170
- share_name: Name of the file share
171
- expand: Optional expansion of properties
172
- x_ms_snapshot: Optional snapshot ID
173
174
Returns:
175
FileShare with properties
176
"""
177
178
def delete(
179
self,
180
resource_group_name: str,
181
account_name: str,
182
share_name: str,
183
x_ms_snapshot: Optional[str] = None,
184
include: Optional[str] = None
185
) -> None:
186
"""
187
Deletes the specified share and its contents.
188
189
Parameters:
190
- resource_group_name: Name of the resource group
191
- account_name: Name of the storage account
192
- share_name: Name of the file share
193
- x_ms_snapshot: Optional snapshot ID to delete
194
- include: Include additional options like snapshots
195
"""
196
197
def list(
198
self,
199
resource_group_name: str,
200
account_name: str,
201
maxpagesize: Optional[str] = None,
202
filter: Optional[str] = None,
203
expand: Optional[str] = None
204
) -> ItemPaged[FileShareItem]:
205
"""
206
Lists all shares in a storage account.
207
208
Parameters:
209
- resource_group_name: Name of the resource group
210
- account_name: Name of the storage account
211
- maxpagesize: Maximum number of results per page
212
- filter: OData filter expression
213
- expand: Expand additional properties
214
215
Returns:
216
Paginated list of FileShareItem objects
217
"""
218
```
219
220
Usage example:
221
222
```python
223
from azure.mgmt.storage.models import (
224
FileShare, ShareAccessTier, EnabledProtocols
225
)
226
227
# Create a standard file share
228
standard_share = FileShare(
229
properties=FileShareProperties(
230
share_quota=100, # 100 GB quota
231
access_tier=ShareAccessTier.TRANSACTION_OPTIMIZED,
232
metadata={"Department": "IT", "Purpose": "Shared Storage"}
233
)
234
)
235
236
created_share = client.file_shares.create(
237
resource_group_name="my-resource-group",
238
account_name="mystorageaccount123",
239
share_name="shared-files",
240
file_share=standard_share
241
)
242
243
# Create a premium file share with NFS protocol
244
premium_share = FileShare(
245
properties=FileShareProperties(
246
share_quota=500, # 500 GB quota
247
access_tier=ShareAccessTier.PREMIUM,
248
enabled_protocols=EnabledProtocols.NFS,
249
root_squash=RootSquashType.ROOT_SQUASH,
250
metadata={"Type": "Premium", "Protocol": "NFS"}
251
)
252
)
253
254
client.file_shares.create(
255
resource_group_name="my-resource-group",
256
account_name="mypremiumstorage",
257
share_name="nfs-share",
258
file_share=premium_share
259
)
260
261
# List all file shares
262
shares = list(client.file_shares.list(
263
resource_group_name="my-resource-group",
264
account_name="mystorageaccount123",
265
expand="stats"
266
))
267
268
for share in shares:
269
print(f"Share: {share.name}")
270
print(f" Quota: {share.share_quota} GB")
271
print(f" Access Tier: {share.access_tier}")
272
print(f" Protocol: {share.enabled_protocols}")
273
if hasattr(share, 'share_usage_bytes'):
274
print(f" Usage: {share.share_usage_bytes / (1024**3):.2f} GB")
275
```
276
277
### File Share Snapshots
278
279
Create and manage file share snapshots for backup and restore scenarios.
280
281
```python { .api }
282
def restore(
283
self,
284
resource_group_name: str,
285
account_name: str,
286
share_name: str,
287
restore: RestoreRestore
288
) -> None:
289
"""
290
Restore a file share from a snapshot.
291
292
Parameters:
293
- resource_group_name: Name of the resource group
294
- account_name: Name of the storage account
295
- share_name: Name of the file share
296
- restore: Restore configuration specifying snapshot and restore details
297
"""
298
```
299
300
### File Share Leasing
301
302
Acquire and manage leases on file shares for exclusive access control.
303
304
```python { .api }
305
def lease(
306
self,
307
resource_group_name: str,
308
account_name: str,
309
share_name: str,
310
parameters: LeaseShareRequest,
311
x_ms_snapshot: Optional[str] = None
312
) -> LeaseShareResponse:
313
"""
314
Lease a file share for delete and restore operations.
315
316
Parameters:
317
- resource_group_name: Name of the resource group
318
- account_name: Name of the storage account
319
- share_name: Name of the file share
320
- parameters: Lease operation parameters
321
- x_ms_snapshot: Optional snapshot ID
322
323
Returns:
324
LeaseShareResponse with lease information
325
"""
326
```
327
328
Usage example:
329
330
```python
331
from azure.mgmt.storage.models import (
332
LeaseShareRequest, LeaseShareAction
333
)
334
335
# Acquire a lease on file share
336
lease_request = LeaseShareRequest(
337
action=LeaseShareAction.ACQUIRE,
338
lease_duration=60 # seconds, -1 for infinite
339
)
340
341
lease_response = client.file_shares.lease(
342
resource_group_name="my-resource-group",
343
account_name="mystorageaccount123",
344
share_name="shared-files",
345
parameters=lease_request
346
)
347
348
print(f"Lease acquired: {lease_response.lease_id}")
349
350
# Break lease
351
break_request = LeaseShareRequest(
352
action=LeaseShareAction.BREAK,
353
lease_id=lease_response.lease_id
354
)
355
356
client.file_shares.lease(
357
resource_group_name="my-resource-group",
358
account_name="mystorageaccount123",
359
share_name="shared-files",
360
parameters=break_request
361
)
362
```
363
364
## Types
365
366
```python { .api }
367
class FileServiceProperties:
368
"""File service properties configuration."""
369
id: str
370
name: str
371
type_: str
372
properties: FileServicePropertiesProperties
373
374
class FileShare:
375
"""File share resource."""
376
id: str
377
name: str
378
type_: str
379
etag: str
380
properties: FileShareProperties
381
382
class FileShareProperties:
383
"""Properties of a file share."""
384
last_modified_time: datetime
385
share_quota: int
386
enabled_protocols: EnabledProtocols
387
root_squash: RootSquashType
388
version: str
389
deleted: bool
390
deleted_time: datetime
391
remaining_retention_days: int
392
access_tier: ShareAccessTier
393
access_tier_change_time: datetime
394
access_tier_status: str
395
share_usage_bytes: int
396
lease_status: LeaseStatus
397
lease_state: LeaseState
398
lease_duration: LeaseDuration
399
signed_identifiers: List[SignedIdentifier]
400
snapshot_time: datetime
401
metadata: Dict[str, str]
402
403
class FileShareItem:
404
"""File share item in list results."""
405
name: str
406
deleted: bool
407
version: str
408
properties: FileShareProperties
409
410
class ProtocolSettings:
411
"""Protocol settings for file service."""
412
smb: SmbSetting
413
414
class SmbSetting:
415
"""SMB protocol settings."""
416
versions: List[str]
417
authentication_methods: List[str]
418
kerberos_ticket_encryption: List[str]
419
channel_encryption: List[str]
420
multichannel: Multichannel
421
422
class ShareAccessTier(str, Enum):
423
"""File share access tiers."""
424
TRANSACTION_OPTIMIZED = "TransactionOptimized"
425
HOT = "Hot"
426
COOL = "Cool"
427
PREMIUM = "Premium"
428
429
class EnabledProtocols(str, Enum):
430
"""Enabled protocols for file share."""
431
SMB = "SMB"
432
NFS = "NFS"
433
434
class RootSquashType(str, Enum):
435
"""Root squash settings for NFS."""
436
NO_ROOT_SQUASH = "NoRootSquash"
437
ROOT_SQUASH = "RootSquash"
438
ALL_SQUASH = "AllSquash"
439
440
class LeaseShareAction(str, Enum):
441
"""File share lease actions."""
442
ACQUIRE = "Acquire"
443
RENEW = "Renew"
444
CHANGE = "Change"
445
RELEASE = "Release"
446
BREAK = "Break"
447
```