python-compute/compute/exceptions.py

89 lines
2.6 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.
#
# Ansible is distributed in the hope that it will be useful,
# 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
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
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-01 01:39:26 +03:00
class GuestAgentTimeoutError(GuestAgentError):
2023-11-06 12:52:19 +03:00
"""QEMU timeout exceeded."""
2023-12-01 01:39:26 +03:00
def __init__(self, seconds: int):
2023-11-06 12:52:19 +03:00
"""Initialise GuestAgentTimeoutExceededError."""
2023-12-01 01:39:26 +03:00
super().__init__(f'QEMU timeout ({seconds} sec) exceeded')
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
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)}')