다음을 통해 공유


Python을 사용하여 Azure Files을 개발합니다.

Azure Files를 사용하여 데이터를 저장하는 Python 애플리케이션을 개발하는 방법을 알아봅니다. Azure Files는 클라우드의 관리되는 파일 공유 서비스입니다. 업계 표준 SMB(서버 메시지 블록) 및 NFS(네트워크 파일 시스템) 프로토콜을 통해 액세스할 수 있는 완전히 관리되는 파일 공유를 제공합니다. 또한 Azure Files는 파일 공유에 프로그래밍 방식으로 액세스하기 위한 REST API를 제공합니다.

이 문서에서는 Python에서 Azure Files를 사용하여 개발하는 다양한 접근 방식과 앱의 요구 사항에 가장 적합한 방법을 선택하는 방법에 대해 알아봅니다. Azure Files 리소스와 상호 작용하는 기본 콘솔 앱을 만드는 방법도 알아봅니다.

적용 대상

관리 모델 청구 모델 미디어 계층 중복성 중소기업 네트워크 파일 시스템 (NFS)
Microsoft.Storage 프로비전된 v2 HDD(표준) 로컬(LRS) 예 아니요
Microsoft.Storage 프로비전된 v2 HDD(표준) 영역(ZRS) 예 아니요
Microsoft.Storage 프로비전된 v2 HDD(표준) 지역(GRS) 예 아니요
Microsoft.Storage 프로비전된 v2 HDD(표준) GeoZone(GZRS) 예 아니요
Microsoft.Storage 프로비전된 v1 SSD(프리미엄) 로컬(LRS) 예 아니요
Microsoft.Storage 프로비전된 v1 SSD(프리미엄) 영역(ZRS) 예 아니요
Microsoft.Storage 종량제 HDD(표준) 로컬(LRS) 예 아니요
Microsoft.Storage 종량제 HDD(표준) 영역(ZRS) 예 아니요
Microsoft.Storage 종량제 HDD(표준) 지역(GRS) 예 아니요
Microsoft.Storage 종량제 HDD(표준) GeoZone(GZRS) 예 아니요

Azure Files를 사용한 Python 앱 개발 정보

Azure Files는 Python 개발자가 Azure Files에서 데이터에 액세스하고 리소스를 관리하는 여러 가지 방법을 제공합니다. 다음 표에서는 접근 방식을 나열하고, 작동 방식을 요약하고, 각 방법을 사용하는 시기에 대한 지침을 제공합니다.

접근법 작동 방식 사용 시기
표준 파일 I/O 라이브러리 SMB 또는 NFS를 사용하여 탑재된 Azure 파일 공유를 통해 OS 수준 API 호출을 사용합니다. SMB/NFS를 사용하여 파일 공유를 탑재하는 경우 Python과 같은 osio 프로그래밍 언어 또는 프레임워크에 파일 I/O 라이브러리를 사용할 수 있습니다. 현재 표준 파일 I/O를 사용하는 기존 코드가 있는 업무용 앱이 있으며, 이 앱이 Azure 파일 공유와 호환되도록 코드를 다시 작성하지 않으려는 경우
FileREST API HTTPS 엔드포인트를 직접 호출하여 Azure Files에 저장된 데이터와 상호 작용합니다. 파일 공유 리소스에 대한 프로그래밍 방식 제어를 제공합니다. Azure SDK는 FileREST API를 기반으로 빌드되는 파일 공유 클라이언트 라이브러리(azure-storage-file-share)를 제공하여 친숙한 Python 프로그래밍 언어 패러다임을 통해 FileREST API 작업과 상호 작용할 수 있도록 합니다. 고객을 위해 부가 가치 클라우드 서비스 및 앱을 빌드하고 있으며 Python 파일 I/O 라이브러리를 통해 사용할 수 없는 고급 기능을 사용하려고 합니다.
스토리지 리소스 공급자 REST API ARM(Azure Resource Manager)을 사용하여 스토리지 계정 및 파일 공유를 관리합니다. 다양한 리소스 관리 작업을 위해 REST API 엔드포인트를 호출합니다. 앱 또는 서비스는 스토리지 계정 또는 파일 공유 만들기, 삭제 또는 업데이트와 같은 리소스 관리 작업을 수행해야 합니다.

