This commit is contained in:
ge
2023-09-02 00:52:28 +03:00
parent 62388e8b67
commit 43033b5a0d
13 changed files with 110 additions and 110 deletions

View File

@ -1,4 +1,3 @@
from .exceptions import *
from .guest_agent import GuestAgent
from .installer import CPUMode, CPUTopology, VirtualMachineInstaller
from .virtual_machine import VirtualMachine

View File

@ -1,6 +1,6 @@
import libvirt
from .exceptions import VMError
from ..exceptions import VMError
class VirtualMachineBase:

View File

@ -1,14 +0,0 @@
class GuestAgentError(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 vm={domain}'):
self.domain = domain
self.message = message.format(domain=domain)
super().__init__(self.message)

View File

@ -6,8 +6,8 @@ from time import sleep, time
import libvirt
import libvirt_qemu
from ..exceptions import GuestAgentError
from .base import VirtualMachineBase
from .exceptions import GuestAgentError
logger = logging.getLogger(__name__)
@ -33,6 +33,7 @@ class GuestAgent(VirtualMachineBase):
super().__init__(domain)
self.timeout = timeout or QEMU_TIMEOUT # timeout for guest agent
self.flags = flags or libvirt_qemu.VIR_DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT
self.last_pid = None
def execute(self,
command: dict,
@ -68,9 +69,9 @@ class GuestAgent(VirtualMachineBase):
cmd_out = self._execute(command)
if capture_output:
cmd_pid = json.loads(cmd_out)['return']['pid']
self.last_pid = json.loads(cmd_out)['return']['pid']
return self._get_cmd_result(
cmd_pid,
self.last_pid,
decode_output=decode_output,
wait=wait,
timeout=timeout,
@ -106,6 +107,10 @@ class GuestAgent(VirtualMachineBase):
timeout=timeout,
)
def poll_pid(self, pid: int):
# Нужно цепляться к PID и вывести результат
pass
def _execute(self, command: dict):
logging.debug('Execute command: vm=%s cmd=%s', self.domain_name,
command)

View File

@ -2,9 +2,9 @@ import logging
import libvirt
from ..exceptions import VMError
from ..volume import VolumeInfo
from .base import VirtualMachineBase
from .exceptions import VMError
logger = logging.getLogger(__name__)