summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
Diffstat (limited to 'module')
-rw-r--r--module/obmc/wsgi/apps/rest_dbus.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py
index 41538bc..5719236 100644
--- a/module/obmc/wsgi/apps/rest_dbus.py
+++ b/module/obmc/wsgi/apps/rest_dbus.py
@@ -63,6 +63,22 @@ def get_type_signature_by_introspection(bus, service, object_path,
return type_signature
+def get_method_signature(bus, service, object_path, interface, method):
+ obj = bus.get_object(service, object_path)
+ iface = dbus.Interface(obj, 'org.freedesktop.DBus.Introspectable')
+ xml_string = iface.Introspect()
+ arglist = []
+
+ root = ElementTree.fromstring(xml_string)
+ for dbus_intf in root.findall('interface'):
+ if (dbus_intf.get('name') == interface):
+ for dbus_method in dbus_intf.findall('method'):
+ if(dbus_method.get('name') == method):
+ for arg in dbus_method.findall('arg'):
+ arglist.append(arg.get('type'))
+ return arglist
+
+
def split_struct_signature(signature):
struct_regex = r'(b|y|n|i|x|q|u|t|d|s|a\(.+?\)|\(.+?\))|a\{.+?\}+?'
struct_matches = re.findall(struct_regex, signature)
@@ -299,6 +315,8 @@ class MethodHandler(RouteHandler):
def __init__(self, app, bus):
super(MethodHandler, self).__init__(
app, bus, self.verbs, self.rules, self.content_type)
+ self.service = ''
+ self.interface = ''
def find(self, path, method):
busses = self.try_mapper_call(
@@ -321,8 +339,29 @@ class MethodHandler(RouteHandler):
return request.route_data['method']()
except dbus.exceptions.DBusException, e:
+ paramlist = []
if e.get_dbus_name() == DBUS_INVALID_ARGS:
+
+ signature_list = get_method_signature(self.bus, self.service,
+ path, self.interface,
+ method)
+ if not signature_list:
+ abort(400, "Failed to get method signature: %s" % str(e))
+ if len(signature_list) != len(request.parameter_list):
+ abort(400, "Invalid number of args")
+ converted_value = None
+ try:
+ for index, expected_type in enumerate(signature_list):
+ value = request.parameter_list[index]
+ converted_value = convert_type(expected_type, value)
+ paramlist.append(converted_value)
+ request.parameter_list = paramlist
+ self.do_post(path, method)
+ return
+ except Exception as ex:
+ abort(400, "Failed to convert the types")
abort(400, str(e))
+
if e.get_dbus_name() == DBUS_TYPE_ERROR:
abort(400, str(e))
raise
@@ -348,6 +387,8 @@ class MethodHandler(RouteHandler):
m = self.find_method_in_interface(
method, obj, x, y.get('method'))
if m:
+ self.service = bus
+ self.interface = x
return m
OpenPOWER on IntegriCloud