Skip to content
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_host_vmnic_info: Fix issue with offline / disconnected / shut down hosts #1337

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- vmware_host_vmnic_info - Fix a bug that crashes the module when a host is disconnected (https://github.com/ansible-collections/community.vmware/pull/1337).
17 changes: 10 additions & 7 deletions plugins/modules/vmware_host_vmnic_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
'''

try:
from pyVmomi import vim
from pyVmomi import vim, vmodl
except ImportError:
pass

Expand Down Expand Up @@ -231,12 +231,15 @@ def gather_host_vmnic_info(self):
pnic_info['status'] = 'Connected'
pnic_info['actual_speed'] = pnic.linkSpeed.speedMb
pnic_info['actual_duplex'] = 'Full Duplex' if pnic.linkSpeed.duplex else 'Half Duplex'
network_hint = host_nw_system.QueryNetworkHint(pnic.device)
for hint in self.to_json(network_hint):
if hint.get('lldpInfo'):
pnic_info['lldp_info'] = {x['key']: x['value'] for x in hint['lldpInfo'].get('parameter')}
else:
pnic_info['lldp_info'] = 'N/A'
try:
network_hint = host_nw_system.QueryNetworkHint(pnic.device)
for hint in self.to_json(network_hint):
if hint.get('lldpInfo'):
pnic_info['lldp_info'] = {x['key']: x['value'] for x in hint['lldpInfo'].get('parameter')}
else:
pnic_info['lldp_info'] = 'N/A'
except (vmodl.fault.HostNotConnected, vmodl.fault.HostNotReachable):
pnic_info['lldp_info'] = 'N/A'
else:
pnic_info['status'] = 'Disconnected'
pnic_info['actual_speed'] = 'N/A'
Expand Down
57 changes: 57 additions & 0 deletions tests/integration/targets/vmware_host_vmnic_info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,60 @@
- assert:
that:
- host_vmnics_extended.hosts_vmnics_info is defined

- name: Get info from an ESXi host that is offline / disconnected / shut down
block:
- name: Disconnect ESXi host
community.vmware.vmware_host:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter_name: '{{ dc1 }}'
cluster_name: '{{ ccr1 }}'
esxi_hostname: "{{ esxi1 }}"
state: disconnected

- name: Give the ESXi host time to disconnect
ansible.builtin.pause:
minutes: 1

- name: Gather vmnic info about a host that is offline / disconnected / shut down
vmware_host_vmnic_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
esxi_hostname: '{{ esxi1 }}'
validate_certs: false
register: host_vmnics_disconnected
- debug: var=host_vmnics_disconnected
- assert:
that:
- host_vmnics_disconnected.hosts_vmnics_info is defined

- name: Gather extended vmnic info about a host that is offline / disconnected / shut down
vmware_host_vmnic_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
esxi_hostname: '{{ esxi1 }}'
validate_certs: false
capabilities: true
directpath_io: true
sriov: true
register: host_vmnics_extended_disconnected
- debug: var=host_vmnics_extended_disconnected
- assert:
that:
- host_vmnics_extended_disconnected.hosts_vmnics_info is defined
always:
- name: Reconnect ESXi host
community.vmware.vmware_host:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter_name: '{{ dc1 }}'
cluster_name: '{{ ccr1 }}'
esxi_hostname: "{{ esxi1 }}"
state: reconnect