refactor
This commit is contained in:
@ -1,2 +1,3 @@
|
||||
from .main import VirtualMachine
|
||||
from .ga import QemuAgent
|
||||
from .ga import QemuAgent, QemuAgentError
|
||||
from .exceptions import *
|
||||
|
@ -1,7 +1,7 @@
|
||||
import libvirt
|
||||
|
||||
from ..main import LibvirtSession
|
||||
from ..exceptions import VMNotFound
|
||||
from .exceptions import VMNotFound
|
||||
|
||||
|
||||
class VirtualMachineBase:
|
||||
|
13
node_agent/vm/exceptions.py
Normal file
13
node_agent/vm/exceptions.py
Normal 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)
|
@ -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__)
|
||||
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user