Mulai cepat: Membuat akun Microsoft Purview (sebelumnya Azure Purview) menggunakan Python

Dalam mulai cepat ini, Anda akan membuat akun Microsoft Purview (sebelumnya Azure Purview) secara terprogram menggunakan Python. Referensi python untuk Microsoft Purview tersedia, tetapi artikel ini akan membawa Anda melalui semua langkah yang diperlukan untuk membuat akun dengan Python.

Portal tata kelola Microsoft Purview menampilkan alat seperti Peta Data Microsoft Purview dan Katalog Data Microsoft Purview yang membantu Anda mengelola dan mengatur lanskap data Anda. Dengan menyambungkan ke data di seluruh sumber lokal, multi-cloud, dan software-as-a-service (SaaS), Peta Data Microsoft Purview membuat peta terbaru informasi Anda. Ini mengidentifikasi dan mengklasifikasikan data sensitif, dan menyediakan linage end-to-end. Konsumen data dapat menemukan data di seluruh organisasi Anda, dan administrator data dapat mengaudit, mengamankan, dan memastikan penggunaan data Anda dengan benar.

Untuk informasi selengkapnya tentang kemampuan tata kelola Microsoft Purview, sebelumnya Azure Purview, lihat halaman gambaran umum kami. Untuk informasi selengkapnya tentang menyebarkan Microsoft Purview di seluruh organisasi Anda, lihat praktik terbaik penyebaran kami

Prasyarat

  • Jika Anda tidak memiliki langganan Azure, buat langganan gratis sebelum memulai.

  • Penyewa Azure Active Directory yang terkait dengan langganan Anda.

  • Akun pengguna yang Anda gunakan untuk masuk ke Azure harus menjadi anggota peran kontributor atau pemilik , atau administrator langganan Azure. Untuk melihat izin yang Anda miliki dalam langganan, ikuti langkah-langkah berikut:

    1. Masuk ke portal Microsoft Azure
    2. Pilih nama pengguna Anda di sudut kanan atas.
    3. Pilih tombol elipsis ("...") untuk opsi lainnya.
    4. Lalu pilih Izin saya.
    5. Jika Anda memiliki akses ke beberapa langganan, pilih langganan yang sesuai.
  • Tidak ada Kebijakan Azure yang mencegah pembuatan Akun penyimpanan atau namespace layanan Event Hub. Microsoft Purview akan menyebarkan akun Storage terkelola dan Azure Event Hubs saat dibuat. Jika ada kebijakan pemblokiran dan perlu tetap diberlakukan, ikuti panduan tag pengecualian Microsoft Purview kami dan ikuti langkah-langkah untuk membuat pengecualian untuk akun Microsoft Purview.

Masuk ke Azure

Masuk ke portal Microsoft Azure dengan akun Azure Anda.

Menginstal paket Python

  1. Buka terminal atau perintah dengan hak istimewa admin.

  2. Pertama, instal paket Python untuk sumber daya pengelolaan Azure:

    pip install azure-mgmt-resource
    
  3. Untuk menginstal paket Python untuk Microsoft Purview, jalankan perintah berikut:

    pip install azure-mgmt-purview
    

    Python SDK untuk Microsoft Purview mendukung Python 2.7, 3.3, 3.4, 3.5, 3.6 dan 3.7.

  4. Untuk menginstal paket Python untuk autentikasi Azure Identity, jalankan perintah berikut:

    pip install azure-identity
    

    Catatan

    Paket "azure-identity" mungkin memiliki konflik dengan "azure-cli" pada beberapa dependensi umum. Jika Anda memenuhi masalah autentikasi apa pun, hapus "azure-cli" dan dependensinya, atau gunakan mesin bersih tanpa memasang paket "azure-cli".

Membuat klien azure purview

  1. Buat file bernama purview.py. Tambahkan pernyataan berikut untuk menambahkan referensi ke namespace.

    from azure.identity import ClientSecretCredential 
     from azure.mgmt.resource import ResourceManagementClient
     from azure.mgmt.purview import PurviewManagementClient
     from azure.mgmt.purview.models import *
     from datetime import datetime, timedelta
     import time
    
  2. Tambahkan kode berikut ke metode Utama yang membuat instans kelas PurviewManagementClient. Anda akan menggunakan objek ini untuk membuat akun purview, menghapus akun purview, memeriksa ketersediaan nama, dan operasi penyedia sumber daya lainnya.

    def main():
    
    # Azure subscription ID
    subscription_id = '<subscription ID>'
    
     # This program creates this resource group. If it's an existing resource group, comment out the code that creates the resource group
    rg_name = '<resource group>'
    
    # The purview name. It must be globally unique.
    purview_name = '<purview account name>'
    
    # Location name, where Microsoft Purview account must be created.
    location = '<location name>'    
    
    # Specify your Active Directory client ID, client secret, and tenant ID
    credentials = ClientSecretCredential(client_id='<service principal ID>', client_secret='<service principal key>', tenant_id='<tenant ID>') 
    # resource_client = ResourceManagementClient(credentials, subscription_id)
    purview_client = PurviewManagementClient(credentials, subscription_id)
    

