def post (self, rpc=None): if rpc == 'ping': LOG.debug('ping received') self.write('OK') elif rpc == 'get-config': LOG.debug('get-config received') with open(CONFIG_FILE) as f: nffg = NFFG.parse(f.read()) nffg.duplicate_static_links() self.write(nffg.dump()) return elif rpc == 'edit-config': # parse body if it contains a Nf-fg: nffg = None if self.request.body: nffg = NFFG.parse(self.request.body) if nffg is None: self.send_error(400) return LOG.debug('edit-config received: %s', nffg.dump()) return else: self.set_status(404) self.write_error(404)
def timerHandler(self): new_nffg = None if self.__viewer.url is not None: n = self.__http_client.getNFFG(self.__viewer.url) if n is not None: if str(n).startswith("<?xml"): new_nffg = self.__converter.parse_from_Virtualizer(n) else: new_nffg = NFFG.parse(n) if new_nffg is not None: new_nffg.merge_duplicated_links() self.__process_NFFG(new_nffg) self.__viewer.canvas.dataG = self.__network self.__viewer.refresh() self.__timer = threading.Timer(1, self.timerHandler) self.__timer.start()
os.path.abspath(os.path.join(os.path.dirname(__file__), p))) from nffg import NFFG from conversion import NFFGConverter if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) graph = None if len(sys.argv) > 1: nffg_path = os.path.abspath(os.path.join(os.getcwd(), sys.argv[1])) with open(nffg_path, 'r') as f: raw = f.read() if raw.startswith("<?xml"): converter = NFFGConverter(logger=logging.getLogger(__name__)) graph = converter.parse_from_Virtualizer(raw) else: graph = NFFG.parse(raw) else: # creating basic network graph G = nx.complete_graph(4) iterator = G.nodes_iter() for i in iterator: # creating a dict for storing node parameters # TODO create data structure according to NFFG model G.node[i]['type'] = 'sap' G.node[i]['color'] = 'blue' G.node[i]['pattern'] = 'outline' # creating thread # t_view = vt.ViewerThread(viewer_type="get", graph=G) t_view = vt.ViewerThread(viewer_type="get", graph=graph) t_view.start() t_view.join()