![](/img/trans.png)
[英]Azure Python SDK - list VMs and generate custom JSON response
[英]Printing list of VMs in a Resource Group with Azure Python SDK
我有一個python腳本,它僅列出了資源組中的VM。 它過去曾在工作,但由於某種原因已停止生產產品。 我的腳本中的所有其他命令都起作用,正是這一點讓我感到煩惱。 我的代碼如下:
credentials = MSIAuthentication()
subscription_client = SubscriptionClient(credentials)
subscription = next(subscription_client.subscriptions.list())
subscription_id = subscription.subscription_id
compute_client = ComputeManagementClient(credentials, subscription_id)
resourceGroup = "myResourceGroup"
for vm in compute_client.virtual_machines.list(resourceGroup):
print(vm)
我也嘗試過附加一個較舊的API版本,但仍然沒有顯示任何內容。 我可以確認此資源組中有VM。
我有一個類似的命令可以列出VMSS組中的VM,它可以正常工作。
有誰知道這個特定命令可能是什么問題?
回答我自己的問題。
問題源於對服務器應用的自定義角色中的權限不正確/丟失。 確保您的自定義角色具有“ Microsoft.Compute / virtualMachines / read”權限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.