查找磁盘何时未连接?

Find when disk became unattached?

我正在尝试确定一种删除未附加磁盘的方法,如果它们在特定时间段内未附加:

伪代码

if state = "unattached" & date_unattached > 7 days then DELETE

我目前有:

compute_client = ComputeManagementClient(credentials, subscription_id)

for disk in compute_client.disks.list():
    print(disk.as_dict())

但是,有效载荷只为我提供了磁盘创建时间的 date/time。

我尝试将磁盘附加到虚拟机,但 activity 日志似乎没有更新(将继续监控)。我希望磁盘日志可以提供此信息。

有没有一种简单的方法可以找到此磁盘何时脱离连接?

我也在考虑是否可以使用数据库来跟踪首次发现磁盘的时间,然后计算第一次脚本 运行 与下一次脚本之间的天数(如果磁盘状态仍然相同)并得到差异。我需要每天 运行 它,因为用户可能 attach/detach 定期(边缘情况)

I tried attaching the disk to a VM but the activity logs didn't seem to update (will keep monitoring). I was hoping the disk logs might give this information.

它会在日志中,但它只会显示为Create or Update Disk,您可以在门户中查看卸载磁盘相关信息,这是一个预览功能。它不能通过 REST API/Python sdk 获得(sdk 也调用其余 api),所以我认为这不是一个简单的检查方法。

I am also thinking maybe using a DB to track when the disk was first discovered and then count the number of days between the first time the script ran and the next if the disk state is still the same and get the difference. I would need to run it daily as a user may attach/detach regularly (edge case)

我觉得这个方法可行,用pythonsdk查看disk_state是否每天Unattached,统计天数