Share via


快速入門: 使用 Python 啟用虛擬機器的 Azure Automanage

Azure Automanage 可讓使用者順暢地將 Azure 最佳做法套用至其虛擬機器。 本快速入門指南將協助您使用 azure-sdk-for-python 存放庫將最佳做法組態設定檔套用至現有的虛擬機器。

必要條件

注意

免費試用帳戶無法存取本教學課程中使用的虛擬機器。 請升級為隨用隨付訂用帳戶。

重要

您必須在包含 VM 的資源群組上具有 [參與者] 角色,才能啟用 Automanage。 如果您要在訂用帳戶上初次啟用 Automanage,則需要下列權限:您訂用帳戶中的 [擁有者] 角色或 [參與者] 以及 [使用者存取管理員] 角色。

安裝必要的套件

在此示範中,需要 Azure 身分識別Azure Automanage 套件。

使用 pip 安裝這些套件:

pip install azure-identity
pip install azure-mgmt-automanage

匯入套件

Azure 身分識別Azure Automanage 套件匯入指令碼中:

from azure.identity import DefaultAzureCredential
from azure.mgmt.automanage import AutomanageClient

向 Azure 進行驗證並建立 Automanage 用戶端

使用 [Azure 身分識別] 套件向 Azure 進行驗證,然後建立 Automanage 用戶端:

credential = DefaultAzureCredential()
client = AutomanageClient(credential, "<subscription ID>")

啟用現有虛擬機器的最佳做法組態設定檔

assignment = {
    "properties": {
        "configurationProfile": "/providers/Microsoft.Automanage/bestPractices/AzureBestPracticesProduction",
    }
}

client.configuration_profile_assignments.create_or_update("default", "resourceGroupName", "vmName", assignment)

下一步

請造訪 azure-samples-python-management 存放庫,了解如何使用 Automanage 用戶端執行更多作業。