|
|
@ -16,14 +16,25 @@
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
import aiohttp.errors
|
|
|
|
|
|
|
|
|
|
|
|
from aiohttp.web import WebSocketResponse
|
|
|
|
from aiohttp.web import WebSocketResponse
|
|
|
|
from gns3server.web.route import Route
|
|
|
|
from gns3server.web.route import Route
|
|
|
|
from gns3server.compute.notification_manager import NotificationManager
|
|
|
|
from gns3server.compute.notification_manager import NotificationManager
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NotificationHandler:
|
|
|
|
@asyncio.coroutine
|
|
|
|
|
|
|
|
def process_websocket(ws):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Process ping / pong and close message
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
yield from ws.receive()
|
|
|
|
|
|
|
|
except aiohttp.errors.WSServerHandshakeError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NotificationHandler:
|
|
|
|
@Route.get(
|
|
|
|
@Route.get(
|
|
|
|
r"/notifications/ws",
|
|
|
|
r"/notifications/ws",
|
|
|
|
description="Send notifications using Websockets")
|
|
|
|
description="Send notifications using Websockets")
|
|
|
@ -32,8 +43,7 @@ class NotificationHandler:
|
|
|
|
ws = WebSocketResponse()
|
|
|
|
ws = WebSocketResponse()
|
|
|
|
yield from ws.prepare(request)
|
|
|
|
yield from ws.prepare(request)
|
|
|
|
|
|
|
|
|
|
|
|
# Process ping / pong and close message
|
|
|
|
asyncio.async(process_websocket(ws))
|
|
|
|
asyncio.async(ws.receive())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with notifications.queue() as queue:
|
|
|
|
with notifications.queue() as queue:
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|