python-compute/compute/exceptions.py

112 lines
3.3 KiB
Python
Raw Normal View History

2023-11-23 02:34:02 +03:00
# This file is part of Compute
#
# Compute is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
2023-12-03 23:25:34 +03:00
# Compute is distributed in the hope that it will be useful,
2023-11-23 02:34:02 +03:00
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2023-12-03 23:25:34 +03:00
# along with Compute. If not, see <http://www.gnu.org/licenses/>.
2023-11-23 02:34:02 +03:00
2023-11-09 01:17:50 +03:00
"""Exceptions."""
2023-11-06 12:52:19 +03:00
2023-11-23 02:34:02 +03:00
class ComputeError(Exception):
"""Basic exception class."""
2023-11-06 12:52:19 +03:00
2023-11-23 02:34:02 +03:00
class ConfigLoaderError(ComputeError):
2023-11-06 12:52:19 +03:00
"""Something went wrong when loading configuration."""
2023-11-23 02:34:02 +03:00
class SessionError(ComputeError):
2023-11-06 12:52:19 +03:00
"""Something went wrong while connecting to libvirtd."""
2023-11-23 02:34:02 +03:00
class GuestAgentError(ComputeError):
2023-11-06 12:52:19 +03:00
"""Something went wring when QEMU Guest Agent call."""
class GuestAgentUnavailableError(GuestAgentError):
"""Guest agent is not connected or is unavailable."""
2023-12-13 01:42:50 +03:00
class GuestAgentTimeoutExpired(GuestAgentError): # noqa: N818
"""QEMU timeout expired."""
2023-11-06 12:52:19 +03:00
2023-12-01 01:39:26 +03:00
def __init__(self, seconds: int):
2023-12-13 01:42:50 +03:00
"""Initialise GuestAgentTimeoutExpired."""
super().__init__(f'QEMU timeout ({seconds} sec) expired')
2023-11-06 12:52:19 +03:00
class GuestAgentCommandNotSupportedError(GuestAgentError):
"""Guest agent command is not supported or blacklisted on guest."""
2023-11-23 02:34:02 +03:00
class StoragePoolError(ComputeError):
2023-11-06 12:52:19 +03:00
"""Something went wrong when operating with storage pool."""
2023-11-11 02:28:46 +03:00
class StoragePoolNotFoundError(StoragePoolError):
"""Storage pool not found."""
def __init__(self, msg: str):
"""Initialise StoragePoolNotFoundError."""
super().__init__(f"storage pool named '{msg}' not found")
class VolumeNotFoundError(StoragePoolError):
"""Storage volume not found."""
def __init__(self, msg: str):
"""Initialise VolumeNotFoundError."""
super().__init__(f"storage volume '{msg}' not found")
2023-11-23 02:34:02 +03:00
class InstanceError(ComputeError):
2023-11-06 12:52:19 +03:00
"""Something went wrong while interacting with the domain."""
class InstanceNotFoundError(InstanceError):
"""Virtual machine or container not found on compute node."""
def __init__(self, msg: str):
"""Initialise InstanceNotFoundError."""
super().__init__(f"compute instance '{msg}' not found")
2023-12-01 01:39:26 +03:00
2023-12-03 23:25:34 +03:00
class InvalidDeviceConfigError(ComputeError):
"""
Invalid device XML description.
:class:`DeviceCoonfig` instance cannot be created because
device config in libvirt XML config is not valid.
"""
def __init__(self, msg: str, xml: str):
"""Initialise InvalidDeviceConfigError."""
self.msg = f'Invalid device XML config: {msg}'
self.loc = f' {xml}'
2024-01-13 00:45:30 +03:00
super().__init__(f'{self.msg}:\n{self.loc}')
2023-12-03 23:25:34 +03:00
2023-12-01 01:39:26 +03:00
class InvalidDataUnitError(ValueError, ComputeError):
"""Data unit is not valid."""
def __init__(self, msg: str, units: list):
"""Initialise InvalidDataUnitError."""
super().__init__(f'{msg}, valid units are: {", ".join(units)}')
2023-12-03 23:25:34 +03:00
class DictMergeConflictError(ComputeError):
"""Conflict when merging dicts."""
def __init__(self, key: str):
"""Initialise DictMergeConflictError."""
super().__init__(f'Conflicting key: {key}')