vmware / vmware/pyvmomi

After vMotion VmMigrated event the VM's VNIC has stale portgroup data for a period of time.

Open
#636 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs verification VMware Staff Assist Needed
Dominant language
Python
Stars
2.3k
Forks
763
PR merge metrics
No merged PRs in 30d

Description

Using pyvmomi version 6.5 and vSphere Version 6.5.0 Build 4944578

I have a listener that is responding to a vim.event.VmMigratedEvent to determine that a vMotion has completed. Using the event data, I need to determine the portgroup for each VNIC on the VM that moved to the new host.

The VM is moving from: Host HostA, Standard vSwitch vSwitch1, Portgroup PG1, to: Host HostB, Standard vSwitch vSwitch 2, Portgroup PG2. But after the migration, the VM is on Host HostB but still shows Portgroup PG1.

I'm currently interrogating the event as follows:

for device in vm_event.vm.vm.config.hardware.device:
    portgroup = device.backing.deviceName

This works fine to extract the portgroup, except that If I vMotion a VM back and forth, then after the second migration this data is always stale (it always refers to the source host). After a period of time, the portgroup data is then refreshed, but not in time for event processing.

I tried fetching the data directly for the VM (not using the event view) with the following method, but still the data is stale.

            vm = vsphere_connection.vsphere_connection.get_object_by_property(
                property_name='name',
                property_value=virtual_machine.name,
                obj_type=vim.VirtualMachine
            )
            self._logger.debug('VM = %s', vm)
            for vnic in vm.config.hardware.device:
                self._logger.debug('VM vnic %s', vnic)
                if vnic:
                    if vnic.backing:
                        try:
                            self._logger.debug('vnic backing = %s', vnic.backing)
                            if vnic.backing.deviceName:
                                self._logger.debug('vnic backing device = %s', vnic.backing.deviceName)
                        except AttributeError:
                            pass

I found that by adding a sleep for 10 seconds after the vim.event.VmMigratedEvent is received, but before processing the event at all, that the data was then populated correctly. I'd prefer not to add an arbitrary delay, but I don't see a programatic way that I can detect when the data is refreshed.

Any suggestions? Is there a backend bug here that is allowing the event to be sent before all the processing is complete?

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 vim.event.VmMigratedEvent handler and the device.backing.deviceName reads shown in the report; compare event-backed and freshly fetched VM configuration after migration. Reproduce a back-and-forth vMotion and verify whether portgroup data updates without a fixed sleep. Done means identifying a reliable refresh or completion signal, or documenting that the behavior is backend-side.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.