mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
The controller has a streaming API
Now we need to link the hypervisor to the controller.
This commit is contained in:
9 files changed
+255
-53
No files matched your search
@@ -18,9 +18,11 @@
|
||||
import asyncio
|
||||
import aiohttp
|
||||
from uuid import UUID, uuid4
|
||||
from contextlib import contextmanager
|
||||
|
||||
from .vm import VM
|
||||
from .udp_link import UDPLink
|
||||
from ..notification_queue import NotificationQueue
|
||||
|
||||
|
||||
class Project:
|
||||
@@ -48,6 +50,7 @@ class Project:
|
||||
self._hypervisors = set()
|
||||
self._vms = {}
|
||||
self._links = {}
|
||||
self._listeners = set()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -140,6 +143,29 @@ class Project:
|
||||
for hypervisor in self._hypervisors:
|
||||
yield from hypervisor.delete("/projects/{}".format(self._id))
|
||||
|
||||
@contextmanager
|
||||
def queue(self):
|
||||
"""
|
||||
Get a queue of notifications
|
||||
|
||||
Use it with Python with
|
||||
"""
|
||||
queue = NotificationQueue()
|
||||
self._listeners.add(queue)
|
||||
yield queue
|
||||
self._listeners.remove(queue)
|
||||
|
||||
def emit(self, action, event, **kwargs):
|
||||
"""
|
||||
Send an event to all the client listening for notifications
|
||||
|
||||
:param action: Action name
|
||||
:param event: Event to send
|
||||
:param kwargs: Add this meta to the notif (project_id for example)
|
||||
"""
|
||||
for listener in self._listeners:
|
||||
listener.put_nowait((action, event, kwargs))
|
||||
|
||||
def __json__(self):
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user