Buat akun azure purview

  1. Tambahkan kode berikut ke metode Utama yang membuat Akun azure purview. Jika grup sumber daya Anda sudah ada, komentari pernyataan create_or_update pertama.

     # create the resource group
     # comment out if the resource group already exits
     resource_client.resource_groups.create_or_update(rg_name, rg_params)
    
     #Create a purview
     identity = Identity(type= "SystemAssigned")
     sku = AccountSku(name= 'Standard', capacity= 4)
     purview_resource = Account(identity=identity,sku=sku,location =location )
    
     try:
         pa = (purview_client.accounts.begin_create_or_update(rg_name, purview_name, purview_resource)).result()
         print("location:", pa.location, " Microsoft Purview Account Name: ", pa.name, " Id: " , pa.id ," tags: " , pa.tags)  
     except:
         print("Error")
         print_item(pa)
    
     while (getattr(pa,'provisioning_state')) != "Succeeded" :
         pa = (purview_client.accounts.get(rg_name, purview_name))  
         print(getattr(pa,'provisioning_state'))
         if getattr(pa,'provisioning_state') != "Failed" :
             print("Error in creating Microsoft Purview account")
             break
         time.sleep(30)      
    
  2. Sekarang, tambahkan pernyataan berikut untuk memanggil metode Utama saat program dijalankan:

    # Start the main method
    main()
    

Skrip lengkap

Berikut adalah kode Python lengkapnya:

	
	from azure.identity import ClientSecretCredential 
	from azure.mgmt.resource import ResourceManagementClient
	from azure.mgmt.purview import PurviewManagementClient
	from azure.mgmt.purview.models import *
	from datetime import datetime, timedelta
	import time
	
	 # Azure subscription ID
    subscription_id = '<subscription ID>'
	
	# This program creates this resource group. If it's an existing resource group, comment out the code that creates the resource group
    rg_name = '<resource group>'

    # The purview name. It must be globally unique.
    purview_name = '<purview account name>'

    # Specify your Active Directory client ID, client secret, and tenant ID
    credentials = ClientSecretCredential(client_id='<service principal ID>', client_secret='<service principal key>', tenant_id='<tenant ID>') 
    # resource_client = ResourceManagementClient(credentials, subscription_id)
    purview_client = PurviewManagementClient(credentials, subscription_id)
	
	# create the resource group
    # comment out if the resource group already exits
    resource_client.resource_groups.create_or_update(rg_name, rg_params)

    #Create a purview
    identity = Identity(type= "SystemAssigned")
    sku = AccountSku(name= 'Standard', capacity= 4)
    purview_resource = Account(identity=identity,sku=sku,location ="southcentralus" )
       
    try:
	    pa = (purview_client.accounts.begin_create_or_update(rg_name, purview_name, purview_resource)).result()
	    print("location:", pa.location, " Microsoft Purview Account Name: ", purview_name, " Id: " , pa.id ," tags: " , pa.tags) 
    except:
	    print("Error in submitting job to create account")
	    print_item(pa)
 
    while (getattr(pa,'provisioning_state')) != "Succeeded" :
        pa = (purview_client.accounts.get(rg_name, purview_name))  
        print(getattr(pa,'provisioning_state'))
        if getattr(pa,'provisioning_state') != "Failed" :
            print("Error in creating Microsoft Purview account")
            break
        time.sleep(30)    

# Start the main method
main()

Menjalankan kode

Bangun dan jalankan aplikasi. Konsol mencetak kemajuan pembuatan akun Microsoft Purview. Tunggu sampai selesai. Berikut contoh outputnya:

location: southcentralus  Microsoft Purview Account Name:  purviewpython7  Id:  /subscriptions/8c2c7b23-848d-40fe-b817-690d79ad9dfd/resourceGroups/Demo_Catalog/providers/Microsoft.Purview/accounts/purviewpython7  tags:  None
Creating
Creating
Succeeded

Verifikasi output

Buka halaman akun Microsoft Purview di portal Azure dan verifikasi akun yang dibuat menggunakan kode di atas.

Menghapus akun Microsoft Purview

Untuk menghapus akun azure purview, tambahkan kode berikut ke program, lalu jalankan:

pa = purview_client.accounts.begin_delete(rg_name, purview_name).result()

Langkah berikutnya

Dalam mulai cepat ini, Anda mempelajari cara membuat akun Microsoft Purview (sebelumnya Azure Purview), menghapus akun, dan memeriksa ketersediaan nama. Sekarang Anda dapat mengunduh Python SDK dan mempelajari tentang tindakan penyedia sumber daya lain yang dapat Anda lakukan untuk akun Microsoft Purview.

Ikuti artikel berikutnya ini untuk mempelajari cara menavigasi portal tata kelola Microsoft Purview, membuat koleksi, dan memberikan akses ke portal tata kelola Microsoft Purview.