added reconfigure event type, for re-generating service config files
added new Event Message handling for starting mobility model or reconfiguring a service during runtime (Boeing r1806)
This commit is contained in:
parent
c1c71bb33a
commit
a9ea208a08
4 changed files with 42 additions and 6 deletions
|
@ -282,6 +282,7 @@ event_types = dict(enumerate([
|
|||
"CORE_EVENT_FILE_OPEN",
|
||||
"CORE_EVENT_FILE_SAVE",
|
||||
"CORE_EVENT_SCHEDULED",
|
||||
"CORE_EVENT_RECONFIGURE",
|
||||
]))
|
||||
|
||||
enumdict(event_types)
|
||||
|
|
|
@ -36,18 +36,25 @@ class MobilityManager(ConfigurableManager):
|
|||
self.session.broker.handlers += (self.physnodehandlelink, )
|
||||
self.register()
|
||||
|
||||
def startup(self):
|
||||
def startup(self, nodenums=None):
|
||||
''' Session is transitioning from instantiation to runtime state.
|
||||
Instantiate any mobility models that have been configured for a WLAN.
|
||||
'''
|
||||
for nodenum in self.configs:
|
||||
v = self.configs[nodenum]
|
||||
if nodenums is None:
|
||||
nodenums = self.configs.keys()
|
||||
|
||||
for nodenum in nodenums:
|
||||
try:
|
||||
n = self.session.obj(nodenum)
|
||||
except KeyError:
|
||||
self.session.warn("Skipping mobility configuration for unknown"
|
||||
"node %d." % nodenum)
|
||||
continue
|
||||
if nodenum not in self.configs:
|
||||
self.session.warn("Missing mobility configuration for node "
|
||||
"%d." % nodenum)
|
||||
continue
|
||||
v = self.configs[nodenum]
|
||||
for model in v:
|
||||
try:
|
||||
cls = self._modelclsmap[model[0]]
|
||||
|
@ -60,6 +67,7 @@ class MobilityManager(ConfigurableManager):
|
|||
self.installphysnodes(n)
|
||||
if n.mobility:
|
||||
self.session.evq.add_event(0.0, n.mobility.startup)
|
||||
return ()
|
||||
|
||||
|
||||
def reset(self):
|
||||
|
|
|
@ -626,6 +626,18 @@ class CoreServices(ConfigurableManager):
|
|||
node.warn("error starting command %s" % cmd)
|
||||
if eventtype == coreapi.CORE_EVENT_PAUSE:
|
||||
self.validatenodeservice(node, s, services)
|
||||
if eventtype == coreapi.CORE_EVENT_RECONFIGURE:
|
||||
if s._custom:
|
||||
cfgfiles = s._configs
|
||||
else:
|
||||
cfgfiles = s.getconfigfilenames(node.objid, services)
|
||||
for filename in cfgfiles:
|
||||
if filename[:7] == "file:///":
|
||||
raise NotImplementedError # TODO
|
||||
cfg = self.getservicefiledata(s, filename)
|
||||
if cfg is None:
|
||||
cfg = s.generateconfig(node, filename, services)
|
||||
node.nodefile(filename, cfg)
|
||||
|
||||
|
||||
class CoreService(object):
|
||||
|
|
|
@ -1047,11 +1047,26 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler):
|
|||
def handleeventmsg(self, msg):
|
||||
''' Event Message handler
|
||||
'''
|
||||
eventtype = msg.tlvdata[coreapi.CORE_TLV_EVENT_TYPE]
|
||||
eventtype = msg.gettlv(coreapi.CORE_TLV_EVENT_TYPE)
|
||||
if eventtype is None:
|
||||
raise NotImplementedError, "Event message missing event type"
|
||||
node = msg.gettlv(coreapi.CORE_TLV_EVENT_NODE)
|
||||
|
||||
if self.verbose:
|
||||
self.info("EVENT %d: %s at %s" % \
|
||||
(eventtype, coreapi.event_types[eventtype], time.ctime()))
|
||||
if eventtype <= coreapi.CORE_EVENT_SHUTDOWN_STATE:
|
||||
if node is not None:
|
||||
try:
|
||||
n = self.session.obj(node)
|
||||
except KeyError:
|
||||
raise KeyError, "Event message for unknown node %d" % node
|
||||
if eventtype == coreapi.CORE_EVENT_INSTANTIATION_STATE:
|
||||
# configure mobility models for WLAN added during runtime
|
||||
if isinstance(n, pycore.nodes.WlanNode):
|
||||
return (self.session.mobility.startup(nodenums=(n.objid,)))
|
||||
self.warn("dropping unhandled Event message with node number")
|
||||
return ()
|
||||
self.session.setstate(state=eventtype, info=True, sendevent=False)
|
||||
|
||||
if eventtype == coreapi.CORE_EVENT_DEFINITION_STATE:
|
||||
|
@ -1080,8 +1095,8 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler):
|
|||
if self.session.master:
|
||||
self.warn("Unexpected event message: SHUTDOWN state received " \
|
||||
"at session master")
|
||||
elif eventtype >= coreapi.CORE_EVENT_START and \
|
||||
eventtype <= coreapi.CORE_EVENT_RESTART:
|
||||
elif eventtype in (coreapi.CORE_EVENT_START, coreapi.CORE_EVENT_RESTART, \
|
||||
coreapi.CORE_EVENT_RECONFIGURE):
|
||||
name = msg.gettlv(coreapi.CORE_TLV_EVENT_NAME)
|
||||
# TODO: register system for event message handlers, like confobjs
|
||||
if name[:8] == "service:":
|
||||
|
|
Loading…
Reference in a new issue