3

How do I get a list of all the names of VMs in a scale set via the Python SDK?

I think this might have the answer, but I cant create an instance of the class.

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
Varun Vembar
  • 318
  • 5
  • 18

1 Answers1

7

You could use virtual_machine_scale_set_vms.list(rg,name) to list all of the instance name. See this sdk.

For example:

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
Shui shengbao
  • 18,746
  • 3
  • 27
  • 45