aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authoremellor@ewan <emellor@ewan>2005-10-05 11:43:23 +0100
committeremellor@ewan <emellor@ewan>2005-10-05 11:43:23 +0100
commit39f62611c40944029fb67527aafd3c3853bea35f (patch)
treed6c74daa0fba413fe3dc3c9c133977129af95a46 /tools
parentacbce460773919d8a2eef2b688be64865e304807 (diff)
downloadxen-39f62611c40944029fb67527aafd3c3853bea35f.tar.gz
xen-39f62611c40944029fb67527aafd3c3853bea35f.tar.bz2
xen-39f62611c40944029fb67527aafd3c3853bea35f.zip
Removed the EventServer, replacing the events fired with simple logging
messages. This closes bug #281. Removed references to XendRoot where these have become unnecessary either through the work above or just through time. Renamed some parameters in event.py, to mark them as unused. Fix a call to a base class constructor there too. Signed-off-by: Ewan Mellor <ewan@xensource.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/python/xen/xend/EventServer.py265
-rw-r--r--tools/python/xen/xend/XendDomain.py17
-rw-r--r--tools/python/xen/xend/XendRoot.py12
-rw-r--r--tools/python/xen/xend/server/SrvDaemon.py7
-rw-r--r--tools/python/xen/xend/server/SrvRoot.py5
-rw-r--r--tools/python/xen/xend/server/event.py54
-rw-r--r--tools/python/xen/xend/server/relocate.py2
7 files changed, 25 insertions, 337 deletions
diff --git a/tools/python/xen/xend/EventServer.py b/tools/python/xen/xend/EventServer.py
deleted file mode 100644
index e4966414a7..0000000000
--- a/tools/python/xen/xend/EventServer.py
+++ /dev/null
@@ -1,265 +0,0 @@
-#============================================================================
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of version 2.1 of the GNU Lesser General Public
-# License as published by the Free Software Foundation.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#============================================================================
-# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
-#============================================================================
-
-"""Simple publish/subscribe event server.
-
-"""
-import string
-from threading import Lock
-
-import scheduler
-
-# subscribe a.b.c h: map a.b.c -> h
-# subscribe a.b.* h: map a.b.* -> h
-# subscribe a.b.? h: map a.b.? -> h
-#
-# for event a.b.c.d:
-#
-# lookup a.b.c.d, call handlers
-#
-# lookup a.b.c.?, call handlers
-#
-# lookup a.b.c.d.*, call handlers
-# lookup a.b.c.*, call handlers
-# lookup a.b.*, call handlers
-# lookup a.*, call handlers
-# lookup *, call handlers
-
-# a.b.c.d = (a b c d)
-# a.b.c.? = (a b c _)
-# a.b.c.* = (a b c . _)
-
-class EventServer:
-
- DOT = '.'
- QUERY = '?'
- DOT_QUERY = DOT + QUERY
- STAR = '*'
- DOT_STAR = DOT + STAR
-
- def __init__(self, run=0):
- self.handlers = {}
- self.run = run
- self.queue = []
- self.lock = Lock()
-
- def start(self):
- """Enable event handling. Sends any queued events.
- """
- try:
- self.lock.acquire()
- self.run = 1
- queue = self.queue
- self.queue = []
- finally:
- self.lock.release()
- for (e,v) in queue:
- self.inject(e, v)
-
- def stop(self):
- """Suspend event handling. Events injected while suspended
- are queued until we are started again.
- """
- try:
- self.lock.acquire()
- self.run = 0
- finally:
- self.lock.release()
-
- def subscribe(self, event, handler):
- """Subscribe to an event. For example 'a.b.c.d'.
- A subcription like 'a.b.c.?' ending in '?' matches any value
- for the '?'. A subscription like 'a.b.c.*' ending in '*' matches
- any event type with the same prefix, 'a.b.c' in this case.
-
- event event name
- handler event handler fn(event, val)
- """
- try:
- self.lock.acquire()
- hl = self.handlers.get(event)
- if hl is None:
- self.handlers[event] = [handler]
- else:
- hl.append(handler)
- finally:
- self.lock.release()
-
- def unsubscribe_all(self, event=None):
- """Unsubscribe all handlers for a given event, or all handlers.
-
- event event (optional)
- """
- try:
- self.lock.acquire()
- if event == None:
- self.handlers.clear()
- elif event in self.handlers:
- del self.handlers[event]
- finally:
- self.lock.release()
-
- def unsubscribe(self, event, handler):
- """Unsubscribe a given event and handler.
-
- event event
- handler handler
- """
- try:
- self.lock.acquire()
- hl = self.handlers.get(event)
- if hl is None:
- return
- if handler in hl:
- hl.remove(handler)
- finally:
- self.lock.release()
-
- def inject(self, event, val, async=1):
- """Inject an event. Handlers for it are called if running, otherwise
- it is queued.
-
- event event type
- val event value
- """
- try:
- self.lock.acquire()
- if not self.run:
- self.queue.append( (event, val) )
- return
- finally:
- self.lock.release()
-
- if async:
- scheduler.now(self.call_handlers, event, val)
- else:
- self.call_handlers(event, val)
-
- def call_handlers(self, event, val):
- """Internal method to call event handlers.
- """
- #print ">event", event, val
- self.call_event_handlers(event, event, val)
- self.call_query_handlers(event, val)
- self.call_star_handlers(event, val)
-
- def call_event_handlers(self, key, event, val):
- """Call the handlers for an event.
- It is safe for handlers to subscribe or unsubscribe.
-
- key key for handler list
- event event type
- val event value
- """
- try:
- self.lock.acquire()
- hl = self.handlers.get(key)
- if hl is None:
- return
- # Copy the handler list so that handlers can call
- # subscribe/unsubscribe safely - python list iteration
- # is not safe against list modification.
- hl = hl[:]
- finally:
- self.lock.release()
- # Must not hold the lock while calling the handlers.
- for h in hl:
- try:
- h(event, val)
- except:
- pass
-
- def call_query_handlers(self, event, val):
- """Call regex handlers for events matching 'event' that end in '?'.
-
- event event type
- val event value
- """
- dot_idx = event.rfind(self.DOT)
- if dot_idx == -1:
- self.call_event_handlers(self.QUERY, event, val)
- else:
- event_query = event[0:dot_idx] + self.DOT_QUERY
- self.call_event_handlers(event_query, event, val)
-
- def call_star_handlers(self, event, val):
- """Call regex handlers for events matching 'event' that end in '*'.
-
- event event type
- val event value
- """
- etype = string.split(event, self.DOT)
- for i in range(len(etype), 0, -1):
- event_star = self.DOT.join(etype[0:i]) + self.DOT_STAR
- self.call_event_handlers(event_star, event, val)
- self.call_event_handlers(self.STAR, event, val)
-
-def instance():
- global inst
- try:
- inst
- except:
- inst = EventServer()
- inst.start()
- return inst
-
-def main():
- def sys_star(event, val):
- print 'sys_star', event, val
-
- def sys_foo(event, val):
- print 'sys_foo', event, val
- s.unsubscribe('sys.foo', sys_foo)
-
- def sys_foo2(event, val):
- print 'sys_foo2', event, val
-
- def sys_bar(event, val):
- print 'sys_bar', event, val
-
- def sys_foo_bar(event, val):
- print 'sys_foo_bar', event, val
-
- def foo_bar(event, val):
- print 'foo_bar', event, val
-
- s = EventServer()
- s.start()
- s.subscribe('sys.*', sys_star)
- s.subscribe('sys.foo', sys_foo)
- s.subscribe('sys.foo', sys_foo2)
- s.subscribe('sys.bar', sys_bar)
- s.subscribe('sys.foo.bar', sys_foo_bar)
- s.subscribe('foo.bar', foo_bar)
- s.inject('sys.foo', 'hello')
- print
- s.inject('sys.bar', 'hello again')
- print
- s.inject('sys.foo.bar', 'hello again')
- print
- s.inject('foo.bar', 'hello again')
- print
- s.inject('foo', 'hello again')
- print
- s.start()
- s.unsubscribe('sys.*', sys_star)
- s.unsubscribe_all('sys.*')
- s.inject('sys.foo', 'hello')
-
-if __name__ == "__main__":
- main()
-
diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py
index 51f2ea61a2..5ee74977a5 100644
--- a/tools/python/xen/xend/XendDomain.py
+++ b/tools/python/xen/xend/XendDomain.py
@@ -30,7 +30,6 @@ import XendDomainInfo
from xen.xend import XendRoot
from xen.xend import XendCheckpoint
-from xen.xend import EventServer
from xen.xend.XendError import XendError
from xen.xend.XendLogging import log
from xen.xend.server import relocate
@@ -38,7 +37,6 @@ from xen.xend.server import relocate
xc = xen.lowlevel.xc.new()
xroot = XendRoot.instance()
-eserver = EventServer.instance()
__all__ = [ "XendDomain" ]
@@ -329,20 +327,21 @@ class XendDomain:
def domain_unpause(self, domid):
"""Unpause domain execution."""
- dominfo = self.domain_lookup(domid)
- eserver.inject('xend.domain.unpause', [dominfo.getName(),
- dominfo.getDomid()])
try:
+ dominfo = self.domain_lookup(domid)
+ log.info("Domain %s (%d) unpaused.", dominfo.getName(),
+ dominfo.getDomid())
return xc.domain_unpause(dom=dominfo.getDomid())
except Exception, ex:
raise XendError(str(ex))
-
+
+
def domain_pause(self, domid):
"""Pause domain execution."""
- dominfo = self.domain_lookup(domid)
- eserver.inject('xend.domain.pause', [dominfo.getName(),
- dominfo.getDomid()])
try:
+ dominfo = self.domain_lookup(domid)
+ log.info("Domain %s (%d) paused.", dominfo.getName(),
+ dominfo.getDomid())
return xc.domain_pause(dom=dominfo.getDomid())
except Exception, ex:
raise XendError(str(ex))
diff --git a/tools/python/xen/xend/XendRoot.py b/tools/python/xen/xend/XendRoot.py
index 2306f0d31f..5162163cba 100644
--- a/tools/python/xen/xend/XendRoot.py
+++ b/tools/python/xen/xend/XendRoot.py
@@ -28,15 +28,12 @@ import os
import os.path
import sys
-import EventServer
from XendLogging import XendLogging
from XendError import XendError
-# Initial create of the event server.
-eserver = EventServer.instance()
-
import sxp
+
class XendRoot:
"""Root of the management classes."""
@@ -96,9 +93,7 @@ class XendRoot:
self.config = None
self.logging = None
self.configure()
- eserver.subscribe('xend.*', self.event_handler)
- #eserver.subscribe('xend.domain.created', self.event_handler)
- #eserver.subscribe('xend.domain.died', self.event_handler)
+
def add_component(self, name, val):
"""Add a xend component.
@@ -118,9 +113,6 @@ class XendRoot:
"""
return self.components.get(name)
- def start(self):
- eserver.inject('xend.start', 0)
-
def _format(self, msg, args):
if args:
return str(msg) % args
diff --git a/tools/python/xen/xend/server/SrvDaemon.py b/tools/python/xen/xend/server/SrvDaemon.py
index 71ae1c3aa3..0248d18ab7 100644
--- a/tools/python/xen/xend/server/SrvDaemon.py
+++ b/tools/python/xen/xend/server/SrvDaemon.py
@@ -2,6 +2,7 @@
## Xen controller daemon
## Copyright (c) 2004, K A Fraser (University of Cambridge)
## Copyright (C) 2004, Mike Wray <mike.wray@hp.com>
+## Copyright (C) 2005, XenSource Ltd
###########################################################
import os
@@ -13,20 +14,14 @@ import pwd
import re
import traceback
-from xen.xend import EventServer
from xen.xend.server import SrvServer
from xen.xend.XendLogging import log
-from xen.xend import XendRoot
import event
import relocate
from params import *
-eserver = EventServer.instance()
-xroot = XendRoot.instance()
-
-
class Daemon:
"""The xend daemon.
"""
diff --git a/tools/python/xen/xend/server/SrvRoot.py b/tools/python/xen/xend/server/SrvRoot.py
index 9137aae39b..51b4c4126f 100644
--- a/tools/python/xen/xend/server/SrvRoot.py
+++ b/tools/python/xen/xend/server/SrvRoot.py
@@ -13,10 +13,9 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
+# Copyright (C) 2005 XenSource Ltd
#============================================================================
-from xen.xend import XendRoot
-xroot = XendRoot.instance()
from xen.web.SrvDir import SrvDir
class SrvRoot(SrvDir):
@@ -39,8 +38,6 @@ class SrvRoot(SrvDir):
self.add(name, klass)
for (name, klass) in self.subdirs:
self.get(name)
- xroot.start()
def __repr__(self):
return "<SrvRoot %x %s>" %(id(self), self.table.keys())
-
diff --git a/tools/python/xen/xend/server/event.py b/tools/python/xen/xend/server/event.py
index d8a03a521f..c9d3257738 100644
--- a/tools/python/xen/xend/server/event.py
+++ b/tools/python/xen/xend/server/event.py
@@ -24,12 +24,10 @@ from xen.web import protocol, tcp, unix
from xen.xend import scheduler
from xen.xend import sxp
from xen.xend import PrettyPrint
-from xen.xend import EventServer
from xen.xend.XendError import XendError
from xen.xend import XendRoot
-eserver = EventServer.instance()
xroot = XendRoot.instance()
@@ -44,13 +42,7 @@ class EventProtocol(protocol.Protocol):
self.daemon = daemon
# Event queue.
self.queue = []
- # Subscribed events.
- self.events = []
self.parser = sxp.Parser()
- self.pretty = 0
-
- # For debugging subscribe to everything and make output pretty.
- #self.subscribe(['*'])
self.pretty = 1
def dataReceived(self, data):
@@ -74,7 +66,7 @@ class EventProtocol(protocol.Protocol):
scheduler.now(self.connectionLost)
def connectionLost(self, reason=None):
- self.unsubscribe()
+ pass
def send_reply(self, sxpr):
io = StringIO.StringIO()
@@ -105,16 +97,6 @@ class EventProtocol(protocol.Protocol):
def send_event(self, val):
return self.send_reply(['event', val[0], val[1]])
- def unsubscribe(self):
- for event in self.events:
- eserver.unsubscribe(event, self.queue_event)
-
- def subscribe(self, events):
- self.unsubscribe()
- for event in events:
- eserver.subscribe(event, self.queue_event)
- self.events = events
-
def queue_event(self, name, v):
# Despite the name we don't queue the event here.
# We send it because the transport will queue it.
@@ -132,7 +114,7 @@ class EventProtocol(protocol.Protocol):
op_method = getattr(self, op_method_name, self.operror)
return op_method(op_name, req)
- def op_help(self, name, req):
+ def op_help(self, _1, _2):
def nameop(x):
if x.startswith('op_'):
return x[3:].replace('_', '.')
@@ -142,37 +124,27 @@ class EventProtocol(protocol.Protocol):
l = [ nameop(k) for k in dir(self) if k.startswith('op_') ]
return l
- def op_quit(self, name, req):
+ def op_quit(self, _1, _2):
self.loseConnection()
- def op_exit(self, name, req):
+ def op_exit(self, _1, _2):
sys.exit(0)
- def op_pretty(self, name, req):
+ def op_pretty(self, _1, _2):
self.pretty = 1
- def op_info(self, name, req):
+ def op_info(self, _1, _2):
val = ['info']
#val += self.daemon.blkifs()
#val += self.daemon.netifs()
#val += self.daemon.usbifs()
return val
- def op_sys_subscribe(self, name, v):
- # (sys.subscribe event*)
- # Subscribe to the events:
- self.subscribe(v[1:])
-
- def op_sys_inject(self, name, v):
- # (sys.inject event)
- event = v[1]
- eserver.inject(sxp.name(event), event)
-
- def op_trace(self, name, v):
+ def op_trace(self, _, v):
mode = (v[1] == 'on')
self.daemon.tracing(mode)
- def op_log_stderr(self, name, v):
+ def op_log_stderr(self, _, v):
mode = v[1]
logging = xroot.get_logging()
if mode == 'on':
@@ -180,11 +152,11 @@ class EventProtocol(protocol.Protocol):
else:
logging.removeLogStderr()
- def op_domain_ls(self, name, v):
+ def op_domain_ls(self, _1, _2):
xd = xroot.get_component("xen.xend.XendDomain")
return xd.list_names()
- def op_domain_configure(self, name, v):
+ def op_domain_configure(self, _, v):
domid = sxp.child_value(v, "dom")
config = sxp.child_value(v, "config")
if domid is None:
@@ -194,7 +166,7 @@ class EventProtocol(protocol.Protocol):
xd = xroot.get_component("xen.xend.XendDomain")
xd.domain_configure(domid, config)
- def op_domain_unpause(self, name, v):
+ def op_domain_unpause(self, _, v):
domid = sxp.child_value(v, "dom")
if domid is None:
raise XendError("missing domain id")
@@ -206,10 +178,10 @@ class EventFactory(protocol.ServerFactory):
"""
def __init__(self, daemon):
- #protocol.ServerFactory.__init__(self)
+ protocol.ServerFactory.__init__(self)
self.daemon = daemon
- def buildProtocol(self, addr):
+ def buildProtocol(self, _):
return EventProtocol(self.daemon)
def listenEvent(daemon):
diff --git a/tools/python/xen/xend/server/relocate.py b/tools/python/xen/xend/server/relocate.py
index 42d3720409..13bac8e5f8 100644
--- a/tools/python/xen/xend/server/relocate.py
+++ b/tools/python/xen/xend/server/relocate.py
@@ -24,13 +24,11 @@ from xen.web import protocol, tcp, unix
from xen.xend import scheduler
from xen.xend import sxp
-from xen.xend import EventServer
from xen.xend.XendError import XendError
from xen.xend import XendRoot
from xen.xend.XendLogging import log
-eserver = EventServer.instance()
xroot = XendRoot.instance()