2015-10-14 22:02:11 +02:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, https://www.qubes-os.org/
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Joanna Rutkowska <joanna@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-14 22:02:11 +02:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is distributed in the hope that it will be useful,
|
2015-10-14 22:02:11 +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-14 22:02:11 +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-14 22:02:11 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
'''
|
|
|
|
Qubes OS exception hierarchy
|
|
|
|
'''
|
|
|
|
|
|
|
|
class QubesException(Exception):
|
|
|
|
'''Exception that can be shown to the user'''
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotFoundError(QubesException, KeyError):
|
|
|
|
'''Domain cannot be found in the system'''
|
|
|
|
def __init__(self, vmname):
|
|
|
|
super(QubesVMNotFoundError, self).__init__(
|
|
|
|
'No such domain: {!r}'.format(vmname))
|
|
|
|
self.vmname = vmname
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMError(QubesException):
|
|
|
|
'''Some problem with domain state.'''
|
|
|
|
def __init__(self, vm, msg):
|
|
|
|
super(QubesVMError, self).__init__(msg)
|
|
|
|
self.vm = vm
|
|
|
|
|
2017-09-26 14:55:45 +02:00
|
|
|
class QubesVMInUseError(QubesVMError):
|
|
|
|
'''VM is in use, cannot remove.'''
|
|
|
|
def __init__(self, vm, msg=None):
|
|
|
|
super(QubesVMInUseError, self).__init__(vm,
|
|
|
|
msg or 'Domain is in use: {!r}'.format(vm.name))
|
2015-10-14 22:02:11 +02:00
|
|
|
|
|
|
|
class QubesVMNotStartedError(QubesVMError):
|
|
|
|
'''Domain is not started.
|
|
|
|
|
|
|
|
This exception is thrown when machine is halted, but should be started
|
|
|
|
(that is, either running or paused).
|
|
|
|
'''
|
|
|
|
def __init__(self, vm, msg=None):
|
|
|
|
super(QubesVMNotStartedError, self).__init__(vm,
|
|
|
|
msg or 'Domain is powered off: {!r}'.format(vm.name))
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotRunningError(QubesVMNotStartedError):
|
|
|
|
'''Domain is not running.
|
|
|
|
|
|
|
|
This exception is thrown when machine should be running but is either
|
|
|
|
halted or paused.
|
|
|
|
'''
|
|
|
|
def __init__(self, vm, msg=None):
|
|
|
|
super(QubesVMNotRunningError, self).__init__(vm,
|
|
|
|
msg or 'Domain not running (either powered off or paused): {!r}' \
|
|
|
|
.format(vm.name))
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotPausedError(QubesVMNotStartedError):
|
|
|
|
'''Domain is not paused.
|
|
|
|
|
|
|
|
This exception is thrown when machine should be paused, but is not.
|
|
|
|
'''
|
|
|
|
def __init__(self, vm, msg=None):
|
|
|
|
super(QubesVMNotPausedError, self).__init__(vm,
|
|
|
|
msg or 'Domain is not paused: {!r}'.format(vm.name))
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotSuspendedError(QubesVMError):
|
|
|
|
'''Domain is not suspended.
|
|
|
|
|
|
|
|
This exception is thrown when machine should be suspended but is either
|
|
|
|
halted or running.
|
|
|
|
'''
|
|
|
|
def __init__(self, vm, msg=None):
|
|
|
|
super(QubesVMNotSuspendedError, self).__init__(vm,
|
|
|
|
msg or 'Domain is not suspended: {!r}'.format(vm.name))
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotHaltedError(QubesVMError):
|
|
|
|
'''Domain is not halted.
|
|
|
|
|
|
|
|
This exception is thrown when machine should be halted, but is not (either
|
|
|
|
running or paused).
|
|
|
|
'''
|
|
|
|
def __init__(self, vm, msg=None):
|
|
|
|
super(QubesVMNotHaltedError, self).__init__(vm,
|
|
|
|
msg or 'Domain is not powered off: {!r}'.format(vm.name))
|
|
|
|
|
2018-10-21 04:36:13 +02:00
|
|
|
class QubesVMShutdownTimeoutError(QubesVMError):
|
|
|
|
'''Domain shutdown timed out.
|
|
|
|
|
|
|
|
'''
|
|
|
|
def __init__(self, vm, msg=None):
|
|
|
|
super(QubesVMShutdownTimeoutError, self).__init__(vm,
|
|
|
|
msg or 'Domain shutdown timed out: {!r}'.format(vm.name))
|
|
|
|
|
2015-10-14 22:02:11 +02:00
|
|
|
|
|
|
|
class QubesNoTemplateError(QubesVMError):
|
|
|
|
'''Cannot start domain, because there is no template'''
|
|
|
|
def __init__(self, vm, msg=None):
|
2017-06-19 17:24:11 +02:00
|
|
|
super(QubesNoTemplateError, self).__init__(vm,
|
2015-10-14 22:02:11 +02:00
|
|
|
msg or 'Template for the domain {!r} not found'.format(vm.name))
|
|
|
|
|
|
|
|
|
|
|
|
class QubesValueError(QubesException, ValueError):
|
|
|
|
'''Cannot set some value, because it is invalid, out of bounds, etc.'''
|
|
|
|
|
|
|
|
|
|
|
|
class QubesPropertyValueError(QubesValueError):
|
|
|
|
'''Cannot set value of qubes.property, because user-supplied value is wrong.
|
|
|
|
'''
|
|
|
|
def __init__(self, holder, prop, value, msg=None):
|
|
|
|
super(QubesPropertyValueError, self).__init__(
|
|
|
|
msg or 'Invalid value {!r} for property {!r} of {!r}'.format(
|
|
|
|
value, prop.__name__, holder))
|
|
|
|
self.holder = holder
|
|
|
|
self.prop = prop
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
|
2017-05-23 04:32:59 +02:00
|
|
|
class QubesNoSuchPropertyError(QubesException, AttributeError):
|
|
|
|
'''Requested property does not exist
|
|
|
|
'''
|
|
|
|
def __init__(self, holder, prop_name, msg=None):
|
|
|
|
super(QubesNoSuchPropertyError, self).__init__(
|
|
|
|
msg or 'Invalid property {!r} of {!s}'.format(
|
|
|
|
prop_name, holder))
|
|
|
|
self.holder = holder
|
|
|
|
self.prop = prop_name
|
|
|
|
|
|
|
|
|
2015-10-14 22:02:11 +02:00
|
|
|
class QubesNotImplementedError(QubesException, NotImplementedError):
|
|
|
|
'''Thrown at user when some feature is not implemented'''
|
|
|
|
def __init__(self, msg=None):
|
|
|
|
super(QubesNotImplementedError, self).__init__(
|
|
|
|
msg or 'This feature is not available')
|
|
|
|
|
|
|
|
|
|
|
|
class BackupCancelledError(QubesException):
|
|
|
|
'''Thrown at user when backup was manually cancelled'''
|
|
|
|
def __init__(self, msg=None):
|
|
|
|
super(BackupCancelledError, self).__init__(
|
|
|
|
msg or 'Backup cancelled')
|
|
|
|
|
|
|
|
|
2018-10-24 14:13:07 +02:00
|
|
|
class QubesMemoryError(QubesVMError, MemoryError):
|
2015-10-14 22:02:11 +02:00
|
|
|
'''Cannot start domain, because not enough memory is available'''
|
|
|
|
def __init__(self, vm, msg=None):
|
2018-10-30 01:14:58 +01:00
|
|
|
super(QubesMemoryError, self).__init__(vm,
|
2015-10-14 22:02:11 +02:00
|
|
|
msg or 'Not enough memory to start domain {!r}'.format(vm.name))
|
2017-04-15 02:28:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
class QubesFeatureNotFoundError(QubesException, KeyError):
|
|
|
|
'''Feature not set for a given domain'''
|
|
|
|
def __init__(self, domain, feature):
|
|
|
|
super(QubesFeatureNotFoundError, self).__init__(
|
|
|
|
'Feature not set for domain {}: {}'.format(domain, feature))
|
|
|
|
self.feature = feature
|
|
|
|
self.vm = domain
|
2017-06-19 19:57:15 +02:00
|
|
|
|
|
|
|
class QubesTagNotFoundError(QubesException, KeyError):
|
|
|
|
'''Tag not set for a given domain'''
|
|
|
|
|
|
|
|
def __init__(self, domain, tag):
|
|
|
|
super().__init__('Tag not set for domain {}: {}'.format(
|
|
|
|
domain, tag))
|
|
|
|
self.vm = domain
|
|
|
|
self.tag = tag
|