Skip to content
Snippets Groups Projects
Commit 702abcf9 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

rpc: Use definitions directly instead of via generated code


Until now “autotools/build-rpc” would read the definition of all RPCs
and write them to a new file, “lib/_generated_rpc.py” with some
modifications. With this patch the generated code loads the definitions
and, at module load time, gets references to the actual definitions.
Further patches will even remove the calls to the post-processing
functions from the generated code.

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent a09f9847
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,8 @@ def _WritePreamble(sw):
sw.Write("")
sw.Write("\"\"\"")
sw.Write("")
sw.Write("from ganeti import rpc_defs")
sw.Write("")
def _WrapCode(line):
......@@ -112,6 +114,9 @@ def _WriteBaseClass(sw, clsname, calls):
sw.Write("pass")
return
sw.Write("_CALLS = rpc_defs.CALLS[%r]", clsname)
sw.Write("")
for (name, kind, timeout, args, postproc, desc) in calls:
funcargs = ["self"]
......@@ -127,6 +132,8 @@ def _WriteBaseClass(sw, clsname, calls):
assert "read_timeout" not in funcargs
funcargs.append("read_timeout=%s" % timeout)
funcargs.append("_def=_CALLS[%r]" % name)
funcdef = "def call_%s(%s):" % (name, utils.CommaJoin(funcargs))
for line in _WrapCode(funcdef):
sw.Write(line)
......@@ -143,18 +150,15 @@ def _WriteBaseClass(sw, clsname, calls):
if postproc:
buf.write("%s(" % postproc)
buf.write("self._Call(")
buf.write("self._Call(_def, ")
if kind == _SINGLE:
buf.write("[node]")
else:
buf.write("node_list")
buf.write(", \"%s\", read_timeout, [%s], [%s])" %
(name,
# Argument definitions
utils.CommaJoin(map(compat.snd, args)),
# Function arguments
utils.CommaJoin(map(compat.fst, args))))
buf.write(", read_timeout, [%s])" %
# Function arguments
utils.CommaJoin(map(compat.fst, args)))
if kind == _SINGLE:
buf.write("[node]")
......
......@@ -430,13 +430,14 @@ class _RpcClientBase:
else:
return encoder_fn(argkind)(value)
def _Call(self, node_list, procedure, timeout, argdefs, args):
def _Call(self, cdef, node_list, timeout, args):
"""Entry point for automatically generated RPC wrappers.
"""
assert len(args) == len(argdefs), "Wrong number of arguments"
(procedure, _, _, argdefs, _, _) = cdef
body = serializer.DumpJson(map(self._encoder, zip(argdefs, args)),
body = serializer.DumpJson(map(self._encoder,
zip(map(compat.snd, argdefs), args)),
indent=False)
return self._proc(node_list, procedure, body, read_timeout=timeout)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment