summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-07-09 20:11:35 -0400
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-07-10 00:35:42 -0400
commitcb2e1b308c51036667766a7d6b9b288399470b99 (patch)
tree4e9b76fd42ee70a1567aa429736f5c743af1029c
parent8b633b7ea4ab671a73c1f57d878041f83f672a7e (diff)
downloadphosphor-objmgr-cb2e1b308c51036667766a7d6b9b288399470b99.tar.gz
phosphor-objmgr-cb2e1b308c51036667766a7d6b9b288399470b99.zip
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>
-rw-r--r--obmc/mapper/server.py64
-rw-r--r--phosphor-mapper24
2 files changed, 72 insertions, 16 deletions
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 dbus.mainloop.glib
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 Manager(obmc.dbuslib.bindings.DbusObjectManager):
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 @@ class ObjectMapper(dbus.service.Object):
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 @@ class ObjectMapper(dbus.service.Object):
for path, items in bus_items.iteritems():
self.update_interfaces(path, str(owner), old=[], new=items)
- def discover(self, owners=[]):
- def match(iface):
- return iface == dbus.BUS_DAEMON_IFACE + '.ObjectManager' or \
- self.intf_match(iface)
+ 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
- subtree_match = lambda x: obmc.utils.misc.org_dot_openbmc_match(
- x, sep='/', prefix='/')
+ 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=[]):
if not owners:
owned_names = filter(
lambda x: not obmc.dbuslib.bindings.is_unique(x),
@@ -465,8 +489,8 @@ class ObjectMapper(dbus.service.Object):
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 @@ class ObjectMapper(dbus.service.Object):
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 @@ class ObjectMapper(dbus.service.Object):
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()
diff --git a/phosphor-mapper b/phosphor-mapper
index 2f35daa..4e28c1c 100644
--- a/phosphor-mapper
+++ b/phosphor-mapper
@@ -18,6 +18,28 @@
import sys
import obmc.mapper.server
+from argparse import ArgumentParser
if __name__ == '__main__':
- sys.exit(obmc.mapper.server.server_main())
+ parser = ArgumentParser()
+ parser.add_argument(
+ '-p', '--path_namespaces',
+ required=True)
+ parser.add_argument(
+ '-i', '--interface_namespaces',
+ required=True)
+ parser.add_argument(
+ '-b', '--blacklists',
+ default="")
+ parser.add_argument(
+ '-n', '--interface_blacklists',
+ default="")
+
+ args = parser.parse_args()
+
+ sys.exit(
+ obmc.mapper.server.server_main(
+ path_namespaces=args.path_namespaces.split(),
+ interface_namespaces=args.interface_namespaces.split(),
+ blacklists=args.blacklists.split(),
+ interface_blacklists=args.interface_blacklists.split()))
OpenPOWER on IntegriCloud