-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vmware_guest_network speedup module #2277
vmware_guest_network speedup module #2277
Conversation
Build failed. ❌ ansible-tox-linters FAILURE in 4m 49s |
Build failed. ❌ ansible-tox-linters FAILURE in 4m 29s |
Build failed. ✔️ ansible-tox-linters SUCCESS in 4m 42s |
Build failed. ✔️ ansible-tox-linters SUCCESS in 4m 22s |
guess this failed because esxi MOB is disabled by default, gonna return part of old code to be compatible
|
Build succeeded. ✔️ ansible-tox-linters SUCCESS in 4m 38s |
Build failed. ✔️ ansible-tox-linters SUCCESS in 4m 53s |
recheck |
Build succeeded. ✔️ ansible-tox-linters SUCCESS in 4m 53s |
I'm sorry, I didn't find much time to work on this collection during the last weeks. I hope I'm able to review this PR soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GuideGlyph Please a changelog fragment. Maybe something like:
changelogs/fragments/2277-vmware_guest_network.yml
minor_changes:
- vmware_guest_network - Speedup network search
(https://github.com/ansible-collections/community.vmware/pull/2277).
@mariolenz ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @GuideGlyph!
I'm not 100% sure that I understand your changes. But if this speeds up things for you and the CI is happy 🤷
FYI I'm planing to do a new release within the next few days, possibly next weekend.
Build failed. ✔️ ansible-tox-linters SUCCESS in 4m 46s |
recheck |
recheck |
Build succeeded. ✔️ ansible-tox-linters SUCCESS in 4m 37s |
Thanks for review. Some info how it works. old code use a huge loop through all networks and check that name mach. For a small infrastructure it work nice, but when there are more then 500 networks it become slow. if compute_resource:
for network in compute_resource.network:
if isinstance(network, vim.dvs.DistributedVirtualPortgroup):
dvs = network.config.distributedVirtualSwitch
if (switch_name and dvs.config.name == switch_name) or not switch_name:
if network.config.name == network_name:
return network
if hasattr(network.config.defaultPortConfig.vlan, 'vlanId') and \
network.config.defaultPortConfig.vlan.vlanId == vlan_id:
return network
if hasattr(network.config.defaultPortConfig.vlan, 'pvlanId') and \
network.config.defaultPortConfig.vlan.pvlanId == vlan_id:
return network
elif isinstance(network, vim.Network):
if network_name and network_name == network.name:
return network
if vlan_id:
for k in pg_lookup.keys():
if vlan_id == pg_lookup[k]['vlan_id']:
if k == network.name:
return network
break I add a code before loop that check if network can be find using def get_managed_objects_properties(self, vim_type, properties=None):
"""
Look up a Managed Object Reference in vCenter / ESXi Environment
:param vim_type: Type of vim object e.g, for datacenter - vim.Datacenter
:param properties: List of properties related to vim object e.g. Name
:return: local content object
""" Managed Object References doc
|
Thanks for the additional info @GuideGlyph! I'd have merged this already yesterday, but somehow our CI/CD didn't want me to. I'll give it another try now :-) |
Build succeeded (gate pipeline). ✔️ ansible-tox-linters SUCCESS in 5m 46s |
817b93f
into
ansible-collections:main
SUMMARY Speedup vmware_guest_network module. Current design loop though all networks and slow for big infrastructure with many networks (more then 100). ISSUE TYPE Bugfix Pull Request Docs Pull Request COMPONENT NAME vmware_guest_network.py ADDITIONAL INFORMATION In my scenario current module spend 5 min to find network (this function run twice during module work and lead to 10min waiting) if compute_resource: for network in compute_resource.network: if isinstance(network, vim.dvs.DistributedVirtualPortgroup): dvs = network.config.distributedVirtualSwitch if (switch_name and dvs.config.name == switch_name) or not switch_name: if network.config.name == network_name: return network if hasattr(network.config.defaultPortConfig.vlan, 'vlanId') and \ network.config.defaultPortConfig.vlan.vlanId == vlan_id: return network if hasattr(network.config.defaultPortConfig.vlan, 'pvlanId') and \ network.config.defaultPortConfig.vlan.pvlanId == vlan_id: return network elif isinstance(network, vim.Network): if network_name and network_name == network.name: return network if vlan_id: for k in pg_lookup.keys(): if vlan_id == pg_lookup[k]['vlan_id']: if k == network.name: return network break This code loop through networks and check if its name equal to self.params['network_name']. Its slow. Its about 30s to check 100 networks. vmware.py has perfect function for this. PyVmomi.find_network_by_name works perfect and find network immediately Reviewed-by: Mario Lenz <[email protected]>
SUMMARY
Speedup vmware_guest_network module. Current design loop though all networks and slow for big infrastructure with many networks (more then 100).
ISSUE TYPE
COMPONENT NAME
vmware_guest_network.py
ADDITIONAL INFORMATION
In my scenario current module spend 5 min to find network (this function run twice during module work and lead to 10min waiting)
This code loop through networks and check if its name equal to self.params['network_name']. Its slow. Its about 30s to check 100 networks.
vmware.py has perfect function for this. PyVmomi.find_network_by_name works perfect and find network immediately