Operazioni di gestione di account in Azure Data Lake Store con PythonAccount management operations on Azure Data Lake Store using Python

Informazioni su come usare Python SDK per Azure Data Lake Store per eseguire operazioni di gestione di account di base, ad esempio creare un account Data Lake Store, elencare gli account Data Lake Store e così via. Per istruzioni su come eseguire le operazioni del file system in Data Lake Store con Python, vedere Operazioni del file system in Data Lake Store con Python.Learn how to use the Python SDK for Azure Data Lake Store to perform basic account management operations such as create Data Lake Store account, list Data Lake Store account, etc. For instructions on how to perform filesystem operations on Data Lake Store using Python, see Filesystem operations on Data Lake Store using Python.

prerequisitiPrerequisites

Installare i moduliInstall the modules

Per gestire Data Lake Store usando Python, è necessario installare tre moduli.To work with Data Lake Store using Python, you need to install three modules.

Per installare i moduli, usare i comandi seguenti.Use the following commands to install the modules.

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

Creare una nuova applicazione PythonCreate a new Python application

  1. In un IDE a scelta creare una nuova applicazione Python, ad esempio mysample.py.In the IDE of your choice create a new Python application, for example, mysample.py.

  2. Aggiungere il frammento di codice seguente per importare i moduli necessariAdd the following snippet to import the required modules

    ## Use this only for Azure AD service-to-service authentication
    from azure.common.credentials import ServicePrincipalCredentials
    
    ## Use this only for Azure AD end-user authentication
    from azure.common.credentials import UserPassCredentials
    
    ## Use this only for Azure AD multi-factor authentication
    from msrestazure.azure_active_directory import AADTokenCredentials
    
    ## Required for Azure Data Lake Store account management
    from azure.mgmt.datalake.store import DataLakeStoreAccountManagementClient
    from azure.mgmt.datalake.store.models import DataLakeStoreAccount
    
    ## Required for Azure Data Lake Store filesystem management
    from azure.datalake.store import core, lib, multithread
    
    # Common Azure imports
    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. Salvare le modifiche a mysample.py.Save changes to mysample.py.

AuthenticationAuthentication

Questa sezione descrive le diverse modalità di autenticazione con Azure AD.In this section, we talk about the different ways to authenticate with Azure AD. Le opzioni disponibili sono:The options available are:

Creare il client e l'account Data Lake StoreCreate client and Data Lake Store account

Il frammento seguente crea prima il client account Data Lake Store,The following snippet first creates the Data Lake Store account client. poi usa l'oggetto client per creare un account Data Lake StoreIt uses the client object to create a Data Lake Store account. e infine crea un oggetto client per il file system.Finally, the snippet creates a filesystem client object.

## Declare variables
subscriptionId = 'FILL-IN-HERE'
adlsAccountName = 'FILL-IN-HERE'
resourceGroup = 'FILL-IN-HERE'
location = 'eastus2'

## Create data lake store account management client object
adlsAcctClient = DataLakeStoreAccountManagementClient(armCreds, subscriptionId)

## Create a Data Lake Store account
adlsAcctResult = adlsAcctClient.account.create(
    resourceGroup,
    adlsAccountName,
    DataLakeStoreAccount(
        location=location
    )
).wait()

Elencare gli account Data Lake StoreList the Data Lake Store accounts

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

Eliminare l'account Data Lake StoreDelete the Data Lake Store account

## Delete the existing Data Lake Store accounts
adlsAcctClient.account.delete(adlsAccountName)

Passaggi successiviNext steps

Vedere anche See also