azure-sdk-for-python:获取指定资源组的托管磁盘列表

问题描述 投票:1回答:2

这是艰难的一天。我正在努力找到如何通过azure-sdk-for-python中的指定资源组获取托管磁盘列表。搜索了所有可能的解决方案,但没有什么能接近我想要的。为他们的文档做得很好的ms致敬,是的,先生!成功让我如此沮丧。

如果我循环访问VM,我可以获得托管磁盘列表,但它可能不是最好的解决方案,因为托管磁盘可以连接/分离,我将无法获得那些分离的磁盘。

建议非常感谢。

python azure sdk azure-virtual-machine azure-managed-disk
2个回答
1
投票

您可以使用以下脚本列出资源组中的磁盘。

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.resource import ResourceManagementClient, SubscriptionClient

# Tenant ID for your Azure Subscription
TENANT_ID = ''

# Your Service Principal App ID
CLIENT = ''

# Your Service Principal Password
KEY = ''

credentials = ServicePrincipalCredentials(
    client_id = CLIENT,
    secret = KEY,
    tenant = TENANT_ID
)

subscription_id = ''

compute_client = ComputeManagementClient(credentials, subscription_id)

rg = 'shuilinux'

disks = compute_client.disks.list_by_resource_group(rg)
for disk in disks:
    print disk

1
投票

您可以通过list_by_resource_group列出给定资源组内的所有资源。

然后你会得到一个包含GenericResource的页面容器。然后,您可以轻松选择所需内容。

或者,您可以通过list_by_resource_group for disk直接列出给定资源组中的所有磁盘。

© www.soinside.com 2019 - 2024. All rights reserved.