qubesmanager.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. # pylint: disable=no-self-use,unused-argument,too-few-public-methods
  35. @qubes.ext.handler('status:error')
  36. def on_status_error(self, vm, status, message):
  37. try:
  38. qubes_manager = self._system_bus.get_object(
  39. 'org.qubesos.QubesManager',
  40. '/org/qubesos/QubesManager')
  41. qubes_manager.notify_error(vm.name, message,
  42. dbus_interface='org.qubesos.QubesManager')
  43. except dbus.DBusException:
  44. # ignore the case when no qubes-manager is running
  45. pass
  46. @qubes.ext.handler('status:no-error')
  47. def on_status_no_error(self, vm, status, message):
  48. try:
  49. qubes_manager = self._system_bus.get_object(
  50. 'org.qubesos.QubesManager',
  51. '/org/qubesos/QubesManager')
  52. qubes_manager.clear_error_exact(vm.name, message,
  53. dbus_interface='org.qubesos.QubesManager')
  54. except dbus.DBusException:
  55. # ignore the case when no qubes-manager is running
  56. pass