server: Add command line options
Add four non-optional command line options for the server:
namespace
Instruct the server what dbus path namespaces to watch.
interface_namespace
Instruct the server which interfaces to watch.
blacklist
Instruct the server to ignore specific paths.
interface blacklist
Instruct the server to ignore specific interfaces.
Paths are checked before interfaces. If a path does not match the
interface configuration does not matter.
Paths are first checked against the blacklist and then allowed if
the path contains the namespace or the namespace contains the path.
Interfaces are slightly different; the blacklist is checked as with
paths but then the interface is only allowed if it contains the namespace.
Resolves: openbmc/openbmc#1767
Change-Id: Ib83d5163681fc49114e4c86be177d11b8528322f
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/obmc/mapper/server.py b/obmc/mapper/server.py
index 0766daf..07830e3 100644
--- a/obmc/mapper/server.py
+++ b/obmc/mapper/server.py
@@ -21,7 +21,6 @@
import gobject
import xml.etree.ElementTree as ET
import obmc.utils.pathtree
-import obmc.utils.misc
import obmc.mapper
import obmc.dbuslib.bindings
import obmc.dbuslib.enums
@@ -225,12 +224,12 @@
class ObjectMapper(dbus.service.Object):
- def __init__(self, bus, path,
- intf_match=obmc.utils.misc.org_dot_openbmc_match):
+ def __init__(
+ self, bus, path, namespaces, interface_namespaces,
+ blacklist, interface_blacklist):
super(ObjectMapper, self).__init__(bus, path)
self.cache = obmc.utils.pathtree.PathTree()
self.bus = bus
- self.intf_match = intf_match
self.service = None
self.index = {}
self.manager = Manager(bus, obmc.dbuslib.bindings.OBJ_PREFIX)
@@ -238,6 +237,11 @@
self.bus_map = {}
self.defer_signals = {}
self.bus_map[self.unique] = obmc.mapper.MAPPER_NAME
+ self.namespaces = namespaces
+ self.interface_namespaces = interface_namespaces
+ self.blacklist = blacklist
+ self.blacklist.append(obmc.mapper.MAPPER_PATH)
+ self.interface_blacklist = interface_blacklist
# add my object mananger instance
self.add_new_objmgr(obmc.dbuslib.bindings.OBJ_PREFIX, self.unique)
@@ -444,14 +448,34 @@
for path, items in bus_items.iteritems():
self.update_interfaces(path, str(owner), old=[], new=items)
+ def path_match(self, path):
+ match = False
+
+ if not any([x for x in self.blacklist if x in path]):
+ # not blacklisted
+
+ if any([x for x in self.namespaces if x in path]):
+ # a watched namespace contains the path
+ match = True
+ elif any([path for x in self.namespaces if path in x]):
+ # the path contains a watched namespace
+ match = True
+
+ return match
+
+ def interface_match(self, interface):
+ match = True
+
+ if any([x for x in self.interface_blacklist if x in interface]):
+ # not blacklisted
+ match = False
+ elif not any([x for x in self.interface_namespaces if x in interface]):
+ # the interface contains a watched interface namespace
+ match = False
+
+ return match
+
def discover(self, owners=[]):
- def match(iface):
- return iface == dbus.BUS_DAEMON_IFACE + '.ObjectManager' or \
- self.intf_match(iface)
-
- subtree_match = lambda x: obmc.utils.misc.org_dot_openbmc_match(
- x, sep='/', prefix='/')
-
if not owners:
owned_names = filter(
lambda x: not obmc.dbuslib.bindings.is_unique(x),
@@ -465,8 +489,8 @@
self.bus, o, '/',
self.discovery_callback,
self.discovery_error,
- subtree_match=subtree_match,
- iface_match=self.intf_match)
+ subtree_match=self.path_match,
+ iface_match=self.interface_match)
def valid_signal(self, name):
if obmc.dbuslib.bindings.is_unique(name):
@@ -477,7 +501,7 @@
def get_signal_interfaces(self, owner, interfaces):
filtered = []
if self.valid_signal(owner):
- filtered = [str(x) for x in interfaces if self.intf_match(x)]
+ filtered = [str(x) for x in interfaces if self.interface_match(x)]
return filtered
@@ -733,10 +757,20 @@
pass
-def server_main():
+def server_main(
+ path_namespaces,
+ interface_namespaces,
+ blacklists,
+ interface_blacklists):
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
- o = ObjectMapper(bus, obmc.mapper.MAPPER_PATH)
+ o = ObjectMapper(
+ bus,
+ obmc.mapper.MAPPER_PATH,
+ path_namespaces,
+ interface_namespaces,
+ blacklists,
+ interface_blacklists)
loop = gobject.MainLoop()
loop.run()