简体   繁体   中英

azure-sdk-for-python: get the LUN of a disk

How can I get the LUN of a disk? My current code looks something like this:

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

The problem is that this produces a list of Disk objects, which contain some useful information, but do not contain things like the disk LUN.

I see that a DataDisk object contains the LUN, but I don't know how to get one.

How can I get a list of disks with their names and LUNs?

(As an aside, is there a better way to get a VM from a vm id, or a list of attached disks for a VM other than methodically searching all the vms and all the disks in my subscription?)

How can I get a list of disks with their names and LUNs?

Actually, the lun is a property of the VM disk, not the disk. So you need to get the data disk lun and name through the VM information. The example code here:

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)

For more details, see the StorageProfile class of the virtual machine.

I think you just need to get the VM information and then get the VM disks from it, if you want to get the disks that all attached to the VM. This is advice. And you also need to search for all the VMs in your subscriptions, except you just want to search for a special VM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM