add default node map configuration, to avoid the need to set this up every time

This commit is contained in:
Blake J. Harnden 2018-01-04 08:19:34 -08:00
parent afb6af5f87
commit 42bcb1c79d
14 changed files with 38 additions and 63 deletions

View file

@ -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):

View file

@ -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.