【问题标题】:How to get OS disk related details from Azure Python SDK for a vm如何从用于 vm 的 Azure Python SDK 获取 OS 磁盘相关的详细信息
【发布时间】:2020-11-08 15:57:56
【问题描述】:

我正在尝试通过 python sdk 获取有关 Azure VM 操作系统磁盘的信息

我试图通过

获取信息
 disk_account_type =  vm.managed_disk.storage_account_type

但出现以下错误:

AttributeError: 'VirtualMachine' object has no attribute 'managed_disk'

我在哪里可以获取此操作系统磁盘的操作系统磁盘名称、大小和加密值以及存储帐户类型。 编辑:截图

【问题讨论】:

    标签: python azure virtual-machine disk


    【解决方案1】:

    您可以使用下面的代码来获取它们。

    vm = compute_client.virtual_machines.get("groupname", "joyvm1")
    
    name = vm.storage_profile.os_disk.name
    disk_size_gb = vm.storage_profile.os_disk.disk_size_gb
    encryption_settings = vm.storage_profile.os_disk.encryption_settings
    storage_account_type = vm.storage_profile.os_disk.managed_disk.storage_account_type
    
    print(name, disk_size_gb, encryption_settings, storage_account_type)
    

    更新:

    如果你说的Encryption valuedisk_encryption_set,可以使用下面的代码,返回磁盘加密集资源id。

    disk_encryption_set = vm.storage_profile.os_disk.managed_disk.disk_encryption_set
    print(disk_encryption_set)
    

    更新2:

    disk_encryption_set = vm.storage_profile.os_disk.managed_disk.disk_encryption_set
    
    if disk_encryption_set is None:
        encryption = "SSE with PMK"
    else:
        encryption = "SSE with CMK"
    
    print(encryption)
    

    【讨论】:

    • 嗨,我正在查看的加密值类似于 azure 门户上显示的“SSE with PMK”
    • @asp 你能在你的问题中显示截图吗?
    • @asp 无法通过sdk直接获取,默认加密为SSE with PMK,则disk_encryption_setNone,如果为SSE with CMK则返回我在回复中的更新中提到的磁盘加密集的资源 ID。所以你的选择是使用判断,如果vm.storage_profile.os_disk.managed_disk.disk_encryption_setNoneencryption typeSSE with PMK
    • 我看到 python 和其他一些 SDK 仅在 VM 运行时显示大小。有没有办法让停止的虚拟机克服它?
    猜你喜欢
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    • 2019-09-13
    • 2013-04-12
    • 1970-01-01
    相关资源
    最近更新 更多