如何解决如何在Azure中使用Azure-SDK-for-Python获取磁盘的所有快照列表
我正在尝试找到一种通过azure-sdk-for-python获取Azure磁盘快照列表的方法。 快照或磁盘类没有用于此目的的任何方法或字段。
但是在Web客户端中,您可以在快照概述页面enter image description here
中找到源磁盘参数。解决方法
请我回答这个愚蠢的问题。我总是将 creation_data 读为 creation_date 。 :(
解决方案是:
from typing import List
from azure.identity import ClientSecretCredential
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.compute.models import Disk
from azure.mgmt.compute.models import Snapshot
def get_disk_snapshot_list(disk: Disk,resource_group_name: str) -> List[Snapshot]
disk_snapshot_list = list()
snapshot_list = compute_client.snapshots.list_by_resource_group(resource_group_name=resource_group_name)
for snapshot in snapshot_list:
if snapshot.creation_data.source_unique_id != disk.unique_id:
continue
disk_snapshot_list.append(snapshot)
return disk_snapshot_list
def main():
credential = ClientSecretCredential(
tenant_id='your_tenant_id',client_id='your_client_id',client_secret='your_client_secret'
)
resource_group_name = 'your_resource_group_name'
compute_client = ComputeManagementClient(credential=credential,subscription_id='your_subscription_id')
disk = compute_client.disks.get(resource_group_name=resource_group_name,disk_name='your_disk_name')
disk_snapshot_list = get_disk_snapshot_list(disk=disk,resource_group_name=resource_group_name)
if __name__ == '__main__':
main()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。