Azure python ComputeManagementClient检索虚拟机规模集的计算机数(每个日期)
我试图用python检索虚拟机规模集的机器数量 编辑: 我没有提到的是,我需要每个日期的数据 通缉结果:Azure python ComputeManagementClient检索虚拟机规模集的计算机数(每个日期),python,azure,azure-monitoring,Python,Azure,Azure Monitoring,我试图用python检索虚拟机规模集的机器数量 编辑: 我没有提到的是,我需要每个日期的数据 通缉结果: 谢谢如果您想在python应用程序中列出Azure虚拟机规模集中的vm,请参考以下步骤 创建服务主体并将参与者角色分配给sp 代码 欲知详情,,请参阅。您好,谢谢您的回答,但我需要按日期筛选这些数据。是否可以将其作为历史数据-每个日期的机器数?@NadavSternn您能详细描述一下您的问题吗?您的解决方案给出了查询时虚拟比例集的机器数-但我需要它历史数据-我需要知道,对于一个给定日期
谢谢如果您想在python应用程序中列出Azure虚拟机规模集中的vm,请参考以下步骤
欲知详情,,请参阅。您好,谢谢您的回答,但我需要按日期筛选这些数据。是否可以将其作为历史数据-每个日期的机器数?@NadavSternn您能详细描述一下您的问题吗?您的解决方案给出了查询时虚拟比例集的机器数-但我需要它历史数据-我需要知道,对于一个给定日期,有2台机器,而对于另一个日期,有4台机器。我添加了一个表a说明,Thanks@NadavStern关于这个问题,您可以制定一个计划任务来每天获取信息。
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}')