removed session manager, since CoreEmu does this now, set future examples to serve as API examples, removed netns examples that are replaced by these API variations

This commit is contained in:
Blake J. Harnden 2018-04-26 13:06:18 -07:00
parent 8644e9d61e
commit dc751dde2b
18 changed files with 12 additions and 996 deletions

View file

@ -113,8 +113,8 @@ class IdGen(object):
class FutureSession(Session):
def __init__(self, session_id, config=None, persistent=True, mkdir=True):
super(FutureSession, self).__init__(session_id, config, persistent, mkdir)
def __init__(self, session_id, config=None, mkdir=True):
super(FutureSession, self).__init__(session_id, config, mkdir)
# object management
self.node_id_gen = IdGen()

View file

@ -3,7 +3,6 @@ session.py: defines the Session class used by the core-daemon daemon program
that manages a CORE session.
"""
import atexit
import os
import pprint
import random
@ -52,68 +51,17 @@ node_map = nodemaps.NODES
nodeutils.set_node_map(node_map)
class SessionManager(object):
"""
Manages currently known sessions.
"""
sessions = set()
session_lock = threading.Lock()
@classmethod
def add(cls, session):
"""
Add a session to the manager.
:param Session session: session to add
:return: nothing
"""
with cls.session_lock:
logger.info("adding session to manager: %s", session.session_id)
cls.sessions.add(session)
@classmethod
def remove(cls, session):
"""
Remove session from the manager.
:param Session session: session to remove
:return: nothing
"""
with cls.session_lock:
logger.info("removing session from manager: %s", session.session_id)
if session in cls.sessions:
cls.sessions.remove(session)
else:
logger.info("session was already removed: %s", session.session_id)
@classmethod
def on_exit(cls):
"""
Method used to shutdown all currently known sessions, in case of unexpected exit.
:return: nothing
"""
logger.info("caught program exit, shutting down all known sessions")
while cls.sessions:
with cls.session_lock:
session = cls.sessions.pop()
logger.error("WARNING: automatically shutting down non-persistent session %s - %s",
session.session_id, session.name)
session.shutdown()
class Session(object):
"""
CORE session manager.
"""
def __init__(self, session_id, config=None, persistent=False, mkdir=True):
def __init__(self, session_id, config=None, mkdir=True):
"""
Create a Session instance.
:param int session_id: session id
:param dict config: session configuration
:param bool persistent: flag is session is considered persistent
:param bool mkdir: flag to determine if a directory should be made
"""
self.session_id = session_id
@ -152,9 +100,6 @@ class Session(object):
self.add_state_hook(state=EventTypes.RUNTIME_STATE.value, hook=self.runtime_state_hook)
if not persistent:
SessionManager.add(self)
self.master = False
# handlers for broadcasting information
@ -227,9 +172,6 @@ class Session(object):
for handler in self.shutdown_handlers:
handler(self)
# remove this session from the manager
SessionManager.remove(self)
def broadcast_event(self, event_data):
"""
Handle event data that should be provided to event handler.
@ -1514,7 +1456,3 @@ class SessionMetaData(ConfigurableManager):
:return: configuration items iterator
"""
return self.configs.iteritems()
# configure the program exit function to run
atexit.register(SessionManager.on_exit)