Skip to content

Commit 3e33020

Browse files
committed
fix: Handle hypervisor_id option properly
* Card ID: CCT-2241 * When hypervisor_id is set to hostname and Nutanix does not provide `name` property in host object, then fallback to uuid for hypervisor_id Signed-off-by: Jiri Hnidek <jhnidek@redhat.com>
1 parent 48ccfbc commit 3e33020

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

virtwho/virt/ahv/ahv.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def get_host_guest_mapping_v3(self):
104104
Dictionary with host-guest mapping
105105
"""
106106
mapping = {'hypervisors': []}
107-
hypervisor_id = None
108107

109108
host_uvm_map = self._interface.build_host_to_uvm_map()
110109

@@ -113,15 +112,18 @@ def get_host_guest_mapping_v3(self):
113112
for host_uuid in host_uvm_map:
114113
host = host_uvm_map[host_uuid]
115114

116-
try:
117-
if self.config['hypervisor_id'] == 'uuid':
118-
hypervisor_id = host_uuid
119-
elif self.config['hypervisor_id'] == 'hostname':
115+
# Set hypervisor_id to default uuid. The self.config['hypervisor_id']
116+
# can have only two possible values: 'uuid' or 'hostname' at this point.
117+
hypervisor_id = host_uuid
118+
if self.config['hypervisor_id'] == 'uuid':
119+
self.logger.debug("Using hypervisor_id: uuid: %s", hypervisor_id)
120+
elif self.config['hypervisor_id'] == 'hostname':
121+
try:
120122
hypervisor_id = host['name']
121-
122-
except KeyError:
123-
self.logger.debug("Host '%s' doesn't have hypervisor_id property", host_uuid)
124-
continue
123+
self.logger.debug("Using hypervisor_id: hostname: %s", hypervisor_id)
124+
except KeyError:
125+
self.logger.warning("Host '%s' doesn't have 'name' property", host_uuid)
126+
self.logger.warning("Falling back to default hypervisor_id: uuid")
125127

126128
guests = []
127129
if 'guest_list' in host and len(host['guest_list']) > 0:

0 commit comments

Comments
 (0)