通过Python SDK获取azure scale集中所有虚拟机的名称

时间:2018-01-05 07:48:06

标签: python azure azure-virtual-machine azure-vm-scale-set

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

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

1 个答案:

答案 0 :(得分:2)

您可以使用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