Yeela Kaplan has uploaded a new change for review. Change subject: jsonrpcvdscli: create a client for vdsm with jsonrpc ......................................................................
jsonrpcvdscli: create a client for vdsm with jsonrpc Change-Id: Ib9dbd70d28968db1305628281015f7b2379c8058 Signed-off-by: Yeela Kaplan <[email protected]> --- A lib/vdsm/jsonrpcvdscli.py 1 file changed, 80 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/03/39203/1 diff --git a/lib/vdsm/jsonrpcvdscli.py b/lib/vdsm/jsonrpcvdscli.py new file mode 100644 index 0000000..3dd8258 --- /dev/null +++ b/lib/vdsm/jsonrpcvdscli.py @@ -0,0 +1,80 @@ +# +# Copyright 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# + +from functools import partial + +from rpc.Bridge import InvalidCall +from yajsonrpc import \ + JsonRpcError, \ + JsonRpcClient, \ + JsonRpcRequest, \ + CALL_TIMEOUT + + +command_converter = { + 'ping': 'Host.ping', + 'destroy': 'VM.destroy', + 'getVmStats': 'VM.getStats', + 'migrationCreate': 'VM.migrationCreate', +} + + +class _Server: + + def __init__(self, client): + self._client = client + + def _callMethod(self, methodName, *args): + try: + method = command_converter[methodName] + except AttributeError as e: + raise InvalidCall(methodName, args, e) + + req = JsonRpcRequest(methodName, args, reqId=str(uuid4())) + call = self._client.call_async(req) + call.wait(CALL_TIMEOUT) + + resp = call.responses[0] + + if resp.error is not None: + raise JsonRpcError(resp.error['code'], resp.error['message']) + + return resp.result + + def migrationCreate(self, params): + self._callMethod(command_converter['migrationCreate'], + params['vmId'], + params) + return {'status': {'code': 0}} + + def __getattr__(self, methodName): + return partial(self._callMethod(methodName)) + + def __del__(self): + self._client.close() + + + +def connect(reactor, client_socket): + client = JsonRpcClient(reactor.createClient(client_socket)) + client.connect() + server = _Server(client) + + return server \ No newline at end of file -- To view, visit https://gerrit.ovirt.org/39203 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib9dbd70d28968db1305628281015f7b2379c8058 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Yeela Kaplan <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
