Reputation: 2727
I am trying to retrieve the number of machines for virtual machine scale sets in python
Edit: something that I failed to mention is that I need this data per date
wanted result:
Thanks
Upvotes: 0
Views: 245
Reputation: 23141
If you want to list the vm in Azure virtual machine scale sets in python application, please refer to the following steps
az login
#create sp and assign Contributor role at subscription level
az ad sp create-for-rbac -n "your service principal name"
from azure.mgmt.compute import ComputeManagementClient
from azure.common.credentials import ServicePrincipalCredentials
client_id = "sp appId"
secret = "sp password"
tenant = "sp tenant"
credentials = ServicePrincipalCredentials(
client_id = client_id,
secret = secret,
tenant = tenant
)
Subscription_Id = ''
compute_client =ComputeManagementClient(credentials,Subscription_Id)
resource_group_name='Networking-WebApp-AppGW-V1-E2ESSL'
virtual_machine_scale_set_name='VMSS'
result=compute_client.virtual_machine_scale_set_vms.list(resource_group_name,virtual_machine_scale_set_name)
num=0
for item in result:
num+=1
print(item.name)
print(f'the number of vm in the virtual machine scale sets is {num}')
For more details, please refer to here.
Upvotes: 1