简体   繁体   English

使用Azure Python SDK打印资源组中的VM列表

[英]Printing list of VMs in a Resource Group with Azure Python SDK

I have a python script which simply lists the VMs in a resource group. 我有一个python脚本,它仅列出了资源组中的VM。 It was working in the past but for some reason has stopped producing output. 它过去曾在工作,但由于某种原因已停止生产产品。 All other commands in my script work, it is just this one that is giving me bother. 我的脚本中的所有其他命令都起作用,正是这一点让我感到烦恼。 My code is as follows: 我的代码如下:

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)

I have also tried appending an older API version but still nothing is printed. 我也尝试过附加一个较旧的API版本,但仍然没有显示任何内容。 I can confirm there are VMs in this resource group. 我可以确认此资源组中有VM。

I have a similar command for listing VMs in VMSS groups, and it works fine. 我有一个类似的命令可以列出VMSS组中的VM,它可以正常工作。

Does anyone know what could be the issue with this particular command? 有谁知道这个特定命令可能是什么问题?

Answering my own question. 回答我自己的问题。

The problem stemmed from having incorrect/missing permissions in the custom role applied to the server. 问题源于对服务器应用的自定义角色中的权限不正确/丢失。 Ensure that your custom role has the 'Microsoft.Compute/virtualMachines/read' permissions. 确保您的自定义角色具有“ Microsoft.Compute / virtualMachines / read”权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM