From 42bcb1c79d5dca2e21f3cd2cae2211fe02df68fd Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Thu, 4 Jan 2018 08:19:34 -0800 Subject: [PATCH] add default node map configuration, to avoid the need to set this up every time --- daemon/core/misc/nodeutils.py | 21 +++++++++++++++++-- daemon/core/session.py | 6 ++++++ daemon/examples/netns/basicrange.py | 7 +------ daemon/examples/netns/daemonnodes.py | 6 +----- daemon/examples/netns/distributed.py | 6 +----- daemon/examples/netns/emane80211.py | 6 +----- daemon/examples/netns/howmanynodes.py | 6 +----- .../examples/netns/iperf-performance-chain.py | 6 +----- daemon/examples/netns/ospfmanetmdrtest.py | 6 +----- daemon/examples/netns/switch.py | 6 +----- daemon/examples/netns/switchtest.py | 6 +----- daemon/examples/netns/wlanemanetests.py | 6 +----- daemon/examples/netns/wlantest.py | 6 +----- daemon/sbin/core-daemon | 7 ++----- 14 files changed, 38 insertions(+), 63 deletions(-) diff --git a/daemon/core/misc/nodeutils.py b/daemon/core/misc/nodeutils.py index eadd42c2..503daaa3 100644 --- a/daemon/core/misc/nodeutils.py +++ b/daemon/core/misc/nodeutils.py @@ -9,6 +9,12 @@ from core import logger _NODE_MAP = None +def _log_map(): + global _NODE_MAP + print_map = reduce(lambda x, y: _convert_map(x, y), _NODE_MAP.items(), {}) + logger.info("node class map: \n%s", pprint.pformat(print_map, indent=4)) + + def _convert_map(x, y): """ Convenience method to create a human readable version of the node map to log. @@ -21,6 +27,18 @@ def _convert_map(x, y): return x +def update_node_map(node_map): + """ + Update the current node map with the provided node map values. + + + :param dict node_map: node map to update with + """ + global _NODE_MAP + _NODE_MAP.update(node_map) + _log_map() + + def set_node_map(node_map): """ Set the global node map that proides a consistent way to retrieve differently configured nodes. @@ -29,9 +47,8 @@ def set_node_map(node_map): :return: nothing """ global _NODE_MAP - print_map = reduce(lambda x, y: _convert_map(x, y), node_map.items(), {}) - logger.info("setting node class map: \n%s", pprint.pformat(print_map, indent=4)) _NODE_MAP = node_map + _log_map() def get_node_class(node_type): diff --git a/daemon/core/session.py b/daemon/core/session.py index 175e00c3..aba53711 100644 --- a/daemon/core/session.py +++ b/daemon/core/session.py @@ -35,6 +35,7 @@ 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 @@ -49,6 +50,11 @@ from core.xen.xenconfig import XenConfigManager from core.xml.xmlsession import save_session_xml +# set default node map +node_map = nodemaps.NODES +nodeutils.set_node_map(node_map) + + class SessionManager(object): """ Manages currently known sessions. diff --git a/daemon/examples/netns/basicrange.py b/daemon/examples/netns/basicrange.py index ecf6db28..b1fdd2f8 100755 --- a/daemon/examples/netns/basicrange.py +++ b/daemon/examples/netns/basicrange.py @@ -13,8 +13,7 @@ import optparse import sys import time -from core.misc import ipaddress, nodeutils -from core.misc import nodemaps +from core.misc import ipaddress from core.mobility import BasicRangeModel from core.netns.nodes import WlanNode from core.netns.vnet import EbtablesQueue @@ -108,8 +107,4 @@ def main(): if __name__ == "__main__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - main() diff --git a/daemon/examples/netns/daemonnodes.py b/daemon/examples/netns/daemonnodes.py index daad6c2d..2f8b7f81 100755 --- a/daemon/examples/netns/daemonnodes.py +++ b/daemon/examples/netns/daemonnodes.py @@ -25,7 +25,7 @@ from core.enumerations import LinkTlvs from core.enumerations import LinkTypes from core.enumerations import MessageFlags from core.enumerations import MessageTypes -from core.misc import ipaddress, nodeutils, nodemaps +from core.misc import ipaddress from core.netns import nodes # declare classes for use with Broker @@ -187,8 +187,4 @@ def main(): if __name__ == "__main__" or __name__ == "__builtin__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - main() diff --git a/daemon/examples/netns/distributed.py b/daemon/examples/netns/distributed.py index b8e392f0..81cc7e3f 100755 --- a/daemon/examples/netns/distributed.py +++ b/daemon/examples/netns/distributed.py @@ -16,7 +16,7 @@ import sys from core import constants from core.api import coreapi, dataconversion from core.enumerations import CORE_API_PORT, EventTypes, EventTlvs, LinkTlvs, LinkTypes, MessageFlags -from core.misc import ipaddress, nodeutils, nodemaps +from core.misc import ipaddress from core.netns import nodes from core.session import Session @@ -124,8 +124,4 @@ def main(): if __name__ == "__main__" or __name__ == "__builtin__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - main() diff --git a/daemon/examples/netns/emane80211.py b/daemon/examples/netns/emane80211.py index 4dae69d0..e1874158 100755 --- a/daemon/examples/netns/emane80211.py +++ b/daemon/examples/netns/emane80211.py @@ -13,7 +13,7 @@ import sys from core import constants from core.emane.ieee80211abg import EmaneIeee80211abgModel from core.emane.nodes import EmaneNode -from core.misc import ipaddress, nodeutils, nodemaps +from core.misc import ipaddress from core.netns import nodes # node list (count from 1) @@ -100,8 +100,4 @@ def main(): if __name__ == "__main__" or __name__ == "__builtin__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - main() diff --git a/daemon/examples/netns/howmanynodes.py b/daemon/examples/netns/howmanynodes.py index 3387af6d..8803d872 100755 --- a/daemon/examples/netns/howmanynodes.py +++ b/daemon/examples/netns/howmanynodes.py @@ -20,7 +20,7 @@ import sys import time from core import constants -from core.misc import ipaddress, nodeutils, nodemaps +from core.misc import ipaddress from core.netns import nodes from core.session import Session @@ -206,8 +206,4 @@ def main(): if __name__ == "__main__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - main() diff --git a/daemon/examples/netns/iperf-performance-chain.py b/daemon/examples/netns/iperf-performance-chain.py index cd9081a1..e946f727 100755 --- a/daemon/examples/netns/iperf-performance-chain.py +++ b/daemon/examples/netns/iperf-performance-chain.py @@ -19,7 +19,7 @@ import optparse import sys from core import constants -from core.misc import ipaddress, nodeutils, nodemaps +from core.misc import ipaddress from core.netns import nodes # node list (count from 1) @@ -100,8 +100,4 @@ def main(): if __name__ == "__main__" or __name__ == "__builtin__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - main() diff --git a/daemon/examples/netns/ospfmanetmdrtest.py b/daemon/examples/netns/ospfmanetmdrtest.py index 3a6c8b8b..f51d1e91 100755 --- a/daemon/examples/netns/ospfmanetmdrtest.py +++ b/daemon/examples/netns/ospfmanetmdrtest.py @@ -16,7 +16,7 @@ import time from string import Template from core.constants import QUAGGA_STATE_DIR -from core.misc import ipaddress, nodeutils, nodemaps +from core.misc import ipaddress from core.misc.utils import mutecall from core.netns import nodes @@ -602,8 +602,4 @@ def main(): if __name__ == "__main__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - me = main() diff --git a/daemon/examples/netns/switch.py b/daemon/examples/netns/switch.py index 97d517e3..64137f36 100755 --- a/daemon/examples/netns/switch.py +++ b/daemon/examples/netns/switch.py @@ -10,7 +10,7 @@ import optparse import sys from core import constants -from core.misc import ipaddress, nodeutils, nodemaps +from core.misc import ipaddress from core.netns import nodes # node list (count from 1) @@ -73,8 +73,4 @@ def main(): if __name__ == "__main__" or __name__ == "__builtin__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - main() diff --git a/daemon/examples/netns/switchtest.py b/daemon/examples/netns/switchtest.py index c33ac09f..524ae2b0 100755 --- a/daemon/examples/netns/switchtest.py +++ b/daemon/examples/netns/switchtest.py @@ -12,7 +12,7 @@ import datetime import optparse import sys -from core.misc import ipaddress, nodeutils, nodemaps +from core.misc import ipaddress from core.misc.utils import mutecall from core.netns import nodes from core.session import Session @@ -101,8 +101,4 @@ def main(): if __name__ == "__main__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - main() diff --git a/daemon/examples/netns/wlanemanetests.py b/daemon/examples/netns/wlanemanetests.py index 2f4b29d8..60ad31d2 100755 --- a/daemon/examples/netns/wlanemanetests.py +++ b/daemon/examples/netns/wlanemanetests.py @@ -41,7 +41,7 @@ from core import emane from core.emane.bypass import EmaneBypassModel from core.emane.nodes import EmaneNode from core.emane.rfpipe import EmaneRfPipeModel -from core.misc import ipaddress, nodemaps, nodeutils +from core.misc import ipaddress from core.netns import nodes from core.session import Session @@ -851,8 +851,4 @@ def main(): if __name__ == "__main__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - main() diff --git a/daemon/examples/netns/wlantest.py b/daemon/examples/netns/wlantest.py index fc046fdb..70892d1b 100755 --- a/daemon/examples/netns/wlantest.py +++ b/daemon/examples/netns/wlantest.py @@ -12,7 +12,7 @@ import datetime import optparse import sys -from core.misc import ipaddress, nodeutils, nodemaps +from core.misc import ipaddress from core.misc.utils import mutecall from core.netns import nodes from core.session import Session @@ -99,8 +99,4 @@ def main(): if __name__ == "__main__": - # configure nodes to use - node_map = nodemaps.NODES - nodeutils.set_node_map(node_map) - main() diff --git a/daemon/sbin/core-daemon b/daemon/sbin/core-daemon index 59fbb861..b47ec8f5 100755 --- a/daemon/sbin/core-daemon +++ b/daemon/sbin/core-daemon @@ -336,17 +336,14 @@ def main(): if __name__ == "__main__": # configure nodes to use - node_map = nodemaps.NODES if len(sys.argv) == 2 and sys.argv[1] == "ovs": from core.netns.openvswitch import OVS_NODES - node_map.update(OVS_NODES) + nodeutils.update_node_map(OVS_NODES) # update with BSD based nodes if os.uname()[0] == "FreeBSD": from core.bsd.nodes import BSD_NODES - node_map.update(BSD_NODES) - - nodeutils.set_node_map(node_map) + nodeutils.update_node_map(BSD_NODES) # load default services services.load()