refactor
This commit is contained in:
parent
3ac1cf5404
commit
a0344b703f
@ -1,4 +1,3 @@
|
||||
from .main import LibvirtSession
|
||||
from .vm import VirtualMachine, QemuAgent
|
||||
from .config import ConfigLoader
|
||||
from .exceptions import *
|
||||
from .vm import *
|
||||
|
@ -3,13 +3,15 @@ import tomllib
|
||||
from pathlib import Path
|
||||
from collections import UserDict
|
||||
|
||||
from .exceptions import ConfigLoadError
|
||||
|
||||
|
||||
NODEAGENT_CONFIG_FILE = os.getenv('NODEAGENT_CONFIG_FILE')
|
||||
NODEAGENT_DEFAULT_CONFIG_FILE = '/etc/node-agent/config.toml'
|
||||
|
||||
|
||||
class ConfigLoadError(Exception):
|
||||
"""Bad config file syntax, unreachable file or bad data."""
|
||||
|
||||
|
||||
class ConfigLoader(UserDict):
|
||||
def __init__(self, file: Path | None = None):
|
||||
if file is None:
|
||||
|
@ -4,7 +4,10 @@ from contextlib import AbstractContextManager
|
||||
import libvirt
|
||||
|
||||
from .config import ConfigLoader
|
||||
from .exceptions import LibvirtSessionError
|
||||
|
||||
|
||||
class LibvirtSessionError(Exception):
|
||||
"""Something went wrong while connecting to libvirt."""
|
||||
|
||||
|
||||
class LibvirtSession(AbstractContextManager):
|
||||
|
@ -21,8 +21,7 @@ import libvirt
|
||||
from docopt import docopt
|
||||
|
||||
from ..main import LibvirtSession
|
||||
from ..vm import VirtualMachine
|
||||
from ..exceptions import VMError, VMNotFound
|
||||
from ..vm import VirtualMachine, VMError, VMNotFound
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -17,8 +17,7 @@ import logging
|
||||
from docopt import docopt
|
||||
|
||||
from ..main import LibvirtSession
|
||||
from ..vm import QemuAgent
|
||||
from ..exceptions import QemuAgentError, VMNotFound
|
||||
from ..vm import QemuAgent, QemuAgentError, VMNotFound
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -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:
|
||||
|
@ -1,9 +1,5 @@
|
||||
class ConfigLoadError(Exception):
|
||||
"""Bad config file syntax, unreachable file or bad data."""
|
||||
|
||||
|
||||
class LibvirtSessionError(Exception):
|
||||
"""Something went wrong while connecting to libvirt."""
|
||||
class QemuAgentError(Exception):
|
||||
"""Mostly QEMU Guest Agent is not responding."""
|
||||
|
||||
|
||||
class VMError(Exception):
|
||||
@ -15,7 +11,3 @@ class VMNotFound(Exception):
|
||||
self.domain = domain
|
||||
self.message = message.format(domain=domain)
|
||||
super().__init__(self.message)
|
||||
|
||||
|
||||
class QemuAgentError(Exception):
|
||||
"""Mostly QEMU Guest Agent is not responding."""
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user