Python을 사용한 Azure Data Lake Storage Gen1에서의 계정 관리 작업

Azure Data Lake Storage Gen1용 Python SDK를 사용하여 Data Lake Storage Gen1 계정 만들기, Data Lake Storage Gen1 계정 나열 등과 같은 기본 계정 관리 작업을 수행하는 방법을 알아봅니다. Python을 사용하여 Data Lake Storage Gen1에서 파일 시스템 작업을 수행하는 방법에 대한 지침은 Python을 사용한 Data Lake Storage Gen1의 파일 시스템 작업을 참조하세요.

필수 구성 요소

  • Python. Python을 여기에서 다운로드할 수 있습니다. 이 문서에서는 Python 3.6.2를 사용합니다.

  • Azure 구독. Azure 평가판을 참조하세요.

  • Azure 리소스 그룹 지침에 대해서는 Azure 리소스 그룹 만들기를 참조하세요.

모듈 설치

Python을 통해 Data Lake Storage Gen1을 사용하려면 세 가지 모듈을 설치해야 합니다.

  • Active Directory 등 Azure 모듈을 포함하는 azure-mgmt-resource 모듈.
  • Azure Data Lake Storage Gen1 계정 관리 작업을 포함하는 azure-mgmt-datalake-store 모듈. 이 모듈에 대한 자세한 내용은 Azure Data Lake Storage Gen1 관리 모듈 참조를 참조하세요.
  • Azure Data Lake Storage Gen1 파일 시스템 작업을 포함하는 azure-datalake-store 모듈. 이 모듈에 대한 자세한 내용은 azure-datalake-store 파일 시스템 모듈 참조를 참조하세요.

다음 명령을 사용하여 모듈을 설치합니다.

pip install azure-identity
pip install azure-mgmt-resource
pip install azure-mgmt-datalake-store
pip install azure-datalake-store

새 Python 애플리케이션 만들기

  1. 원하는 IDE에서 mysample.py와 같이 새 Python 애플리케이션을 만듭니다.

  2. 다음 코드 조각을 추가하여 필요한 모듈을 가져옵니다.

    # Acquire a credential object for the app identity. When running in the cloud,
    # DefaultAzureCredential uses the app's managed identity (MSI) or user-assigned service principal.
    # When run locally, DefaultAzureCredential relies on environment variables named
    # AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID.
    from azure.identity import DefaultAzureCredential
    
    ## Required for Data Lake Storage Gen1 account management
    from azure.mgmt.datalake.store import DataLakeStoreAccountManagementClient
    from azure.mgmt.datalake.store.models import CreateDataLakeStoreAccountParameters
    
    ## Required for Data Lake Storage Gen1 filesystem management
    from azure.datalake.store import core, lib, multithread
    
    # Common Azure imports
    import adal
    from azure.mgmt.resource.resources import ResourceManagementClient
    from azure.mgmt.resource.resources.models import ResourceGroup
    
    # Use these as needed for your application
    import logging, getpass, pprint, uuid, time
    
  3. mysample.py의 변경 내용을 저장합니다.

인증

이 섹션에서는 Microsoft Entra ID 인증하는 다양한 방법에 대해 설명합니다. 제공되는 옵션은 다음과 같습니다.

클라이언트 및 Data Lake Storage Gen1 계정 만들기

다음 코드 조각은 Data Lake Storage Gen1 계정 클라이언트를 먼저 만듭니다. 클라이언트 개체를 사용하여 Data Lake Storage Gen1 계정을 만듭니다. 마지막으로 코드 조각은 파일 시스템 클라이언트 개체를 만듭니다.

## Declare variables
subscriptionId = 'FILL-IN-HERE'
adlsAccountName = 'FILL-IN-HERE'
resourceGroup = 'FILL-IN-HERE'
location = 'eastus2'
credential = DefaultAzureCredential()

## Create Data Lake Storage Gen1 account management client object
adlsAcctClient = DataLakeStoreAccountManagementClient(credential, subscription_id=subscriptionId)

## Create a Data Lake Storage Gen1 account
adlsAcctResult = adlsAcctClient.accounts.begin_create(
    resourceGroup,
    adlsAccountName,
    CreateDataLakeStoreAccountParameters(
        location=location
    )
)

Data Lake Storage Gen1 계정 나열

## List the existing Data Lake Storage Gen1 accounts
result_list_response = adlsAcctClient.accounts.list()
result_list = list(result_list_response)
for items in result_list:
    print(items)

Data Lake Storage Gen1 계정 삭제

## Delete an existing Data Lake Storage Gen1 account
adlsAcctClient.accounts.begin_delete(resourceGroup, adlsAccountName)

다음 단계

참고 항목