2015-10-01 21:55:47 +02:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, https://www.qubes-os.org/
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2014 Marek Marczykowski-Górecki
|
|
|
|
# <marmarek@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
|
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
2015-10-01 21:55:47 +02:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is distributed in the hope that it will be useful,
|
2015-10-01 21:55:47 +02:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-10-12 00:11:50 +02:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
2015-10-01 21:55:47 +02:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, see <https://www.gnu.org/licenses/>.
|
2015-10-01 21:55:47 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
'''Qubes Manager hooks.
|
|
|
|
|
|
|
|
.. warning:: API defined here is not declared stable.
|
|
|
|
'''
|
|
|
|
|
|
|
|
import dbus
|
2016-07-13 20:38:46 +02:00
|
|
|
import qubes.ext
|
2015-10-01 21:55:47 +02:00
|
|
|
|
|
|
|
|
2016-03-04 13:03:43 +01:00
|
|
|
class QubesManager(qubes.ext.Extension):
|
2015-10-01 21:55:47 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
2016-03-04 13:03:43 +01:00
|
|
|
super(QubesManager, self).__init__(*args, **kwargs)
|
2016-11-03 02:58:18 +01:00
|
|
|
try:
|
|
|
|
self._system_bus = dbus.SystemBus()
|
|
|
|
except dbus.exceptions.DBusException:
|
|
|
|
# we can't access Qubes() object here to check for offline mode,
|
|
|
|
# so lets assume it is this case...
|
|
|
|
self._system_bus = None
|
2015-10-01 21:55:47 +02:00
|
|
|
|
2015-10-05 23:46:25 +02:00
|
|
|
# pylint: disable=no-self-use,unused-argument,too-few-public-methods
|
|
|
|
|
2015-10-01 21:55:47 +02:00
|
|
|
@qubes.ext.handler('status:error')
|
2016-03-07 01:03:31 +01:00
|
|
|
def on_status_error(self, vm, event, status, message):
|
2016-11-03 02:58:18 +01:00
|
|
|
if self._system_bus is None:
|
|
|
|
return
|
2015-10-01 21:55:47 +02:00
|
|
|
try:
|
2015-10-05 23:46:25 +02:00
|
|
|
qubes_manager = self._system_bus.get_object(
|
2015-10-01 21:55:47 +02:00
|
|
|
'org.qubesos.QubesManager',
|
|
|
|
'/org/qubesos/QubesManager')
|
|
|
|
qubes_manager.notify_error(vm.name, message,
|
|
|
|
dbus_interface='org.qubesos.QubesManager')
|
|
|
|
except dbus.DBusException:
|
|
|
|
# ignore the case when no qubes-manager is running
|
|
|
|
pass
|
|
|
|
|
|
|
|
@qubes.ext.handler('status:no-error')
|
2016-03-07 01:03:31 +01:00
|
|
|
def on_status_no_error(self, vm, event, status, message):
|
2016-11-03 02:58:18 +01:00
|
|
|
if self._system_bus is None:
|
|
|
|
return
|
2015-10-01 21:55:47 +02:00
|
|
|
try:
|
2015-10-05 23:46:25 +02:00
|
|
|
qubes_manager = self._system_bus.get_object(
|
2015-10-01 21:55:47 +02:00
|
|
|
'org.qubesos.QubesManager',
|
|
|
|
'/org/qubesos/QubesManager')
|
|
|
|
qubes_manager.clear_error_exact(vm.name, message,
|
|
|
|
dbus_interface='org.qubesos.QubesManager')
|
|
|
|
except dbus.DBusException:
|
|
|
|
# ignore the case when no qubes-manager is running
|
|
|
|
pass
|