mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-12 09:00:57 +00:00
Possibility to get the server version over JSON-RPC/Websocket.
This commit is contained in:
parent
93058f92d4
commit
ed8b93dee2
@ -22,8 +22,9 @@ JSON-RPC protocol over Websockets.
|
||||
import zmq
|
||||
import uuid
|
||||
import tornado.websocket
|
||||
from ..version import __version__
|
||||
from tornado.escape import json_decode
|
||||
from ..version import __version__
|
||||
from ..jsonrpc import JSONRPCResponse
|
||||
from ..jsonrpc import JSONRPCParseError
|
||||
from ..jsonrpc import JSONRPCInvalidRequest
|
||||
from ..jsonrpc import JSONRPCMethodNotFound
|
||||
@ -52,6 +53,20 @@ class JSONRPCWebSocket(tornado.websocket.WebSocketHandler):
|
||||
self._session_id = str(uuid.uuid4())
|
||||
self.zmq_router = zmq_router
|
||||
|
||||
# special built-in to return the server version
|
||||
self.register_destination("builtin.version", self._server_version)
|
||||
|
||||
def _server_version(self, request_id, params):
|
||||
"""
|
||||
Builtin destination to return the server version.
|
||||
|
||||
:param request_id: JSON-RPC call identifier
|
||||
:param params: JSON-RPC method params (not used here)
|
||||
"""
|
||||
|
||||
json_message = {"version": __version__}
|
||||
self.write_message(JSONRPCResponse(json_message, request_id)())
|
||||
|
||||
@property
|
||||
def session_id(self):
|
||||
"""
|
||||
@ -101,6 +116,10 @@ class JSONRPCWebSocket(tornado.websocket.WebSocketHandler):
|
||||
:param module: module string
|
||||
"""
|
||||
|
||||
if destination.startswith("builtin") and destination in cls.destinations:
|
||||
# ignore new built-in destination registration if already registered
|
||||
return
|
||||
|
||||
# Make sure the destination is not already registered
|
||||
# by another module for instance
|
||||
assert destination not in cls.destinations
|
||||
@ -114,8 +133,6 @@ class JSONRPCWebSocket(tornado.websocket.WebSocketHandler):
|
||||
"""
|
||||
|
||||
log.info("Websocket client {} connected".format(self.session_id))
|
||||
# send this server version when a client connects
|
||||
self.write_message({"version": __version__})
|
||||
self.clients.add(self)
|
||||
|
||||
def on_message(self, message):
|
||||
@ -150,9 +167,9 @@ class JSONRPCWebSocket(tornado.websocket.WebSocketHandler):
|
||||
# This is a notification, silently ignore this error...
|
||||
return
|
||||
|
||||
if method.startswith("builtin"):
|
||||
if method.startswith("builtin") and request_id:
|
||||
log.info("calling built-in method {}".format(method))
|
||||
self.destinations[method]()
|
||||
self.destinations[method](request_id, request.get("params"))
|
||||
return
|
||||
|
||||
module = self.destinations[method]
|
||||
|
@ -115,9 +115,6 @@ class Server(object):
|
||||
# instance.start() # starts the new process
|
||||
#=======================================================================
|
||||
|
||||
# special built-in destination to stop the server
|
||||
# JSONRPCWebSocket.register_destination("builtin.stop", self._cleanup)
|
||||
|
||||
for module in MODULES:
|
||||
instance = module(module.__name__.lower(),
|
||||
"127.0.0.1", # ZeroMQ server address
|
||||
|
Loading…
Reference in New Issue
Block a user