qubesmanager.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org/
  5. #
  6. # Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2014 Marek Marczykowski-Górecki
  8. # <marmarek@invisiblethingslab.com>
  9. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License along
  22. # with this program; if not, write to the Free Software Foundation, Inc.,
  23. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. #
  25. '''Qubes Manager hooks.
  26. .. warning:: API defined here is not declared stable.
  27. '''
  28. import qubes.ext
  29. import dbus
  30. class QubesManagerExtension(qubes.ext.Extension):
  31. def __init__(self, *args, **kwargs):
  32. super(QubesManagerExtension, self).__init__(*args, **kwargs)
  33. self._system_bus = dbus.SystemBus()
  34. @qubes.ext.handler('status:error')
  35. def on_status_error(self, vm, status, message):
  36. try:
  37. qubes_manager = system_bus.get_object(
  38. 'org.qubesos.QubesManager',
  39. '/org/qubesos/QubesManager')
  40. qubes_manager.notify_error(vm.name, message,
  41. dbus_interface='org.qubesos.QubesManager')
  42. except dbus.DBusException:
  43. # ignore the case when no qubes-manager is running
  44. pass
  45. @qubes.ext.handler('status:no-error')
  46. def on_status_error(self, vm, status, message):
  47. try:
  48. qubes_manager = system_bus.get_object(
  49. 'org.qubesos.QubesManager',
  50. '/org/qubesos/QubesManager')
  51. qubes_manager.clear_error_exact(vm.name, message,
  52. dbus_interface='org.qubesos.QubesManager')
  53. except dbus.DBusException:
  54. # ignore the case when no qubes-manager is running
  55. pass