[PATCH rest-dbus 3/3] Address sdbus service discovery issue

OpenBMC Patches patches at stwcx.xyz
Fri Oct 30 04:39:37 AEDT 2015


From: Brad Bishop <bradleyb at us.ibm.com>

Objects created with sdbus bindings present
themselves differently than python-dbus and gdbus
when introspected.  The OpenBMCMapper module
has a parser that hides that so use that for
service discovery.
---
 rest-dbus | 32 +++-----------------------------
 1 file changed, 3 insertions(+), 29 deletions(-)

diff --git a/rest-dbus b/rest-dbus
index 34fcb65..ddd958b 100644
--- a/rest-dbus
+++ b/rest-dbus
@@ -6,7 +6,7 @@ import SocketServer
 import json
 import os
 import sys
-from xml.etree import ElementTree
+from OpenBMCMapper import IntrospectionParser
 
 busses = {
     'system': dbus.SystemBus,
@@ -98,35 +98,9 @@ class DBusRestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
         return obj
 
     def handle_service(self, bus_name):
-        objects = []
-
-        def parse_introspection_data(data):
-            tree = ElementTree.fromstring(data)
-            children = []
-            has_interfaces = False
-            for node in tree:
-                if node.tag == 'node':
-                    children.append(node.attrib['name'])
-                elif node.tag == 'interface':
-                    has_interfaces = True
-            return (has_interfaces, children)
-
-        def walk_object_tree(obj_path):
-            obj = self.get_object_or_404(bus_name, obj_path)
-
-            iface = dbus.Interface(obj, 'org.freedesktop.DBus.Introspectable')
-            data = iface.Introspect()
-            (has_interfaces, children) = parse_introspection_data(data)
-            if has_interfaces:
-                objects.append({'path': obj_path})
-            for child in children:
-                if obj_path == '/':
-                    obj_path = ''
-
-                walk_object_tree('/'.join([obj_path, child]))
-                
+        data = IntrospectionParser(bus_name, self.bus).introspect()
+        objects = [ { 'path': x } for x in data.iterkeys() ]
 
-        walk_object_tree('/')
         return DBusRestJSONResponse({
             'status': 'ok',
             'bus_name': bus_name,
-- 
2.6.0




More information about the openbmc mailing list