vmware / vmware/pyvmomi

How to find the corresponding hard disk object through the name of the hard disk, not through the VM hardware device

Open
#823 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
2.3k
Forks
763
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the posted search_disk function, especially the get_ds_obj call and storage.ListVStorageObject(dataStore) invocation. Reproduce the empty result with the supplied parameters and inspect the pyvmomi-community-samples implementation. Done means identifying whether the datastore or argument usage causes the empty list and reporting the correct usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.