如何从Azure Python SDK获取虚拟机的操作系统磁盘相关详细信息

如何从Azure Python SDK获取虚拟机的操作系统磁盘相关详细信息,python,azure,virtual-machine,disk,Python,Azure,Virtual Machine,Disk,我正试图通过python sdk获取有关Azure VM操作系统磁盘的特定信息 我试图通过互联网获得信息 disk_account_type = vm.managed_disk.storage_account_type 但得到以下错误: AttributeError: 'VirtualMachine' object has no attribute 'managed_disk' 在哪里可以获取此操作系统磁盘的操作系统磁盘名称、大小和加密值以及存储帐户类型。 编辑:截图 您可以使用下面的代

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

我试图通过互联网获得信息

 disk_account_type =  vm.managed_disk.storage_account_type
但得到以下错误:

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


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

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)

更新:

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)
如果您所指的
加密值
磁盘加密集
,则可以使用下面的代码,它返回磁盘加密集资源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”portal@asp您可以在问题中显示该问题的屏幕截图吗?@asp您无法通过sdk直接获取它,默认情况下,加密为
SSE with PMK
,然后
磁盘加密集将
为None
,如果它是带有CMK的SSE
,它将返回磁盘加密集的资源id,如我在回复中的更新中所述。因此,您可以选择使用判断,如果
vm.storage\u profile.os\u disk.managed\u disk.disk\u encryption\u set
None
,则
加密类型为
SSE with PMK