def add_nodes_from(self, nbunch, retain=[], **kwargs): try: retain.lower() retain = [retain] # was a string, put into list except AttributeError: pass # already a list nbunch = list(nbunch) nbunch_in = nbunch if len(retain): add_nodes = [] for n in nbunch: data = dict( (key, n.get(key)) for key in retain) add_nodes.append( (n.node_id, data) ) nbunch = add_nodes else: log.warn("Cannot add node ids directly to NIDB: must add overlay nodes") self._graph.add_nodes_from(nbunch, **kwargs) for n in nbunch_in: interfaces = dict((interface.id, {"type": interface.type, "description": interface.description}) for interface in n.interfaces()) self._graph.node[n.node_id]['_interfaces'] = interfaces
def add_nodes_from(self, nbunch, retain=[], **kwargs): try: retain.lower() retain = [retain] # was a string, put into list except AttributeError: pass # already a list nbunch = list(nbunch) nodes_to_add = nbunch # retain for interface copying if len(retain): add_nodes = [] for n in nbunch: data = dict( (key, n.get(key)) for key in retain) add_nodes.append( (n.node_id, data) ) nbunch = add_nodes else: log.warn("Cannot add node ids directly to NIDB: must add overlay nodes") self._graph.add_nodes_from(nbunch, **kwargs) for node in nodes_to_add: #TODO: add an interface_retain for attributes also int_dict = {i.interface_id: {'type': i.type, 'description': i.description, 'layer': i.overlay_id} for i in node.interfaces()} int_dict = {i.interface_id: {'type': i.type, 'description': i.description, } for i in node.interfaces()} self._graph.node[node.node_id]["_interfaces"] = int_dict
def dst_int(self): """Interface bound to destination node of edge""" try: dst_int_id = self._ports[self.dst_id] except KeyError: log.warn("Remove interface not present for %s" % self) return NmPort(self.anm, self.overlay_id, self.dst_id, dst_int_id)
def main(): ank_version = pkg_resources.get_distribution("AutoNetkit").version log.info("AutoNetkit %s" % ank_version) import optparse opt = optparse.OptionParser() opt.add_option('--file', '-f', default=None, help="Load topology from FILE") opt.add_option('--monitor', '-m', action="store_true", default=False, help="Monitor input file for changes") options, arguments = opt.parse_args() input_filename = options.file if not options.file: input_filename = "ank.graphml" anm = build_network(input_filename) anm.save() nidb = compile_network(anm) render.render(nidb) #deploy_network() if options.monitor: try: log.info("Monitoring for updates...") while True: time.sleep(0.2) if change_monitor.check_for_change(input_filename, anm): try: log.info("Input graph updated, recompiling network") anm = build_network(input_filename) anm.save() nidb = compile_network(anm) render.render(nidb) log.info("Monitoring for updates...") except: # TODO: remove this, add proper warning log.warn("Unable to build network") pass except KeyboardInterrupt: log.info("Exiting")
def add_nodes_from(self, nbunch, retain=[], **kwargs): try: retain.lower() retain = [retain] # was a string, put into list except AttributeError: pass # already a list nbunch = list(nbunch) nodes_to_add = nbunch # retain for interface copying if len(retain): add_nodes = [] for n in nbunch: data = dict((key, n.get(key)) for key in retain) add_nodes.append((n.node_id, data)) nbunch = add_nodes else: log.warn( "Cannot add node ids directly to NIDB: must add overlay nodes") self._graph.add_nodes_from(nbunch, **kwargs) for node in nodes_to_add: #TODO: add an interface_retain for attributes also int_dict = { i.interface_id: { 'type': i.type, 'description': i.description, 'layer': i.overlay_id } for i in node.interfaces() } int_dict = { i.interface_id: { 'type': i.type, 'description': i.description, } for i in node.interfaces() } self._graph.node[node.node_id]["_interfaces"] = int_dict
def main(): ank_version = pkg_resources.get_distribution("AutoNetkit").version log.info("AutoNetkit %s" % ank_version) import optparse opt = optparse.OptionParser() opt.add_option('--file', '-f', default= None, help="Load topology from FILE") opt.add_option('--monitor', '-m', action="store_true", default= False, help="Monitor input file for changes") options, arguments = opt.parse_args() input_filename = options.file if not options.file: input_filename = "ank.graphml" anm = build_network(input_filename) anm.save() nidb = compile_network(anm) render.render(nidb) #deploy_network() if options.monitor: try: log.info("Monitoring for updates...") while True: time.sleep(0.2) if change_monitor.check_for_change(input_filename, anm): try: log.info("Input graph updated, recompiling network") anm = build_network(input_filename) anm.save() nidb = compile_network(anm) render.render(nidb) log.info("Monitoring for updates...") except: # TODO: remove this, add proper warning log.warn("Unable to build network") pass except KeyboardInterrupt: log.info("Exiting")
def main(): ank_version = pkg_resources.get_distribution("AutoNetkit").version log.info("AutoNetkit %s" % ank_version) import optparse opt = optparse.OptionParser() opt.add_option('--file', '-f', default= None, help="Load topology from FILE") opt.add_option('--monitor', '-m', action="store_true", default= False, help="Monitor input file for changes") opt.add_option('--debug', action="store_true", default= False, help="Debug mode") opt.add_option('--compile', action="store_true", default= False, help="Compile") opt.add_option('--deploy', action="store_true", default= False, help="Deploy") opt.add_option('--measure', action="store_true", default= False, help="Measure") options, arguments = opt.parse_args() input_filename = options.file if not options.file: input_filename = "ank.graphml" if options.debug: #TODO: fix this import logging logger = logging.getLogger("ANK") logger.setLevel(logging.DEBUG) if options.compile: anm = build_network(input_filename) anm.save() nidb = compile_network(anm) nidb.save() render.remove_dirs(["rendered/nectar1/nklab/"]) render.render(nidb) else: anm = AbstractNetworkModel() anm.restore_latest() nidb = NIDB() nidb.restore_latest() if options.deploy: deploy_network(nidb) if options.measure: measure_network(nidb) if options.monitor: try: log.info("Monitoring for updates...") while True: time.sleep(0.2) if change_monitor.check_for_change(input_filename, anm): try: log.info("Input graph updated, recompiling network") if options.compile: nidb = compile_network(anm) render.remove_dirs(["rendered/nectar1/nklab/"]) render.render(nidb) if options.deploy: deploy_network(nidb) if options.measure: measure_network(nidb) log.info("Monitoring for updates...") except: # TODO: remove this, add proper warning log.warn("Unable to build network") pass except KeyboardInterrupt: log.info("Exiting")
except KeyError, error: return ank_version = pkg_resources.get_distribution("AutoNetkit").version date = time.strftime("%Y-%m-%d %H:%M", time.localtime()) #TODO: make sure is an abspath here so don't wipe user directory!!! if not os.path.isdir(render_output_dir): os.makedirs(render_output_dir) if render_template_file: try: render_template = lookup.get_template(render_template_file) except SyntaxException, error: log.warn( "Unable to render %s: Syntax error in template: %s" % (node, error)) return dst_file = os.path.join(render_output_dir, node.render.dst_file) #TODO: may need to iterate if multiple parts of the directory need to be created #TODO: capture mako errors better with open( dst_file, 'wb') as dst_fh: try: dst_fh.write(render_template.render( node = node, ank_version = ank_version, date = date, )) except KeyError, error:
except KeyError, error: return ank_version = pkg_resources.get_distribution("AutoNetkit").version date = time.strftime("%Y-%m-%d %H:%M", time.localtime()) #TODO: make sure is an abspath here so don't wipe user directory!!! if not os.path.isdir(render_output_dir): os.makedirs(render_output_dir) if render_template_file: try: render_template = lookup.get_template(render_template_file) except SyntaxException, error: log.warn("Unable to render %s: Syntax error in template: %s" % (node, error)) return dst_file = os.path.join(render_output_dir, node.render.dst_file) #TODO: may need to iterate if multiple parts of the directory need to be created #TODO: capture mako errors better with open(dst_file, 'wb') as dst_fh: try: dst_fh.write( render_template.render( node=node, ank_version=ank_version, date=date, ))