이러한 접근 방식에 대한 일반적인 내용은 Azure Files를 사용한 애플리케이션 개발 개요를 참조하세요.

이 문서에서는 다음 방법을 사용하여 Azure Files 리소스를 사용하는 방법에 중점을 둡니다.

필수 조건

프로젝트 설정

이 섹션에서는 Azure Files를 사용할 프로젝트를 준비하는 방법을 안내합니다.

프로젝트 디렉터리에서 명령을 사용하여 pip install 앱의 요구 사항에 따라 패키지를 설치합니다. 다음 예제에서는 Azure 파일 공유 클라이언트 라이브러리, 스토리지 관리 클라이언트 라이브러리 및 Azure ID 라이브러리를 설치하는 방법을 보여 줍니다. Azure 서비스에 암호 없이 연결하려면 azure-identity 패키지가 필요합니다.

pip install azure-identity
pip install azure-storage-file-share
pip install azure-mgmt-resource
pip install azure-mgmt-storage

코드 파일을 열고 필요한 import 문을 추가합니다.

Python osio 라이브러리를 사용하려는 경우 .py 파일에 다음을 추가합니다.

import os
import io

Azure Storage 파일 공유 클라이언트 라이브러리를 사용하려는 경우 .py 파일에 다음을 추가합니다.

from azure.identity import DefaultAzureCredential
from azure.storage.fileshare import ShareClient, ShareDirectoryClient, ShareFileClient

Azure Storage 관리 라이브러리를 사용하려는 경우 .py 파일에 다음을 추가합니다.

from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storage import StorageManagementClient

Python 파일 I/O 라이브러리를 사용하여 Azure 파일과 작업하기

표준 파일 I/O 라이브러리는 Azure Files 리소스에 액세스하고 작업하는 가장 일반적인 방법입니다. SMB 또는 NFS를 사용하여 파일 공유를 탑재하면 운영 체제에서 로컬 파일 시스템에 대한 API 요청을 리디렉션합니다. 이 방법을 사용하면 표준 파일 I/O 라이브러리(예: os 또는 io)를 사용하여 공유의 파일 및 디렉터리와 상호 작용할 수 있습니다.

앱에 다음이 필요할 때 Python 파일 I/O 라이브러리를 사용하는 것이 좋습니다.

  • 앱 호환성: 이미 Python 파일 I/O 라이브러리를 사용하는 기존 코드가 있는 기간 업무 앱에 적합합니다. 앱이 Azure 파일 공유로 작동하도록 코드를 다시 작성할 필요가 없습니다.
  • 사용 편의성: Python 파일 I/O 라이브러리는 개발자가 잘 알고 있으며 사용하기 쉽습니다. Azure Files의 주요 가치 제안은 SMB 및 NFS를 통해 네이티브 파일 시스템 API를 노출한다는 것입니다.

이 섹션에서는 Python 파일 I/O 라이브러리를 사용하여 Azure Files 리소스를 사용하는 방법을 알아봅니다.

자세한 내용 및 예는 다음 리소스를 참조하세요.

  • 파일 I/O용 Python 라이브러리: osio

파일 공유 탑재

Python 파일 I/O 라이브러리를 사용하려면 먼저 파일 공유를 탑재해야 합니다. SMB 또는 NFS를 사용하여 파일 공유를 탑재하는 방법에 대한 지침은 다음 리소스를 참조하세요.

이 문서에서는 다음 경로를 사용하여 Windows에서 탑재된 SMB 파일 공유를 참조합니다.

file_share_path = "Z:\\file-share"

예: Python 파일 I/O 라이브러리를 사용하여 파일 공유에 연결하고 디렉터리를 열거합니다.

