qubesmanager.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #
  2. # The Qubes OS Project, https://www.qubes-os.org/
  3. #
  4. # Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  5. # Copyright (C) 2014 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  8. #
  9. # This library is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU Lesser General Public
  11. # License as published by the Free Software Foundation; either
  12. # version 2.1 of the License, or (at your option) any later version.
  13. #
  14. # This library is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. # Lesser General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Lesser General Public
  20. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  21. #
  22. '''Qubes Manager hooks.
  23. .. warning:: API defined here is not declared stable.
  24. '''
  25. import dbus
  26. import qubes.ext
  27. class QubesManager(qubes.ext.Extension):
  28. def __init__(self, *args, **kwargs):
  29. super(QubesManager, self).__init__(*args, **kwargs)
  30. try:
  31. self._system_bus = dbus.SystemBus()
  32. except dbus.exceptions.DBusException:
  33. # we can't access Qubes() object here to check for offline mode,
  34. # so lets assume it is this case...
  35. self._system_bus = None
  36. # pylint: disable=no-self-use,unused-argument,too-few-public-methods
  37. @qubes.ext.handler('status:error')
  38. def on_status_error(self, vm, event, status, message):
  39. if self._system_bus is None:
  40. return
  41. try:
  42. qubes_manager = self._system_bus.get_object(
  43. 'org.qubesos.QubesManager',
  44. '/org/qubesos/QubesManager')
  45. qubes_manager.notify_error(vm.name, message,
  46. dbus_interface='org.qubesos.QubesManager')
  47. except dbus.DBusException:
  48. # ignore the case when no qubes-manager is running
  49. pass
  50. @qubes.ext.handler('status:no-error')
  51. def on_status_no_error(self, vm, event, status, message):
  52. if self._system_bus is None:
  53. return
  54. try:
  55. qubes_manager = self._system_bus.get_object(
  56. 'org.qubesos.QubesManager',
  57. '/org/qubesos/QubesManager')
  58. qubes_manager.clear_error_exact(vm.name, message,
  59. dbus_interface='org.qubesos.QubesManager')
  60. except dbus.DBusException:
  61. # ignore the case when no qubes-manager is running
  62. pass