This commit is contained in:
ge
2023-07-29 15:35:36 +03:00
parent 3ac1cf5404
commit a0344b703f
10 changed files with 19 additions and 24 deletions

View File

@ -1,2 +1,3 @@
from .main import VirtualMachine
from .ga import QemuAgent
from .ga import QemuAgent, QemuAgentError
from .exceptions import *

View File

@ -1,7 +1,7 @@
import libvirt
from ..main import LibvirtSession
from ..exceptions import VMNotFound
from .exceptions import VMNotFound
class VirtualMachineBase:

View File

@ -0,0 +1,13 @@
class QemuAgentError(Exception):
"""Mostly QEMU Guest Agent is not responding."""
class VMError(Exception):
"""Something went wrong while interacting with the domain."""
class VMNotFound(Exception):
def __init__(self, domain, message='VM not found: {domain}'):
self.domain = domain
self.message = message.format(domain=domain)
super().__init__(self.message)

View File

@ -7,8 +7,8 @@ import libvirt
import libvirt_qemu
from ..main import LibvirtSession
from ..exceptions import QemuAgentError
from .base import VirtualMachineBase
from .exceptions import QemuAgentError
logger = logging.getLogger(__name__)

View File

@ -2,8 +2,8 @@ import logging
import libvirt
from ..exceptions import VMError
from .base import VirtualMachineBase
from .exceptions import VMError
logger = logging.getLogger(__name__)
@ -70,7 +70,7 @@ class VirtualMachine(VirtualMachineBase):
logger.debug('VM vm=%s is already started, nothing to do', self.domname)
return
try:
ret = self.domain.create()
self.domain.create()
except libvirt.libvirtError as err:
raise VMError(f'Cannot start vm={self.domname}: {err}') from err