다음 코드 예제에서는 파일 공유에 연결하고 공유의 디렉터리를 나열하는 방법을 보여줍니다.

import os

def enumerate_directories(path):
    try:
        # Get all directories in the specified path
        dirs = [d for d in os.listdir(path) if os.path.isdir(os.path.join(path, d))]
        
        # Print each directory name
        for dir_name in dirs:
            print(f"{dir_name}")
            
        print(f"{len(dirs)} directories found.")
    except (PermissionError, FileNotFoundError, OSError) as ex:
        print(f"Error: {ex}")

#Example usage
file_share_path = "Z:\\file-share"
enumerate_directories(file_share_path)

예: Python 파일 I/O 라이브러리를 사용하여 파일 공유의 파일에 쓰기

다음 코드 예제에서는 파일에 텍스트를 쓰고 추가하는 방법을 보여 줍니다.

import os

def write_to_file(file_share_path, file_name):
    # First line of text with platform-appropriate line ending
    text_to_write = "First line" + os.linesep
    
    # Combine the file share path and filename
    file_path = os.path.join(file_share_path, file_name)
    
    # Write initial text to file (overwrites if file exists)
    with open(file_path, 'w') as file:
        file.write(text_to_write)
    
    # Text to append
    text_to_append = ["Second line", "Third line"]
    
    # Append lines to the file
    with open(file_path, 'a') as file:
        file.write(os.linesep.join(text_to_append) + os.linesep)

# Example usage
file_share_path = "Z:\\file-share"
write_to_file(file_share_path, "test.txt")

예: Python 파일 I/O 라이브러리를 사용하여 파일 ACL 열거

다음 코드 예제에서는 파일에 대한 기본 ACL(액세스 제어 목록)을 열거하는 방법을 보여 줍니다.

import os
import stat

def enumerate_file_acls(file_path):
    try:
        # Get file stats
        file_stat = os.stat(file_path)
        
        # Get permissions in octal format
        permissions_octal = oct(stat.S_IMODE(file_stat.st_mode))
        
        print(f"File: {file_path}")
        print(f"Permissions (octal): {permissions_octal}")
        
        # Interpret permissions in a human-readable format
        permissions = ""
        permissions += "r" if file_stat.st_mode & stat.S_IRUSR else "-"
        permissions += "w" if file_stat.st_mode & stat.S_IWUSR else "-"
        permissions += "x" if file_stat.st_mode & stat.S_IXUSR else "-"
        permissions += "r" if file_stat.st_mode & stat.S_IRGRP else "-"
        permissions += "w" if file_stat.st_mode & stat.S_IWGRP else "-" 
        permissions += "x" if file_stat.st_mode & stat.S_IXGRP else "-"
        permissions += "r" if file_stat.st_mode & stat.S_IROTH else "-"
        permissions += "w" if file_stat.st_mode & stat.S_IWOTH else "-"
        permissions += "x" if file_stat.st_mode & stat.S_IXOTH else "-"
        
        print(f"Permissions (symbolic): {permissions}")
        
        print(f"Owner ID: {file_stat.st_uid}")
        print(f"Group ID: {file_stat.st_gid}")
        print("Note: For detailed Windows ACLs, you may need a specialized library.")
        
    except FileNotFoundError:
        print(f"Error: File '{file_path}' not found.")
    except PermissionError:
        print(f"Error: Permission denied for '{file_path}'.")
    except Exception as e:
        print(f"Error: {e}")

# Example usage
file_share_path = "Z:\\file-share"
file_name = "test.txt"
file_path = os.path.join(file_share_path, file_name)

enumerate_file_acls(file_path)

Python용 파일 공유 클라이언트 라이브러리를 사용하여 Azure Files 데이터 작업

FileREST API는 Azure Files에 프로그래밍 방식으로 액세스할 수 있도록 합니다. 이를 통해 HTTPS 엔드포인트를 호출하여 파일 공유, 디렉터리 및 파일에 대한 작업을 수행할 수 있습니다. FileREST API는 네이티브 프로토콜을 통해 사용할 수 없는 높은 확장성 및 고급 기능을 위해 설계되었습니다. Azure SDK는 FileREST API를 기반으로 하는 Python용 파일 공유 클라이언트 라이브러리와 같은 클라이언트 라이브러리를 제공합니다.

애플리케이션에 다음이 필요한 경우 FileREST API 및 파일 공유 클라이언트 라이브러리를 사용하는 것이 좋습니다.

  • 고급 기능: 네이티브 프로토콜을 통해 사용할 수 없는 작업 및 기능에 액세스합니다.
  • 사용자 지정 클라우드 통합: Azure Files와 직접 상호 작용하는 백업, 바이러스 백신 또는 데이터 관리와 같은 사용자 지정 부가 가치 서비스를 빌드합니다.
  • 성능 최적화: 데이터 평면 작업을 사용하는 대규모 시나리오의 성능 이점을 활용할 수 있습니다.

FileREST API는 Azure Files를 리소스 계층 구조로 모델화하며 디렉터리 또는 파일 수준에서 수행되는 작업에 권장됩니다. 파일 서비스 또는 파일 공유 수준에서 수행되는 작업에 스토리지 리소스 공급자 REST API를 사용하는 것이 좋습니다.

이 섹션에서는 파일 공유 클라이언트 라이브러리를 사용하여 Azure Files 리소스를 사용하는 방법을 알아봅니다.

자세한 내용 및 예는 다음 리소스를 참조하세요.

액세스 권한 부여 및 클라이언트 만들기

Azure Files에 앱을 연결하려면 개체를 만듭니다 ShareClient . 이 개체는 Azure Files 리소스를 사용하기 위한 시작점입니다. 다음 코드 예제에서는 다른 권한 부여 메커니즘을 사용 하 여 개체를 ShareClient 만드는 방법을 보여 줍니다.

Microsoft Entra ID로 권한을 부여하려면 보안 주체를 사용해야 합니다. 필요한 보안 주체의 유형은 앱이 실행되는 위치에 따라 달라집니다. 이 표를 가이드로 참조하세요.

앱이 실행되는 곳 보안 주체 안내
로컬 컴퓨터(개발 및 테스트) 서비스 주체 앱 등록, Microsoft Entra 그룹 설정, 역할 할당, 환경 변수 구성 방법을 알아보려면 개발자 서비스 주체를 사용하여 액세스 권한 부여를 참조하세요.
로컬 컴퓨터(개발 및 테스트) 사용자 ID Microsoft Entra 그룹을 설정하고, 역할을 할당하고, Azure에 로그인하는 방법을 알아보려면 개발자 자격 증명을 사용하여 액세스 권한 부여를 참조하세요.
Azure에서 호스트 관리형 아이덴티티 관리 ID를 사용 설정하고 역할을 할당하는 방법을 알아보려면 관리 ID를 사용하여 Azure 호스트된 앱에서 액세스 권한 부여를 참조하세요.
Azure 외부에서 호스트됨(예: 온-프레미스 앱) 서비스 주체 앱을 등록하고, 역할을 할당하고, 환경 변수를 구성하는 방법을 알아보려면 애플리케이션 서비스 주체를 사용하여 온-프레미스 앱에서 액세스 권한 부여를 참조하세요.

이 문서의 코드 예제를 사용하려면 Azure RBAC 기본 제공 역할 스토리지 파일 데이터 권한 있는 기여자를 보안 주체에 할당합니다. 이 역할은 설정된 파일/디렉터리 수준 NTFS 권한에 관계없이 구성된 모든 스토리지 계정에 대한 공유의 모든 데이터에 대한 전체 읽기, 쓰기, 수정 및 삭제 액세스를 제공합니다. 자세한 내용은 REST를 통해 Azure Files OAuth와 함께 Microsoft Entra ID를 사용하여 Azure 파일 공유에 액세스하세요.

