diff --git a/daemon/core/future/coreemu.py b/daemon/core/future/coreemu.py index 9e9133bc..98e6ec4d 100644 --- a/daemon/core/future/coreemu.py +++ b/daemon/core/future/coreemu.py @@ -5,10 +5,15 @@ import sys import core.services from core import logger -from core.coreobj import PyCoreNode, PyCoreNet +from core.coreobj import PyCoreNet +from core.coreobj import PyCoreNode from core.data import NodeData -from core.enumerations import NodeTypes, EventTypes, LinkTypes -from core.future.futuredata import LinkOptions, NodeOptions +from core.enumerations import EventTypes +from core.enumerations import LinkTypes +from core.enumerations import NodeTypes +from core.future.futuredata import LinkOptions +from core.future.futuredata import NodeOptions +from core.misc import nodemaps from core.misc import nodeutils from core.session import Session from core.xml.xmlparser import core_document_parser @@ -842,12 +847,26 @@ class CoreEmu(object): self.session_id_gen = IdGen(_id=59999) self.sessions = {} + # set default nodes + # set default node map + node_map = nodemaps.NODES + nodeutils.set_node_map(node_map) + # load default services core.services.load() # catch exit event atexit.register(self.shutdown) + def update_nodes(self, node_map): + """ + Updates node map used by core. + + :param dict node_map: node map to update existing node map with + :return: nothing + """ + nodeutils.update_node_map(node_map) + def shutdown(self): """ Shutdown all CORE session. diff --git a/daemon/core/session.py b/daemon/core/session.py index 69a6c1a7..1540e1f6 100644 --- a/daemon/core/session.py +++ b/daemon/core/session.py @@ -33,7 +33,6 @@ from core.enumerations import MessageFlags from core.enumerations import NodeTypes from core.enumerations import RegisterTlvs from core.location import CoreLocation -from core.misc import nodemaps from core.misc import nodeutils from core.misc import utils from core.misc.event import EventLoop @@ -46,10 +45,6 @@ from core.sdt import Sdt from core.service import CoreServices from core.xml.xmlsession import save_session_xml -# set default node map -node_map = nodemaps.NODES -nodeutils.set_node_map(node_map) - class Session(object): """ diff --git a/daemon/scripts/core-daemon b/daemon/scripts/core-daemon index ee4cbf6b..016120d0 100644 --- a/daemon/scripts/core-daemon +++ b/daemon/scripts/core-daemon @@ -15,7 +15,6 @@ from core import enumerations from core import logger from core.legacy.corehandler import CoreHandler from core.legacy.coreserver import CoreServer -from core.misc import nodeutils from core.misc.utils import close_onexec from core.service import ServiceManager @@ -29,11 +28,12 @@ def banner(): logger.info("CORE daemon v.%s started %s", constants.COREDPY_VERSION, time.ctime()) -def cored(cfg=None): +def cored(cfg, use_ovs): """ Start the CoreServer object and enter the server loop. :param dict cfg: core configuration + :param bool use_ovs: flag to determine if ovs nodes should be used :return: nothing """ host = cfg["listenaddr"] @@ -43,6 +43,9 @@ def cored(cfg=None): try: server = CoreServer((host, port), CoreHandler, cfg) + if use_ovs: + from core.netns.openvswitch import OVS_NODES + server.coreemu.update_nodes(OVS_NODES) except: logger.exception("error starting main server on: %s:%s", host, port) sys.exit(1) @@ -123,8 +126,11 @@ def main(): banner() + # check if ovs flag was provided + use_ovs = len(sys.argv) == 2 and sys.argv[1] == "ovs" + try: - cored(cfg) + cored(cfg, use_ovs) except KeyboardInterrupt: logger.info("keyboard interrupt, stopping core daemon") @@ -132,10 +138,4 @@ def main(): if __name__ == "__main__": - # configure nodes to use - if len(sys.argv) == 2 and sys.argv[1] == "ovs": - from core.netns.openvswitch import OVS_NODES - - nodeutils.update_node_map(OVS_NODES) - main()