def _getMonitorTree(self, id): appfacade = self._getFacade() monitorfacade = Zuul.getFacade("monitors", self.context) m = monitorfacade.get(id[len(_monitorprefix):]) monitor = ITreeNode(m) apps = appfacade.queryMonitorDaemons(monitor.name) for app in apps: monitor.addChild(IInfo(app)) return Zuul.marshal(monitor)
def getTree(self, id): """ Returns the tree structure of the application and collector hierarchy. @type id: string @param id: Id of the root node of the tree to be returned @rtype: [dictionary] @return: Object representing the tree """ try: appfacade = self._getFacade() monitorfacade = Zuul.getFacade("monitors", self.context) nodes = [ITreeNode(m) for m in monitorfacade.query()] for monitor in nodes: apps = appfacade.queryMonitorDaemons(monitor.name) for app in apps: monitor.addChild(IInfo(app)) apps = appfacade.queryMasterDaemons() for app in apps: nodes.append(IInfo(app)) return Zuul.marshal(nodes) except URLError as e: log.exception(e) return DirectResponse.fail("Error fetching daemons list: " + str(e.reason))
def getInfo(self, id): """ Returns the serialized info object for the given id @type: id: String @param id: Valid id of a application @rtype: DirectResponse @return: DirectResponse with data of the application """ facade = self._getFacade() monitor = facade.get(id) data = Zuul.marshal(ITreeNode(monitor)) return DirectResponse.succeed(data=data)
def addNode(self, newSubnet, contextUid): """ Add a new subnet. @type newSubnet: string @param newSubnet: New subnet to add @type contextUid: string @param contextUid: Unique identifier of the network parent of the new subnet @rtype: DirectResponse @return: B{Properties}: - newNode: (dictionary) An object representing the new subnet node """ # If the user doesn't include a mask, reject the request. if '/' not in newSubnet: response = DirectResponse.fail('You must include a subnet mask.') else: try: contextUid = getUtility(IVirtualRoot).strip_virtual_root( contextUid) netip, netmask = newSubnet.split('/') netmask = int(netmask) foundSubnet = self.api.findSubnet(netip, netmask, contextUid) if foundSubnet is not None: response = DirectResponse.fail( 'Did not add duplicate subnet: %s (%s/%s)' % (newSubnet, foundSubnet.id, foundSubnet.netmask)) else: newNet = self.api.addSubnet(newSubnet, contextUid) node = ITreeNode(newNet) audit('UI.Network.AddSubnet', contextUid, subnet=newSubnet) response = DirectResponse.succeed( newNode=Zuul.marshal(node)) except IpAddressError as error: response = DirectResponse.exception(error, 'Error adding subnet.') except Exception as error: log.exception("Error adding subnet.") response = DirectResponse.exception(error, 'Error adding subnet.') return response
def getTree(self, uid=None): obj = self._getObject(uid) try: return ITreeNode(obj) except UncataloguedObjectException: pass