DefaultAzureCredential을 사용하여 액세스 권한 부여

액세스 권한을 부여하고 Azure Files에 연결하는 쉽고 안전한 방법은 DefaultAzureCredential 인스턴스를 만들어 OAuth 토큰을 가져오는 것입니다. 그런 다음 해당 자격 증명을 사용하여 ShareClient 개체를 만들 수 있습니다.

다음 예에서는 ShareClient을 사용하여 권한이 있는 DefaultAzureCredential 개체를 만든 다음 공유의 디렉터리와 함께 작동할 ShareDirectoryClient 개체를 만듭니다.

from azure.identity import DefaultAzureCredential
from azure.storage.fileshare import ShareClient

account_name = "<account-name>"
share_name = "<share-name>"

# Create the share client using DefaultAzureCredential
share_client = ShareClient(
    account_url=f"https://{account_name}.file.core.windows.net",
    share_name=share_name,
    credential=DefaultAzureCredential(),
    # When using a token credential, you MUST specify a token_intent
    token_intent='backup'
)

# Get a reference to a directory in the share
directory_client = share_client.get_directory_client("sample-directory")

사용자를 인증하는 데 사용하는 자격 증명 유형을 정확히 알고 있는 경우 Python용 Azure ID 클라이언트 라이브러리의 다른 클래스를 사용하여 OAuth 토큰을 얻을 수 있습니다. 이러한 클래스는 TokenCredential 클래스에서 파생됩니다.

이러한 각 권한 부여 메커니즘에 대한 자세한 내용은 파일 데이터에 대한 액세스 권한을 부여하는 방법 선택을 참조하세요.

예: 파일 공유 클라이언트 라이브러리를 사용하여 파일 복사

다음 방법을 사용하여 파일 공유 내 또는 파일 공유 간에 파일을 복사할 수 있습니다.

BlobClient 개체에서 다음 메서드를 사용하여 파일을 대상 Blob에 복사할 수 있습니다.

다음 코드 예제에서는 다른 파일 공유의 파일에 파일을 복사하는 방법을 보여줍니다.

from azure.identity import DefaultAzureCredential
from azure.storage.fileshare import ShareFileClient

# Define storage account parameters
account_name = "<account-name>"
src_share_name = "src-file-share"
dest_share_name = "dest-file-share"
src_file_path = "src/path/to/file"
dest_file_path = "dest/path/to/file"

# Create token credential
token_credential = DefaultAzureCredential()

# Create source file client
src_file_client = ShareFileClient(
    account_url=f"https://{account_name}.file.core.windows.net",
    share_name=src_share_name,
    file_path=src_file_path,
    credential=token_credential,
    token_intent='backup'
)

# Create destination file client
dest_file_client = ShareFileClient(
    account_url=f"https://{account_name}.file.core.windows.net",
    share_name=dest_share_name,
    file_path=dest_file_path,
    credential=token_credential,
    token_intent='backup'
)

# Copy the file from the source share to the destination share
copy_operation = dest_file_client.start_copy_from_url(src_file_client.url)

예: 파일 공유 클라이언트 라이브러리를 사용하여 파일 임대

임대는 임대 ID를 통해 Azure에서 관리하는 파일에 대한 잠금을 만듭니다. 임대는 분산 시스템의 여러 클라이언트에서 파일에 대한 액세스를 조정하는 메커니즘을 제공합니다. 파일에 대한 임대는 단독 쓰기 및 삭제 액세스를 제공합니다. 임대 상태 및 작업에 대한 자세한 내용은 임대 파일을 참조하세요.

다음 코드 예제에서는 임대 클라이언트를 만들고, 파일에서 무한 기간 임대를 획득하고, 임대를 해제하는 방법을 보여줍니다.

from azure.identity import DefaultAzureCredential
from azure.storage.fileshare import ShareFileClient, ShareLeaseClient

