3

如何通过 Python SDK 获取规模集中所有 VM 名称的列表?

我认为可能有答案,但我无法创建该类的实例。

4

1 回答 1

7

您可以使用virtual_machine_scale_set_vms.list(rg,name)列出所有实例名称。看到这个sdk

例如:

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.resource import ResourceManagementClient, SubscriptionClient

# Tenant ID for your Azure Subscription
TENANT_ID = 'tenat id'

# Your Service Principal App ID
CLIENT = 'client id'

# Your Service Principal Password
KEY = 'client secret'

credentials = ServicePrincipalCredentials(
    client_id = CLIENT,
    secret = KEY,
    tenant = TENANT_ID
)

subscription_id = 'subscription_id'


compute_client = ComputeManagementClient(credentials, subscription_id)

rg = 'shuivmss'
name = 'shuivmss1'
vmss = compute_client.virtual_machine_scale_set_vms.list(rg,name)
for i in vmss:
    print i.name
于 2018-01-05T09:23:37.300 回答