【发布时间】:2020-10-22 17:59:49
【问题描述】:
我已使用以下代码从我的 Azure 帐户获取访问令牌。
很好用,我也拿到了令牌
但是当我使用下面的语句时,它会列出所有虚拟机的信息,但我只需要一个虚拟机 我参考了文档,但它没有任何过滤示例
from azure.mgmt.compute import ComputeManagementClient
from azure.common.credentials import ServicePrincipalCredentials
Subscription_Id = "xxxxx"
Tenant_Id = "xxxxx"
Client_Id = "xxxxx"
Secret = "xxxxx"
credential = ServicePrincipalCredentials(
client_id=Client_Id,
secret=Secret,
tenant=Tenant_Id
)
compute_client = ComputeManagementClient(credential, Subscription_Id)
vm_list = compute_client.virtual_machines.list_all()
如何过滤一个虚拟机并将所有与虚拟机相关的信息输出到 json
【问题讨论】:
-
您需要使用 get() 方法。即
vm = compute_client.virtual_machines.get(<resource group>, <vm name>) -
您对想要获取的 VM 了解多少?
-
我需要了解给定单个虚拟机的标签、磁盘、存储大小等
标签: python azure sdk virtual-machine