various updates
This commit is contained in:
parent
42ad91fa83
commit
5dd15cf01d
@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import tomllib
|
import tomllib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from collections import UserDict
|
from collections import UserDict
|
||||||
@ -24,7 +23,7 @@ class ConfigLoader(UserDict):
|
|||||||
with open(self.file, 'rb') as config:
|
with open(self.file, 'rb') as config:
|
||||||
return tomllib.load(config)
|
return tomllib.load(config)
|
||||||
# todo: config schema validation
|
# 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:
|
except tomllib.TOMLDecodeError as tomlerr:
|
||||||
raise ConfigLoadError(f'Bad TOML syntax in config file: {self.file}: {tomlerr}') from 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
|
||||||
|
@ -20,8 +20,9 @@ import logging
|
|||||||
import libvirt
|
import libvirt
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
|
||||||
sys.path.append('/home/ge/Code/node-agent')
|
from ..main import LibvirtSession
|
||||||
from node_agent import LibvirtSession, VirtualMachine, VMError, VMNotFound
|
from ..vm import VirtualMachine
|
||||||
|
from ..exceptions import VMError, VMNotFound
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -16,8 +16,9 @@ import logging
|
|||||||
|
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
|
||||||
sys.path.append('/home/ge/Code/node-agent')
|
from ..main import LibvirtSession
|
||||||
from node_agent import LibvirtSession, VMNotFound, QemuAgent, QemuAgentError
|
from ..vm import QemuAgent
|
||||||
|
from ..exceptions import QemuAgentError, VMNotFound
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -4,7 +4,7 @@ from ..main import LibvirtSession
|
|||||||
from ..exceptions import VMNotFound
|
from ..exceptions import VMNotFound
|
||||||
|
|
||||||
|
|
||||||
class VMBase:
|
class VirtualMachineBase:
|
||||||
def __init__(self, session: LibvirtSession, name: str):
|
def __init__(self, session: LibvirtSession, name: str):
|
||||||
self.domname = name
|
self.domname = name
|
||||||
self.session = session.session # virConnect object
|
self.session = session.session # virConnect object
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
from base64 import standard_b64encode, b64decode, b64encode
|
from base64 import standard_b64encode, b64decode
|
||||||
|
|
||||||
import libvirt
|
import libvirt
|
||||||
import libvirt_qemu
|
import libvirt_qemu
|
||||||
|
|
||||||
from ..main import LibvirtSession
|
from ..main import LibvirtSession
|
||||||
from ..exceptions import QemuAgentError
|
from ..exceptions import QemuAgentError
|
||||||
from .base import VMBase
|
from .base import VirtualMachineBase
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -18,7 +18,7 @@ QEMU_TIMEOUT = 60 # seconds
|
|||||||
POLL_INTERVAL = 0.3 # also seconds
|
POLL_INTERVAL = 0.3 # also seconds
|
||||||
|
|
||||||
|
|
||||||
class QemuAgent(VMBase):
|
class QemuAgent(VirtualMachineBase):
|
||||||
"""
|
"""
|
||||||
Interacting with QEMU guest agent. Methods:
|
Interacting with QEMU guest agent. Methods:
|
||||||
|
|
||||||
|
@ -3,13 +3,13 @@ import logging
|
|||||||
import libvirt
|
import libvirt
|
||||||
|
|
||||||
from ..exceptions import VMError
|
from ..exceptions import VMError
|
||||||
from .base import VMBase
|
from .base import VirtualMachineBase
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class VirtualMachine(VMBase):
|
class VirtualMachine(VirtualMachineBase):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -72,7 +72,7 @@ class VirtualMachine(VMBase):
|
|||||||
try:
|
try:
|
||||||
ret = self.domain.create()
|
ret = self.domain.create()
|
||||||
except libvirt.libvirtError as err:
|
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:
|
def shutdown(self, force=False, sigkill=False) -> None:
|
||||||
"""
|
"""
|
||||||
@ -108,7 +108,7 @@ class VirtualMachine(VMBase):
|
|||||||
guest OS shutdown.
|
guest OS shutdown.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.domian.reset()
|
self.domain.reset()
|
||||||
except libvirt.libvirtError as err:
|
except libvirt.libvirtError as err:
|
||||||
raise VMError(f'Cannot reset vm={self.domname}: {err}') from err
|
raise VMError(f'Cannot reset vm={self.domname}: {err}') from err
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user