简体   繁体   中英

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. 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. I can confirm there are VMs in this resource group.

I have a similar command for listing VMs in VMSS groups, and it works fine.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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