def addTemplate(self, id, targetUid): id = prepId(id) # make the assumption targetUid is always a device class parent = self._getObject(targetUid) relationship = parent.rrdTemplates relationship._setObject(id, RRDTemplate(id)) template = getattr(relationship, id) node = ITemplateNode(template) leaf = ITemplateLeaf(template) node._addChild(leaf) return node
def getCollectorTemplate(self): """ Returns the tree representation of a collector template """ templates = [] collectorTemplate = self._getObject('/zport/dmd/Monitors/rrdTemplates/PerformanceConf') templates.append(ITemplateNode(collectorTemplate)) try: hubTemplate = self._getObject('/zport/dmd/Monitors/Hub/rrdTemplates/HubConf') templates.append(ITemplateNode(hubTemplate)) except ObjectNotFoundException: pass return templates
def _getTemplateNodes(self): catalog = self._getCatalog('/zport/dmd/Devices') brains = catalog.search(types=RRDTemplate) nodes = {} # create 1 node for each template type for brain in brains: if brain.id not in nodes: try: nodes[brain.id] = ITemplateNode(brain.getObject()) except UncataloguedObjectException: pass for key in sorted(nodes.keys(), key=str.lower): yield nodes[key]
def getOverridableTemplates(self, uid): """ A template is overrideable at the device if it is bound to the device and we have not already overridden it. @param string uid: the unique id of a device @returns a list of all available templates for the given uid """ obj = self._getObject(uid) templates = obj.getRRDTemplates() for template in templates: # see if the template is already overridden here if not obj.id in template.getPhysicalPath(): try: yield ITemplateNode(template) except UncataloguedObjectException: pass