azure sdk for python:获取磁盘的LUN

azure sdk for python:获取磁盘的LUN,python,azure,Python,Azure,如何获取磁盘的LUN?我当前的代码如下所示: compute_client = get_client_from_cli_profile(ComputeManagementClient) virtual_machines = compute_client.virtual_machines # Search VMs for the one I'm looking for machines = virtual_machines.list_all() for machine in machines:

如何获取磁盘的LUN?我当前的代码如下所示:

compute_client = get_client_from_cli_profile(ComputeManagementClient)
virtual_machines = compute_client.virtual_machines

# Search VMs for the one I'm looking for
machines = virtual_machines.list_all()
for machine in machines:
    if machine.vm_id == my_vm_id:
        managed_id = machine.id
        break

# Search disks for those matching my VM
disks = compute_client.disks.list()
disks = filter(lambda disk : \ 
    disk.managed_by and disk.managed_by.lower() == managed_id.lower(), \
    disks)
return disks
问题是,这会生成一个对象列表,其中包含一些有用的信息,但不包含磁盘LUN之类的内容

我看到一个对象包含LUN,但我不知道如何获取LUN

如何获取包含名称和LUN的磁盘列表

(顺便问一下,除了系统地搜索我订阅中的所有虚拟机和所有磁盘之外,还有没有更好的方法从虚拟机id或虚拟机的连接磁盘列表中获取虚拟机?)

如何获取包含名称和LUN的磁盘列表

实际上,lun是VM磁盘的属性,而不是磁盘的属性。因此,您需要通过VM信息获取数据磁盘lun和名称。下面的示例代码:

compute_client = ComputeManagementClient(credential, Subscription_Id)

vm = compute_client.virtual_machines.get(vmGroup, vmName)
dataDisks = vm.storage_profile.data_disks
for disk in dataDisks:
    print(disk.lun)
有关更多详细信息,请参阅虚拟机的

我认为,如果您想获取所有连接到虚拟机的磁盘,您只需要获取虚拟机信息,然后从中获取虚拟机磁盘。这是我的建议。此外,您还需要搜索订阅中的所有虚拟机,除非您只想搜索一个特殊的虚拟机