Microsoft Azure Storage Management Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
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.
Configure file service properties including SMB settings, protocol support, and CORS rules.
class FileServicesOperations:
def get_service_properties(
self,
resource_group_name: str,
account_name: str
) -> FileServiceProperties:
"""
Gets the properties of file services for the specified storage account.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
Returns:
FileServiceProperties with current configuration
"""
def set_service_properties(
self,
resource_group_name: str,
account_name: str,
parameters: FileServiceProperties
) -> FileServiceProperties:
"""
Sets the properties of file services for the specified storage account.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- parameters: File service properties to configure
Returns:
Updated FileServiceProperties
"""
def list(
self,
resource_group_name: str,
account_name: str
) -> FileServiceItems:
"""
Lists all file services for a storage account.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
Returns:
FileServiceItems containing file services
"""Usage example:
from azure.mgmt.storage.models import (
FileServiceProperties, ProtocolSettings, SmbSetting,
CorsRules, CorsRule
)
# Configure file service with SMB settings
smb_settings = SmbSetting(
versions=["SMB2.1", "SMB3.0", "SMB3.1.1"],
authentication_methods=["NTLMv2", "Kerberos"],
kerberos_ticket_encryption=["RC4-HMAC", "AES-256"],
channel_encryption=["AES-128-CCM", "AES-128-GCM", "AES-256-GCM"]
)
protocol_settings = ProtocolSettings(smb=smb_settings)
# Add CORS rules for web access
cors_rule = CorsRule(
allowed_origins=["https://portal.azure.com"],
allowed_methods=["GET", "HEAD", "POST", "PUT"],
allowed_headers=["*"],
exposed_headers=["*"],
max_age_in_seconds=7200
)
file_properties = FileServiceProperties(
properties=FileServicePropertiesProperties(
protocol_settings=protocol_settings,
cors=CorsRules(cors_rules=[cors_rule]),
share_delete_retention_policy=DeleteRetentionPolicy(
enabled=True,
days=7
)
)
)
updated_service = client.file_services.set_service_properties(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
parameters=file_properties
)Create, configure, and manage Azure file shares with quota settings, access tiers, and metadata.
class FileSharesOperations:
def create(
self,
resource_group_name: str,
account_name: str,
share_name: str,
file_share: FileShare,
expand: Optional[str] = None
) -> FileShare:
"""
Creates a new share under the specified account.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- share_name: Name of the file share (3-63 chars, lowercase)
- file_share: File share properties and configuration
- expand: Optional expansion of properties
Returns:
Created FileShare
"""
def update(
self,
resource_group_name: str,
account_name: str,
share_name: str,
file_share: FileShare
) -> FileShare:
"""
Updates share properties or metadata.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- share_name: Name of the file share
- file_share: Updated file share properties
Returns:
Updated FileShare
"""
def get(
self,
resource_group_name: str,
account_name: str,
share_name: str,
expand: Optional[str] = None,
x_ms_snapshot: Optional[str] = None
) -> FileShare:
"""
Gets properties of a specified share.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- share_name: Name of the file share
- expand: Optional expansion of properties
- x_ms_snapshot: Optional snapshot ID
Returns:
FileShare with properties
"""
def delete(
self,
resource_group_name: str,
account_name: str,
share_name: str,
x_ms_snapshot: Optional[str] = None,
include: Optional[str] = None
) -> None:
"""
Deletes the specified share and its contents.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- share_name: Name of the file share
- x_ms_snapshot: Optional snapshot ID to delete
- include: Include additional options like snapshots
"""
def list(
self,
resource_group_name: str,
account_name: str,
maxpagesize: Optional[str] = None,
filter: Optional[str] = None,
expand: Optional[str] = None
) -> ItemPaged[FileShareItem]:
"""
Lists all shares in a storage account.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- maxpagesize: Maximum number of results per page
- filter: OData filter expression
- expand: Expand additional properties
Returns:
Paginated list of FileShareItem objects
"""Usage example:
from azure.mgmt.storage.models import (
FileShare, ShareAccessTier, EnabledProtocols
)
# Create a standard file share
standard_share = FileShare(
properties=FileShareProperties(
share_quota=100, # 100 GB quota
access_tier=ShareAccessTier.TRANSACTION_OPTIMIZED,
metadata={"Department": "IT", "Purpose": "Shared Storage"}
)
)
created_share = client.file_shares.create(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
share_name="shared-files",
file_share=standard_share
)
# Create a premium file share with NFS protocol
premium_share = FileShare(
properties=FileShareProperties(
share_quota=500, # 500 GB quota
access_tier=ShareAccessTier.PREMIUM,
enabled_protocols=EnabledProtocols.NFS,
root_squash=RootSquashType.ROOT_SQUASH,
metadata={"Type": "Premium", "Protocol": "NFS"}
)
)
client.file_shares.create(
resource_group_name="my-resource-group",
account_name="mypremiumstorage",
share_name="nfs-share",
file_share=premium_share
)
# List all file shares
shares = list(client.file_shares.list(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
expand="stats"
))
for share in shares:
print(f"Share: {share.name}")
print(f" Quota: {share.share_quota} GB")
print(f" Access Tier: {share.access_tier}")
print(f" Protocol: {share.enabled_protocols}")
if hasattr(share, 'share_usage_bytes'):
print(f" Usage: {share.share_usage_bytes / (1024**3):.2f} GB")Create and manage file share snapshots for backup and restore scenarios.
def restore(
self,
resource_group_name: str,
account_name: str,
share_name: str,
restore: RestoreRestore
) -> None:
"""
Restore a file share from a snapshot.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- share_name: Name of the file share
- restore: Restore configuration specifying snapshot and restore details
"""Acquire and manage leases on file shares for exclusive access control.
def lease(
self,
resource_group_name: str,
account_name: str,
share_name: str,
parameters: LeaseShareRequest,
x_ms_snapshot: Optional[str] = None
) -> LeaseShareResponse:
"""
Lease a file share for delete and restore operations.
Parameters:
- resource_group_name: Name of the resource group
- account_name: Name of the storage account
- share_name: Name of the file share
- parameters: Lease operation parameters
- x_ms_snapshot: Optional snapshot ID
Returns:
LeaseShareResponse with lease information
"""Usage example:
from azure.mgmt.storage.models import (
LeaseShareRequest, LeaseShareAction
)
# Acquire a lease on file share
lease_request = LeaseShareRequest(
action=LeaseShareAction.ACQUIRE,
lease_duration=60 # seconds, -1 for infinite
)
lease_response = client.file_shares.lease(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
share_name="shared-files",
parameters=lease_request
)
print(f"Lease acquired: {lease_response.lease_id}")
# Break lease
break_request = LeaseShareRequest(
action=LeaseShareAction.BREAK,
lease_id=lease_response.lease_id
)
client.file_shares.lease(
resource_group_name="my-resource-group",
account_name="mystorageaccount123",
share_name="shared-files",
parameters=break_request
)class FileServiceProperties:
"""File service properties configuration."""
id: str
name: str
type_: str
properties: FileServicePropertiesProperties
class FileShare:
"""File share resource."""
id: str
name: str
type_: str
etag: str
properties: FileShareProperties
class FileShareProperties:
"""Properties of a file share."""
last_modified_time: datetime
share_quota: int
enabled_protocols: EnabledProtocols
root_squash: RootSquashType
version: str
deleted: bool
deleted_time: datetime
remaining_retention_days: int
access_tier: ShareAccessTier
access_tier_change_time: datetime
access_tier_status: str
share_usage_bytes: int
lease_status: LeaseStatus
lease_state: LeaseState
lease_duration: LeaseDuration
signed_identifiers: List[SignedIdentifier]
snapshot_time: datetime
metadata: Dict[str, str]
class FileShareItem:
"""File share item in list results."""
name: str
deleted: bool
version: str
properties: FileShareProperties
class ProtocolSettings:
"""Protocol settings for file service."""
smb: SmbSetting
class SmbSetting:
"""SMB protocol settings."""
versions: List[str]
authentication_methods: List[str]
kerberos_ticket_encryption: List[str]
channel_encryption: List[str]
multichannel: Multichannel
class ShareAccessTier(str, Enum):
"""File share access tiers."""
TRANSACTION_OPTIMIZED = "TransactionOptimized"
HOT = "Hot"
COOL = "Cool"
PREMIUM = "Premium"
class EnabledProtocols(str, Enum):
"""Enabled protocols for file share."""
SMB = "SMB"
NFS = "NFS"
class RootSquashType(str, Enum):
"""Root squash settings for NFS."""
NO_ROOT_SQUASH = "NoRootSquash"
ROOT_SQUASH = "RootSquash"
ALL_SQUASH = "AllSquash"
class LeaseShareAction(str, Enum):
"""File share lease actions."""
ACQUIRE = "Acquire"
RENEW = "Renew"
CHANGE = "Change"
RELEASE = "Release"
BREAK = "Break"Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-storage