summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2017-10-11 01:19:17 -0500
committerDeepak Kodihalli <dkodihal@in.ibm.com>2017-10-18 07:13:56 -0500
commitb209dd16eaa495ae3a9fa0fa2e7610fed3c32277 (patch)
tree6117a668364bb30d5ae39be3998c739d975fde19 /module
parent48c7641c79d53be19b8a0c6c33f8b34582791b1c (diff)
downloadphosphor-rest-server-b209dd16eaa495ae3a9fa0fa2e7610fed3c32277.tar.gz
phosphor-rest-server-b209dd16eaa495ae3a9fa0fa2e7610fed3c32277.zip
rest_dbus: add new route for event subscription
Add a route, '/subscribe', to be able to receive notifications from the REST server over a websocket. A client is supposed to create a new websocket by pointing to this route in the URL. In this commit, the implementation of the route is to just write a "Connected" message on the websocket. Change-Id: I38a40b2c17eac3ecdccb131d267baefe20b36572 Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Diffstat (limited to 'module')
-rw-r--r--module/obmc/wsgi/apps/rest_dbus.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py
index c3c42ef..1ad359c 100644
--- a/module/obmc/wsgi/apps/rest_dbus.py
+++ b/module/obmc/wsgi/apps/rest_dbus.py
@@ -719,6 +719,30 @@ class ImagePostHandler(RouteHandler):
pass
+class EventHandler(RouteHandler):
+ ''' Handles the /subscribe route, for clients to be able
+ to subscribe to BMC events. '''
+
+ verbs = ['GET']
+ rules = ['/subscribe']
+
+ def __init__(self, app, bus):
+ super(EventHandler, self).__init__(
+ app, bus, self.verbs, self.rules)
+
+ def find(self, **kw):
+ pass
+
+ def setup(self, **kw):
+ pass
+
+ def do_get(self):
+ wsock = request.environ.get('wsgi.websocket')
+ if not wsock:
+ abort(400, 'Expected WebSocket request.')
+ wsock.send("Connected")
+
+
class ImagePutHandler(RouteHandler):
''' Handles the /upload/image/<filename> route. '''
@@ -1047,6 +1071,9 @@ class ContentCheckerPlugin(object):
class App(Bottle):
def __init__(self, **kw):
super(App, self).__init__(autojson=False)
+
+ self.have_wsock = kw.get('have_wsock', False)
+
self.bus = dbus.SystemBus()
self.mapper = obmc.mapper.Mapper(self.bus)
self.error_callbacks = []
@@ -1090,6 +1117,8 @@ class App(Bottle):
self.image_upload_post_handler = ImagePostHandler(self, self.bus)
self.image_upload_put_handler = ImagePutHandler(self, self.bus)
self.download_dump_get_handler = DownloadDumpHandler(self, self.bus)
+ if self.have_wsock:
+ self.event_handler = EventHandler(self, self.bus)
self.instance_handler = InstanceHandler(self, self.bus)
def install_handlers(self):
@@ -1103,6 +1132,8 @@ class App(Bottle):
self.image_upload_post_handler.install()
self.image_upload_put_handler.install()
self.download_dump_get_handler.install()
+ if self.have_wsock:
+ self.event_handler.install()
# this has to come last, since it matches everything
self.instance_handler.install()
OpenPOWER on IntegriCloud