diff --git a/node_agent/config.py b/node_agent/config.py index aa7b9f3..e7b78b0 100644 --- a/node_agent/config.py +++ b/node_agent/config.py @@ -1,5 +1,4 @@ import os -import sys import tomllib from pathlib import Path from collections import UserDict @@ -24,7 +23,7 @@ class ConfigLoader(UserDict): with open(self.file, 'rb') as config: return tomllib.load(config) # todo: config schema validation - except (OSError, ValueError) as readerr: - raise ConfigLoadError(f'Cannot read config file: {self.file}: {readerr}') from readerr except tomllib.TOMLDecodeError as tomlerr: raise ConfigLoadError(f'Bad TOML syntax in config file: {self.file}: {tomlerr}') from tomlerr + except (OSError, ValueError) as readerr: + raise ConfigLoadError(f'Cannot read config file: {self.file}: {readerr}') from readerr diff --git a/node_agent/utils/vmctl.py b/node_agent/utils/vmctl.py index c949070..2d20bae 100644 --- a/node_agent/utils/vmctl.py +++ b/node_agent/utils/vmctl.py @@ -20,8 +20,9 @@ import logging import libvirt from docopt import docopt -sys.path.append('/home/ge/Code/node-agent') -from node_agent import LibvirtSession, VirtualMachine, VMError, VMNotFound +from ..main import LibvirtSession +from ..vm import VirtualMachine +from ..exceptions import VMError, VMNotFound logger = logging.getLogger(__name__) diff --git a/node_agent/utils/vmexec.py b/node_agent/utils/vmexec.py index 2a0a339..0c217a4 100644 --- a/node_agent/utils/vmexec.py +++ b/node_agent/utils/vmexec.py @@ -16,8 +16,9 @@ import logging from docopt import docopt -sys.path.append('/home/ge/Code/node-agent') -from node_agent import LibvirtSession, VMNotFound, QemuAgent, QemuAgentError +from ..main import LibvirtSession +from ..vm import QemuAgent +from ..exceptions import QemuAgentError, VMNotFound logger = logging.getLogger(__name__) diff --git a/node_agent/vm/base.py b/node_agent/vm/base.py index 693c403..db26a68 100644 --- a/node_agent/vm/base.py +++ b/node_agent/vm/base.py @@ -4,7 +4,7 @@ from ..main import LibvirtSession from ..exceptions import VMNotFound -class VMBase: +class VirtualMachineBase: def __init__(self, session: LibvirtSession, name: str): self.domname = name self.session = session.session # virConnect object diff --git a/node_agent/vm/ga.py b/node_agent/vm/ga.py index a7ed09e..93865c5 100644 --- a/node_agent/vm/ga.py +++ b/node_agent/vm/ga.py @@ -1,14 +1,14 @@ import json import logging from time import time, sleep -from base64 import standard_b64encode, b64decode, b64encode +from base64 import standard_b64encode, b64decode import libvirt import libvirt_qemu from ..main import LibvirtSession from ..exceptions import QemuAgentError -from .base import VMBase +from .base import VirtualMachineBase logger = logging.getLogger(__name__) @@ -18,7 +18,7 @@ QEMU_TIMEOUT = 60 # seconds POLL_INTERVAL = 0.3 # also seconds -class QemuAgent(VMBase): +class QemuAgent(VirtualMachineBase): """ Interacting with QEMU guest agent. Methods: diff --git a/node_agent/vm/main.py b/node_agent/vm/main.py index 5109915..9e12fe4 100644 --- a/node_agent/vm/main.py +++ b/node_agent/vm/main.py @@ -3,13 +3,13 @@ import logging import libvirt from ..exceptions import VMError -from .base import VMBase +from .base import VirtualMachineBase logger = logging.getLogger(__name__) -class VirtualMachine(VMBase): +class VirtualMachine(VirtualMachineBase): @property def name(self): @@ -72,7 +72,7 @@ class VirtualMachine(VMBase): try: ret = self.domain.create() except libvirt.libvirtError as err: - raise VMError(f'Cannot start vm={self.domname} return_code={ret}: {err}') from err + raise VMError(f'Cannot start vm={self.domname}: {err}') from err def shutdown(self, force=False, sigkill=False) -> None: """ @@ -108,7 +108,7 @@ class VirtualMachine(VMBase): guest OS shutdown. """ try: - self.domian.reset() + self.domain.reset() except libvirt.libvirtError as err: raise VMError(f'Cannot reset vm={self.domname}: {err}') from err