Azure python ComputeManagementClient 检索虚拟机规模集的机器数(每个日期)
Azure python ComputeManagementClient retrieve number of machines for virtual machine scale sets (per date)
我正在尝试检索 python
中虚拟机规模集的计算机数量
编辑:
我没有提到的是我需要每个日期的数据
想要的结果:
谢谢
如果要在python应用程序中列出Azure虚拟机规模集中的vm,请参考以下步骤
- 创建服务主体并将贡献者角色分配给 sp
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}')
详情请参考here。
我正在尝试检索 python
中虚拟机规模集的计算机数量编辑: 我没有提到的是我需要每个日期的数据
想要的结果:
谢谢
如果要在python应用程序中列出Azure虚拟机规模集中的vm,请参考以下步骤
- 创建服务主体并将贡献者角色分配给 sp
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}')
详情请参考here。