Если вы хотите указать виртуальную машину в масштабируемых наборах виртуальных машин Azure в приложении python, выполните следующие действия.
- Создайте участника-службу и назначьте роль участника для sp.
az login
#create sp and assign Contributor role at subscription level
az ad sp create-for-rbac -n "your service principal name"
![enter image description here](https://i.stack.imgur.com/O8q93.png)
- код
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}')
![enter image description here](https://i.stack.imgur.com/1q0pb.png)
For more details, please refer to здесь .