qubesmanager.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program 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
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. '''Qubes Manager hooks.
  24. .. warning:: API defined here is not declared stable.
  25. '''
  26. import dbus
  27. import qubes.ext
  28. class QubesManager(qubes.ext.Extension):
  29. def __init__(self, *args, **kwargs):
  30. super(QubesManager, self).__init__(*args, **kwargs)
  31. try:
  32. self._system_bus = dbus.SystemBus()
  33. except dbus.exceptions.DBusException:
  34. # we can't access Qubes() object here to check for offline mode,
  35. # so lets assume it is this case...
  36. self._system_bus = None
  37. # pylint: disable=no-self-use,unused-argument,too-few-public-methods
  38. @qubes.ext.handler('status:error')
  39. def on_status_error(self, vm, event, status, message):
  40. if self._system_bus is None:
  41. return
  42. try:
  43. qubes_manager = self._system_bus.get_object(
  44. 'org.qubesos.QubesManager',
  45. '/org/qubesos/QubesManager')
  46. qubes_manager.notify_error(vm.name, message,
  47. dbus_interface='org.qubesos.QubesManager')
  48. except dbus.DBusException:
  49. # ignore the case when no qubes-manager is running
  50. pass
  51. @qubes.ext.handler('status:no-error')
  52. def on_status_no_error(self, vm, event, status, message):
  53. if self._system_bus is None:
  54. return
  55. try:
  56. qubes_manager = self._system_bus.get_object(
  57. 'org.qubesos.QubesManager',
  58. '/org/qubesos/QubesManager')
  59. qubes_manager.clear_error_exact(vm.name, message,
  60. dbus_interface='org.qubesos.QubesManager')
  61. except dbus.DBusException:
  62. # ignore the case when no qubes-manager is running
  63. pass