def fixips(self): ips = getSubObjects(self.dmd, self.filter, self.decend) self.ccount = 0 for ip in ips: self.log.debug("fixing ip %s" % ip.id) int = ip.interface() if int: ip.removeRelation("interface") ip.addRelation("interface", int) self.ccount += 1 if (self.ccount >= self.options.commitCount and not self.options.noCommit): self.mycommit(ip) if self.options.noCommit: self.log.info("not commiting any changes") else: self.mycommit()
def getComponentTree(self, *args, **kwargs): """Return a list of dictionaries used to build a device's component tree. This method is monkeypatched here to correct the ordering of components. """ # original is injected into locals by monkeypatch. result = original(self, *args, **kwargs) uid = args[0] device = self._getObject(uid) result_bytype = {} for r in result: result_bytype[r['type']] = r def descend(obj): return (isinstance(obj, ToManyContRelationship) or isinstance(obj, DeviceComponent)) def filter(obj): return isinstance(obj, DeviceComponent) # depth-first traversal of the components. ordered_meta_types = [] for o in getSubObjects(device, filter=filter, descend=descend): if o.meta_type not in ordered_meta_types: ordered_meta_types.append(o.meta_type) newresult = [] for meta_type in ordered_meta_types: if meta_type in result_bytype: newresult.append(result_bytype[meta_type]) del result_bytype[meta_type] # if, for whatever reason, there's something in the original results that we # didn't reach through the depth-first traversal, append it alphabetically. newresult.extend([result_bytype[x] for x in sorted(result_bytype.keys())]) return newresult
def getSubObjects(self, filter=None, decend=None, retobjs=None): return getSubObjects(self, filter, decend, retobjs)