diff --git a/server/src/uds/services/Xen/xen_client/__init__.py b/server/src/uds/services/Xen/xen_client/__init__.py index 80f70082..68b1b4a2 100644 --- a/server/src/uds/services/Xen/xen_client/__init__.py +++ b/server/src/uds/services/Xen/xen_client/__init__.py @@ -477,21 +477,27 @@ class XenServer: # pylint: disable=too-many-public-methods # If requested mac address change try: if mac is not None: - for vifId in self.VM.get_VIFs(vmId): + all_VIFs = self.VM.get_VIFs(vmId) + if not all_VIFs: + raise XenException('No Network interfaces found!') + found = (all_VIFs[0], self.VIF.get_record(all_VIFs[0])) + for vifId in all_VIFs: vif = self.VIF.get_record(vifId) + logger.info('VIF: %s', vif) if vif['network'] == mac['network']: - logger.debug('Found VIF: %s', vif['network']) - self.VIF.destroy(vifId) + found = (vifId, vif) + break + + logger.debug('Found VIF: %s', found[1]) + vifId, vif = found + self.VIF.destroy(vifId) + + vif['MAC'] = mac['mac'] + vif['network'] = mac['network'] + vif['MAC_autogenerated'] = False + self.VIF.create(vif) - # for k in ['status_code', 'status_detail', 'uuid']: - # try: - # del vif[k] - # except: - # logger.exception('Erasing property {0}'.format(k)) - vif['MAC'] = mac['mac'] - vif['MAC_autogenerated'] = False - self.VIF.create(vif) # If requested memory change if memory: logger.debug('Setting up memory to %s MB', memory)