pyvmomi
pyvmomi copied to clipboard
How to find the corresponding hard disk object through the name of the hard disk, not through the VM hardware device
hi, Now,I have a requirement to find hard disk objects by the name of the hard disk in the database。I found some methods in the pyvmomi-community-samples project,There is a method called storage. ListVStorageObject () . Return empty list parameters all the time, I suspect it was my parameter passing error,So that the for loop in the function can't execute。 I hope you can help me solve it. Thank you very much !!!
def search_disk(disk_name=None):
"""
Query the corresponding hard disk objects in VC according to the parameters of hard disk
:return:
"""
with VCenter(host='xxx', username='xxx', password='xxx') as vc:
# Set vStorageObjectManager
storage = vc.content.vStorageObjectManager
# Retrieve First Class Disks
disk = None
dataStore = get_ds_obj(content=vc.content,vimtype=[vim.Datastore],name='TYPE02')
for d in storage.ListVStorageObject(dataStore):
disk_info = storage.RetrieveVStorageObject(d, dataStore)
if disk_info.config.name == disk_name:
disk = disk_info
break
if not disk:
raise RuntimeError("First Class Disk not found.")
return disk