427
427
def get_mandos_dbus_object(bus):
429
log.debug("D-Bus: Connect to: (busname=%r, path=%r)",
430
dbus_busname, server_dbus_path)
428
log.debug("D-Bus: Connect to: (busname=%r, path=%r)",
429
dbus_busname, server_dbus_path)
430
with if_dbus_exception_log_with_exception_and_exit(
431
"Could not connect to Mandos server: %s"):
431
432
mandos_dbus_object = bus.get_object(dbus_busname,
432
433
server_dbus_path)
433
except dbus.exceptions.DBusException:
434
log.critical("Could not connect to Mandos server")
437
434
return mandos_dbus_object
437
@contextlib.contextmanager
438
def if_dbus_exception_log_with_exception_and_exit(*args, **kwargs):
441
except dbus.exceptions.DBusException as e:
442
log.critical(*(args + (e,)), **kwargs)
440
446
def get_managed_objects(object_manager):
441
447
log.debug("D-Bus: %s:%s:%s.GetManagedObjects()", dbus_busname,
442
448
server_dbus_path, dbus.OBJECT_MANAGER_IFACE)
449
with if_dbus_exception_log_with_exception_and_exit(
450
"Failed to access Mandos server through D-Bus:\n%s"):
444
451
with SilenceLogger("dbus.proxies"):
445
452
managed_objects = object_manager.GetManagedObjects()
446
except dbus.exceptions.DBusException as e:
447
log.critical("Failed to access Mandos server through D-Bus:"
450
453
return managed_objects