phosphor-gevent: enable websocket support

Set 'WebSocketHandler' as the handler_class.

Websockets are being supported to allow the REST server to be able to
"push" events to clients.

Change-Id: I4c5536ae9070635c00330bb59fc93d3b4382b461
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py
index 4e5df53..c3c42ef 100644
--- a/module/obmc/wsgi/apps/rest_dbus.py
+++ b/module/obmc/wsgi/apps/rest_dbus.py
@@ -1045,7 +1045,7 @@
 
 
 class App(Bottle):
-    def __init__(self):
+    def __init__(self, **kw):
         super(App, self).__init__(autojson=False)
         self.bus = dbus.SystemBus()
         self.mapper = obmc.mapper.Mapper(self.bus)
diff --git a/servers/gevent/phosphor-gevent b/servers/gevent/phosphor-gevent
index 9767407..7907880 100644
--- a/servers/gevent/phosphor-gevent
+++ b/servers/gevent/phosphor-gevent
@@ -21,6 +21,11 @@
 import os
 import gevent
 from gevent.pywsgi import WSGIServer
+have_wsock = True
+try:
+    from geventwebsocket.handler import WebSocketHandler
+except ImportError:
+    have_wsock = False
 
 if __name__ == '__main__':
     if len(sys.argv) < 2:
@@ -32,7 +37,10 @@
     default_cert = os.path.join(
         sys.prefix, 'share', os.path.basename(__file__), 'cert.pem')
 
-    app = App()
+    kw = {}
+    if have_wsock:
+        kw['have_wsock'] = True
+    app = App(**kw)
 
     if os.environ.get('LISTEN_PID', None) == str(os.getpid()):
         FIRST_SYSTEMD_SOCKET_FD = 3
@@ -42,6 +50,9 @@
     else:
         bind = ('', 443)
 
+    kw = {}
+    if have_wsock:
+        kw['handler_class'] = WebSocketHandler
     server = WSGIServer(
-        bind, app, keyfile=default_cert, certfile=default_cert)
+        bind, app, keyfile=default_cert, certfile=default_cert, **kw)
     server.serve_forever()