diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py index f7bc1c8fb2..6cb738e93e 100644 --- a/tools/python/xen/xend/XendAPI.py +++ b/tools/python/xen/xend/XendAPI.py @@ -1986,8 +1986,6 @@ class XendAPI(object): log.exception("Error in VBD_create") return xen_api_error(['INTERNAL_ERROR', str(e)]) - vdi.addVBD(vbd_ref) - xendom.managed_config_save(dom) return xen_api_success(vbd_ref) @@ -2004,8 +2002,6 @@ class XendAPI(object): XendTask.log_progress(0, 100, vm.destroy_vbd, vbd_ref) - vdi.removeVBD(vbd_ref) - return xen_api_success_void() def _VBD_get(self, vbd_ref, prop): diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index 7a125fb23a..336e5bc8b2 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -203,6 +203,17 @@ class XendDomain: if key not in XendConfig.LEGACY_XENSTORE_VM_PARAMS and \ key in dom: running_dom.info[key] = dom[key] + # Devices information is restored from xenstore, + # but VDI value in devices information can be not + # restored because there is not VDI value in + # xenstore. So we restore VDI value by using the + # domain config file. + for vbd_ref in running_dom.info['vbd_refs']: + if dom['devices'].has_key(vbd_ref): + r_devtype, r_devinfo = running_dom.info['devices'][vbd_ref] + _, m_devinfo = dom['devices'][vbd_ref] + r_devinfo['VDI'] = m_devinfo.get('VDI', '') + running_dom.info['devices'][vbd_ref] = (r_devtype, r_devinfo) except Exception: log.exception("Failed to create reference to managed " "domain: %s" % dom_name) @@ -347,7 +358,6 @@ class XendDomain: if self.is_domain_managed(dom): self._managed_config_remove(dom.get_uuid()) del self.managed_domains[dom.get_uuid()] - dom.unlink_xapi_instances() dom.destroy_xapi_instances() except ValueError: log.warn("Domain is not registered: %s" % dom.get_uuid()) @@ -486,7 +496,6 @@ class XendDomain: if domid in self.domains: del self.domains[domid] - info.unlink_xapi_instances() info.destroy_xapi_instances() else: log.warning("Attempted to remove non-existent domain.") diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index e9dfa15782..5c3b1f6c52 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -4048,20 +4048,6 @@ class XendDomainInfo: except Exception, exn: raise XendError('Failed to destroy device') - def unlink_xapi_instances(self): - from xen.xend import XendDomain - if XendDomain.instance().is_valid_vm(self.info.get('uuid')): - # domain still exists. - return - - for vbd_ref in self.info.get('vbd_refs'): - dev_info = self.info['devices'].get(vbd_ref)[1] - vdi_uuid = dev_info.get('VDI', None) - if vdi_uuid and XendNode.instance().is_valid_vdi(vdi_uuid): - vdi = XendNode.instance().get_vdi_by_uuid(vdi_uuid) - if vdi.getVBDs().count(vbd_ref): - vdi.removeVBD(vbd_ref) - def destroy_xapi_instances(self): """Destroy Xen-API instances stored in XendAPIStore. """ diff --git a/tools/python/xen/xend/XendVDI.py b/tools/python/xen/xend/XendVDI.py index fa3d147951..f8abea615f 100644 --- a/tools/python/xen/xend/XendVDI.py +++ b/tools/python/xen/xend/XendVDI.py @@ -76,16 +76,17 @@ class XendVDI(AutoSaveObject): self.read_only = False self.type = "system" self.other_config = {} - self.vbds = [] - - def addVBD(self, vbd_ref): - self.vbds.append(vbd_ref) - - def removeVBD(self, vbd_ref): - self.vbds.remove(vbd_ref) def getVBDs(self): - return self.vbds + from xen.xend import XendDomain + vbd_refs = [d.get_vbds() for d in XendDomain.instance().list('all')] + vbd_refs = reduce(lambda x, y: x + y, vbd_refs) + vbds = [] + for vbd_ref in vbd_refs: + vdi = XendDomain.instance().get_dev_property_by_uuid('vbd', vbd_ref, 'VDI') + if vdi == self.uuid: + vbds.append(vbd_ref) + return vbds def load_config_dict(self, cfg): """Loads configuration into the object from a dict. @@ -161,7 +162,7 @@ class XendVDI(AutoSaveObject): 'type': self.type, 'SR': self.sr_uuid, 'other_config': self.other_config, - 'VBDs': self.vbds} + 'VBDs': self.getVBDs()} def get_location(self): raise NotImplementedError()