クイック スタート: Python を使用して Microsoft Purview (旧称 Azure Purview) アカウントを作成する
注:
Microsoft Purview データ カタログ (クラシック) と Data Health Insights (クラシック) は新しい顧客を引き受けなくなり、これらのサービス (以前は Azure Purview) はカスタマー サポート モードになりました。
重要
テナントごとに作成できる Microsoft Purview アカウントは 1 つだけです。 organizationに既に Microsoft Purview アカウントがある場合、organizationに既に複数のアカウントがあり、まだ既存のクォータの下にない限り、新しい Microsoft Purview アカウントを作成することはできません。 詳細については、FAQ を参照してください。
このクイック スタートでは、Python を使用して Microsoft Purview (旧称 Azure Purview) アカウントをプログラムで作成します。 Microsoft Purview の Python リファレンス を利用できますが、この記事では、Python でアカウントを作成するために必要なすべての手順について説明します。
Microsoft Purview ガバナンス ポータルには、データランドスケープの管理と管理に役立つMicrosoft Purview データ マップやMicrosoft Purview データ カタログなどのツールが表示されます。 オンプレミス、マルチクラウド、およびサービスとしてのソフトウェア (SaaS) ソース全体でデータに接続することで、Microsoft Purview データ マップは情報の最新のマップを作成します。 機密性の高いデータを識別して分類し、エンドツーエンドの言語を提供します。 データ コンシューマーは、organization全体でデータを検出でき、データ管理者はデータの監査、セキュリティ保護、および適切な使用を確保できます。
Microsoft Purview の従来のガバナンス機能の詳細については、 ガバナンス ソリューションの概要ページを参照してください。
前提条件
Azure サブスクリプションをお持ちでない場合は、開始する前に 無料のサブスクリプション を作成してください。
サブスクリプションに関連付けられているMicrosoft Entra テナント。
Azure へのサインインに使用するユーザー アカウントは、 共同作成者 または 所有者 ロールのメンバー、または Azure サブスクリプションの 管理者 である必要があります。 サブスクリプションに含まれているアクセス許可を表示するには、次の手順に従います。
- Azure portalに移動します
- 右上隅でユーザー名を選択します。
- その他のオプションについては、省略記号ボタン ("...") を選択します。
- 次 に、[マイ アクセス許可] を選択します。
- 複数のサブスクリプションにアクセスできる場合は、適切なサブスクリプションを選択します。
Azure にサインインする
Azure アカウントでAzure portalにサインインします。
Python パッケージをインストールする
管理者特権でターミナルまたはコマンド プロンプトを開きます。
まず、Azure 管理リソース用の Python パッケージをインストールします。
pip install azure-mgmt-resource
Microsoft Purview 用の Python パッケージをインストールするには、次のコマンドを実行します。
pip install azure-mgmt-purview
Python SDK for Microsoft Purview では、Python 2.7、3.3、3.4、3.5、3.6、3.7 がサポートされています。
Azure Identity 認証用の Python パッケージをインストールするには、次のコマンドを実行します。
pip install azure-identity
注:
"azure-identity" パッケージは、一部の一般的な依存関係で "azure-cli" と競合する可能性があります。 認証の問題が発生した場合は、"azure-cli" とその依存関係を削除するか、"azure-cli" パッケージをインストールせずにクリーン マシンを使用します。
purview クライアントを作成する
purview.py という名前のファイルを作成します。 名前空間への参照を追加するには、次のステートメントを追加します。
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
PurviewManagementClient クラスのインスタンスを作成する Main メソッドに次のコードを追加します。 このオブジェクトを使用して、purview アカウントの作成、purview アカウントの削除、チェック名の可用性、およびその他のリソース プロバイダー操作を行います。
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)
purview アカウントを作成する
Purview アカウントを作成する Main メソッドに次のコードを追加します。 リソース グループが既に存在する場合は、最初の
create_or_update
ステートメントをコメント アウトします。# 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)
次に、次のステートメントを追加して、プログラムの実行時に メイン メソッドを呼び出します。
# Start the main method main()
完全なスクリプト
完全な Python コードを次に示します。
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
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 for your resource group and your Microsoft Purview account.
location ="<location>"
# 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, {"location": location})
#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: ", 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()
コードを実行する
アプリケーションをビルドして起動します。 コンソールは、Microsoft Purview アカウントの作成の進行状況を出力します。 完了するまで待ちます。 出力例を次に示します。
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
出力を確認する
Azure portalの [Microsoft Purview アカウント] ページに移動し、上記のコードを使用して作成されたアカウントを確認します。
Microsoft Purview アカウントを削除する
purview アカウントを削除するには、次のコードをプログラムに追加し、次を実行します。
pa = purview_client.accounts.begin_delete(rg_name, purview_name).result()
次の手順
このクイック スタートでは、Microsoft Purview (旧称 Azure Purview) アカウントを作成し、アカウントを削除し、名前を利用できるようにチェックする方法について説明しました。 Python SDK をダウンロードし、Microsoft Purview アカウントに対して実行できるその他のリソース プロバイダー アクションについて学習できるようになりました。
次の記事に従って、Microsoft Purview ガバナンス ポータルを移動し、コレクションを作成し、Microsoft Purview ガバナンス ポータルへのアクセスを許可する方法について説明します。