Piotr Kliczewski has uploaded a new change for review.
Change subject: vdscli: map invocation params to dictionary
......................................................................
vdscli: map invocation params to dictionary
We need to be more flexible with parameters provided during execution of
vdscli methods. Now we use api schema to name all the params so we can
match them properly on the server side.
With this change we can call vdscli methods as regular method and do
mapping behind the scene.
Code used for xmlrpc looked like:
self.vdscli.addNetwork(bridge,
*self._get_net_args(vlan, bond, nics, opts))
In above case we are required to prepare named params as array.
Now we can call it:
self.vdscli.addNetwork(bridge,
vlan=vlan, bond=bond, nics=nics, opts=opts))
as well as we can provide only optional params as we want.
This is first step which enable us to provide client side schema
validation.
It is required to extract schema files from jsonrpc rpm due to
dependency needed for python rpm. Now we make schema rpm required for
jsonrpc and python rpm.
Change-Id: Ibac6eab3c519becb29d2b3551111d671bbb79df5
Signed-off-by: pkliczewski <piotr.kliczewski(a)gmail.com>
---
M lib/vdsm/jsonrpcvdscli.py
M tests/crossImportsTests.py.in
M vdsm.spec.in
3 files changed, 29 insertions(+), 3 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/29/45429/1
diff --git a/lib/vdsm/jsonrpcvdscli.py b/lib/vdsm/jsonrpcvdscli.py
index 6e65e0d..e1efb3f 100644
--- a/lib/vdsm/jsonrpcvdscli.py
+++ b/lib/vdsm/jsonrpcvdscli.py
@@ -28,6 +28,7 @@
JsonRpcRequest, \
JsonRpcNoResponseError
+from rpc import vdsmapi
from vdsm import response
from .config import config
@@ -58,10 +59,19 @@
class _Server(object):
def __init__(self, client, compat):
+ self._vapi = vdsmapi.get_api()
self._client = client
self._compat = compat
- def _callMethod(self, methodName, *args):
+ def prepare_args(self, className, methodName, args, kwargs):
+ sym = self._vapi['commands'][className][methodName]
+ allargs = sym.get('data', {}).keys()
+ allargs = [arg[1:] if arg.startswith('*') else arg for arg in allargs]
+ params = dict(zip(allargs, args))
+ params.update(kwargs)
+ return params
+
+ def _callMethod(self, methodName, *args, **kwargs):
try:
method = _COMMAND_CONVERTER[methodName]
except KeyError as e:
@@ -69,7 +79,10 @@
"arguments: %s error: %s" %
(methodName, args, e))
- req = JsonRpcRequest(method, args, reqId=str(uuid4()))
+ class_name, method_name = method.split('.')
+ params = self.prepare_args(class_name, method_name, args, kwargs)
+
+ req = JsonRpcRequest(method, params, reqId=str(uuid4()))
responses = self._client.call(req)
if responses:
resp = responses[0]
diff --git a/tests/crossImportsTests.py.in b/tests/crossImportsTests.py.in
index a3e1d81..acb4ea3 100644
--- a/tests/crossImportsTests.py.in
+++ b/tests/crossImportsTests.py.in
@@ -51,4 +51,7 @@
else:
mods = get_mods(os.path.join(get_python_lib(), pkg_name))
+ # ignore schema dept for this module
+ mods.remove('jsonrpcvdscli')
+
__import__(pkg_name, fromlist=mods)
diff --git a/vdsm.spec.in b/vdsm.spec.in
index d4c1198..729b322 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -260,9 +260,16 @@
An XMLRPC interface for interacting with vdsmd. Primary control interface for
ovirt-engine and vdsClient.
+%package schema
+Summary: VDSM schema
+
+%description schema
+Contains api schema file
+
%package jsonrpc
Summary: VDSM API Server
Requires: %{name}-python = %{version}-%{release}
+Requires: %{name}-schema = %{version}-%{release}
Requires: %{name}-yajsonrpc = %{version}-%{release}
Obsoletes: vdsm-api < 4.16
@@ -301,6 +308,7 @@
Requires: python-cpopen >= 1.2.3-5
Requires: m2crypto
Requires: python-ioprocess >= 0.14
+Requires: %{name}-schema = %{version}-%{release}
%description python
Shared libraries between the various VDSM packages.
@@ -1340,9 +1348,11 @@
%{_datadir}/%{vdsm_name}/rpc/__init__.py*
%{_datadir}/%{vdsm_name}/rpc/bindingjsonrpc.py*
%{_datadir}/%{vdsm_name}/rpc/Bridge.py*
+%{python_sitelib}/yajsonrpc/__init__.py*
+
+%files schema
%{_datadir}/%{vdsm_name}/rpc/vdsmapi-schema.json
%{python_sitelib}/vdsmapi.py*
-%{python_sitelib}/yajsonrpc/__init__.py*
%if ! 0%{?with_gluster}
%exclude %{_datadir}/%{vdsm_name}/rpc/vdsmapi-gluster-schema.json
%endif
--
To view, visit
https://gerrit.ovirt.org/45429
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibac6eab3c519becb29d2b3551111d671bbb79df5
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Piotr Kliczewski <piotr.kliczewski(a)gmail.com>