Skip to content

Commit

Permalink
Order uplink ports by uplink name (#1243)
Browse files Browse the repository at this point in the history
Order uplink ports by uplink name

SUMMARY

When attaching pNics to Distributed Virtual Switches, the vSphere administrator may expect the pNic to be attached to the host uplinks in the named order that is visible in the vSphere Client.   For example, vmnic0 to "Uplink 1", vmnic1 to "Uplink 2" and so on.
The current behavior of the module attaches the first pNic to the first uplink port that it finds for the host, which might not be the first uplink for the host by name.
This change simply sorts the fetched dvSwitch uplink ports for the host by the name of the port.  Then the nics will the be attached in the expected order.
Fixes #1242
Fixes #1070

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

vmware_dvs_host
ADDITIONAL INFORMATION

Reviewed-by: Mario Lenz <m@riolenz.de>
  • Loading branch information
jdptechnc committed Mar 11, 2022
1 parent 51f43c9 commit 31082c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/1243-vmware-dvs-host-uplink-ordering.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- vmware_dvs_host - match the list of the host nics in the correct order based on the uplink port name in vCenter
(https://github.com/ansible-collections/community.vmware/issues/1242).
2 changes: 1 addition & 1 deletion plugins/modules/vmware_dvs_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def set_desired_state(self):
switch_uplink_ports[name].append(port.key)
lag_uplinks.append(port.key)

for port in ports:
for port in sorted(ports, key=lambda port: port.config.name):
if port.key in self.uplink_portgroup.portKeys and port.key not in lag_uplinks:
switch_uplink_ports['non_lag'].append(port.key)

Expand Down

0 comments on commit 31082c5

Please sign in to comment.