[英]azure-sdk-for-python: get list of managed disks from a specified resource group
這是艱難的一天。 我正在努力尋找如何在azure-sdk-for-python中通過指定資源組獲取托管磁盤的列表。 搜索了所有可能的解決方案,但沒有什么比我要找的東西要近。 女士,誰做得很好,請向他們致敬,是的,先生! 成功讓我如此沮喪。
如果我遍歷虛擬機,我可以獲得托管磁盤的列表,但這可能不是最佳解決方案,因為托管磁盤可以連接/分離,而我將無法分離磁盤。
建議非常感激。
您可以通過list_by_resource_group列出給定資源組內的所有資源。
然后,您將獲得一個包含GenericResource
的頁面容器。 然后,輕松選擇所需的內容。
或者,您可以按list_by_resource_group直接列出給定資源組內的所有磁盤。
您可以使用以下腳本列出資源組中的磁盤。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.