如何通过 Python SDK 获取规模集中所有 VM 名称的列表?
我认为这可能有答案,但我无法创建该类的实例。
如何通过 Python SDK 获取规模集中所有 VM 名称的列表?
我认为这可能有答案,但我无法创建该类的实例。
您可以使用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