# Define storage account parameters
account_name = "<account-name>"
share_name = "sample-file-share"
file_path = "path/to/file"

# Create a DefaultAzureCredential for authentication
token_credential = DefaultAzureCredential()

# Create a ShareFileClient
file_client = ShareFileClient(
    account_url=f"https://{account_name}.file.core.windows.net",
    share_name=share_name,
    file_path=file_path,
    credential=token_credential,
    token_intent='backup'
)

# Get a lease client for the file
lease_client = ShareLeaseClient(file_client)

# Acquire an infinite duration lease on the file
lease_info = lease_client.acquire()

# Do something with the file while it's leased
# ...

# Release the lease
lease_client.release()

SMB 및 FileREST API를 모두 사용하는 경우 FileREST API는 임대 를 사용하여 파일 잠금을 관리하는 반면 SMB는 운영 체제에서 관리하는 파일 시스템 잠금을 사용합니다. SMB와 FileREST API 간의 파일 잠금 상호 작용을 관리하는 방법에 대한 자세한 내용은 파일 잠금 관리를 참조하세요.

예: 파일 공유 클라이언트 라이브러리를 사용하여 공유 스냅샷 만들기 및 나열

공유 스냅샷은 특정 시점에 파일 공유의 읽기 전용 복사본입니다. 파일 공유의 스냅샷을 만든 다음 스냅샷을 사용하여 스냅샷을 만들 때 공유의 데이터에 액세스할 수 있습니다. 파일 공유의 모든 스냅샷을 나열하고 공유 스냅샷을 삭제할 수도 있습니다.

다음 코드 예제에서는 공유 스냅샷을 만들고, 파일 공유의 스냅샷을 나열하고, 공유 스냅샷의 루트 디렉터리를 트래버스하는 방법을 보여 줍니다.

from azure.storage.fileshare import ShareServiceClient, ShareDirectoryClient

def list_root_directory_snapshot(root_dir: ShareDirectoryClient):
    for item in root_dir.list_directories_and_files():
        if item["is_directory"]:
            print(f"Directory in snapshot: {item['name']}")
        else:
            print(f"File in snapshot: {item['name']}")

# Connection string with account key (required for share snapshots)
connection_string = "<connection-string>"

# Create service and share clients
share_service_client = ShareServiceClient.from_connection_string(connection_string)
share_name = "sample-file-share"
share_client = share_service_client.get_share_client(share_name)

# Create a snapshot
snapshot_info = share_client.create_snapshot()
print(f"Snapshot created: {snapshot_info['snapshot']}")

# List snapshots in a share
for share_item in share_service_client.list_shares(include_snapshots=True):
    if share_item["snapshot"]:
        print(f"Share: {share_item['name']} (Snapshot: {share_item['snapshot']})")

# List directories and files in a share snapshot
snapshot_timestamp = snapshot_info["snapshot"]
share_snapshot = share_service_client.get_share_client(share_name, snapshot=snapshot_timestamp)
root_dir = share_snapshot.get_directory_client("")

list_root_directory_snapshot(root_dir)

비고

OAuth 토큰(예: 사용 DefaultAzureCredential시 가져온 토큰)은 파일 공유 수준에서 데이터 평면 작업에 허용되지 않습니다. 공유 스냅샷을 사용하려면 계정 키를 사용하여 클라이언트 개체에 권한을 부여해야 합니다. 이 코드 예제에서 만든 개체는 ShareClient 계정 키를 포함하는 연결 문자열을 사용합니다.

계정 키 또는 연결 문자열을 저장하면 보안 위험이 발생합니다. Microsoft Entra 인증을 사용할 수 없는 경우에만 사용해야 합니다. Azure Key Vault에 계정 키를 안전하게 저장하는 방법에 대한 자세한 내용은 Azure Key Vault 관리 스토리지 계정 키에 대해 참조하세요.

Azure Storage 관리 라이브러리를 사용하여 Azure Files 리소스 관리

Azure Storage 관리 라이브러리는 Azure Storage 리소스 공급자 REST API를 기반으로 합니다. Azure Storage 리소스 공급자는 Azure Resource Manager를 기반으로 하는 서비스이며 선언적(템플릿) 및 명령적(직접 API 호출) 메서드를 모두 지원합니다. Azure Storage 리소스 공급자 REST API는 파일 공유를 포함하여 Azure Storage 리소스에 프로그래밍 방식으로 액세스할 수 있도록 합니다. Azure SDK는 Azure Storage 리소스 공급자 REST API를 기반으로 빌드되는 관리 라이브러리를 제공합니다.

관리 라이브러리는 파일 서비스 또는 파일 공유 수준에서 수행되는 작업에 권장됩니다. 이 섹션에서는 Azure Storage 관리 라이브러리를 사용하여 Azure Files 리소스를 관리하는 방법을 알아봅니다.

예: Azure Storage 관리 라이브러리를 사용하여 파일 공유 만들기

다음 코드 예제에서는 최상위 ArmClient 개체를 만들고, Storage 리소스 공급자를 구독에 등록하고, Azure Storage 관리 라이브러리를 사용하여 파일 공유를 만드는 방법을 보여 줍니다.

from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient, SubscriptionClient
from azure.mgmt.storage import StorageManagementClient
from azure.mgmt.storage.models import FileShare

# Create the credential for authentication
credential = DefaultAzureCredential()

# Define variables
subscription_id = "<subscription-id>"
resource_group_name = "<resource-group-name>"
storage_account_name = "<storage-account-name>"
share_name = "sample-file-share"

# Create clients
resource_client = ResourceManagementClient(credential, subscription_id)
subscription_client = SubscriptionClient(credential)
storage_client = StorageManagementClient(credential, subscription_id)

# Register Microsoft.Storage resource provider, if not already registered
provider = resource_client.providers.get('Microsoft.Storage')
if provider.registration_state == "NotRegistered":
    resource_client.providers.register('Microsoft.Storage')

# Create a file share
file_share = storage_client.file_shares.create(
    resource_group_name=resource_group_name,
    account_name=storage_account_name,
    share_name=share_name,
    file_share=FileShare(
        share_quota=1  # Share size in GiB
        # Add other file share properties here
    )
)

클래스를 사용하여 FileShare 파일 공유 속성을 구성할 수 있습니다. 이전 예제에서는 속성을 설정하는 share_quota 방법을 보여줍니다. 자세한 내용은 StorageManagementClient 클래스 참조를 참조하세요.

비고

등록 작업을 수행하려면 다음 Azure RBAC 작업에 대한 권한이 필요합니다. Microsoft.Storage/register/action. 이 권한은 기여자 및 소유자 기본 제공 역할에 포함됩니다.

예: Azure Storage 관리 라이브러리를 사용하여 파일 공유 및 스냅샷 나열

다음 코드 예제에서는 스토리지 계정에서 파일 공유 및 스냅샷을 나열하는 방법을 보여 줍니다.

from azure.identity import DefaultAzureCredential
from azure.mgmt.storage import StorageManagementClient

# Create the credential for authentication
credential = DefaultAzureCredential()

# Define variables
subscription_id = "<subscription-id>"
resource_group_name = "<resource-group-name>"
storage_account_name = "<storage-account-name>"
expand = "snapshots"  # Include snapshots in the response

# Create storage management client
storage_client = StorageManagementClient(credential, subscription_id)

# List all file shares with their snapshots
file_shares = storage_client.file_shares.list(
    resource_group_name=resource_group_name,
    account_name=storage_account_name,
    expand=expand
)

# Iterate over the file shares and print them along with any snapshots
for share in file_shares:
    print(f"Resource name: {share.name}")
    if share.snapshot_time:
        print(f"Snapshot: {share.snapshot_time}")

Azure Files를 사용하여 개발하는 방법에 대한 자세한 내용은 다음 리소스를 참조하세요.