From 47010f458cad990c1088969e2e9da2f2b6dc7da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 2 Jul 2024 11:41:53 +0200 Subject: [PATCH 1/2] machines/machines: drop unused qmp wrapper --- pkgs/clan-cli/clan_cli/machines/machines.py | 31 --------------------- 1 file changed, 31 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/machines.py b/pkgs/clan-cli/clan_cli/machines/machines.py index 6d70a827..2d34c509 100644 --- a/pkgs/clan-cli/clan_cli/machines/machines.py +++ b/pkgs/clan-cli/clan_cli/machines/machines.py @@ -1,14 +1,10 @@ import json import logging -from collections.abc import Generator -from contextlib import contextmanager from pathlib import Path from tempfile import NamedTemporaryFile from typing import Any from clan_cli.clan_uri import ClanURI, MachineData -from clan_cli.dirs import vm_state_dir -from clan_cli.qemu.qmp import QEMUMonitorProtocol from ..cmd import run_no_stdout from ..errors import ClanError @@ -18,28 +14,6 @@ from ..ssh import Host, parse_deployment_address log = logging.getLogger(__name__) -class QMPWrapper: - def __init__(self, state_dir: Path) -> None: - # These sockets here are just symlinks to the real sockets which - # are created by the run.py file. The reason being that we run into - # file path length issues on Linux. If no qemu process is running - # the symlink will be dangling. - self._qmp_socket: Path = state_dir / "qmp.sock" - self._qga_socket: Path = state_dir / "qga.sock" - - @contextmanager - def qmp_ctx(self) -> Generator[QEMUMonitorProtocol, None, None]: - rpath = self._qmp_socket.resolve() - if not rpath.exists(): - raise ClanError(f"qmp socket {rpath} does not exist. Is the VM running?") - qmp = QEMUMonitorProtocol(str(rpath)) - qmp.connect() - try: - yield qmp - finally: - qmp.close() - - class Machine: name: str flake: str | Path @@ -49,7 +23,6 @@ class Machine: build_cache: dict[str, Path] _flake_path: Path | None _deployment_info: None | dict - vm: QMPWrapper def __init__( self, @@ -80,10 +53,6 @@ class Machine: self._deployment_info: None | dict = deployment_info self.nix_options = nix_options - state_dir = vm_state_dir(flake_url=str(self.flake), vm_name=self.data.name) - - self.vm: QMPWrapper = QMPWrapper(state_dir) - def flush_caches(self) -> None: self._deployment_info = None self._flake_path = None From 815bb336bed0f73510a268aa7539cb39bd09ea5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 2 Jul 2024 11:55:58 +0200 Subject: [PATCH 2/2] remove unused MachineParams --- pkgs/clan-cli/clan_cli/clan_uri.py | 26 +------------------------- pkgs/clan-cli/tests/test_clan_uri.py | 3 +-- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/clan_uri.py b/pkgs/clan-cli/clan_cli/clan_uri.py index 9cb387cb..876772cb 100644 --- a/pkgs/clan-cli/clan_cli/clan_uri.py +++ b/pkgs/clan-cli/clan_cli/clan_uri.py @@ -1,10 +1,8 @@ # Import the urllib.parse, enum and dataclasses modules -import dataclasses import urllib.parse import urllib.request from dataclasses import dataclass from pathlib import Path -from typing import Any from .errors import ClanError @@ -36,18 +34,10 @@ class FlakeId: return isinstance(self._value, str) -# Parameters defined here will be DELETED from the nested uri -# so make sure there are no conflicts with other webservices -@dataclass -class MachineParams: - dummy_opt: str = "dummy" - - @dataclass class MachineData: flake_id: FlakeId name: str = "defaultVM" - params: MachineParams = dataclasses.field(default_factory=MachineParams) def get_id(self) -> str: return f"{self.flake_id}#{self.name}" @@ -120,23 +110,9 @@ class ClanURI: def _parse_machine_query(self, machine_frag: str) -> MachineData: comp = urllib.parse.urlparse(machine_frag) - query = urllib.parse.parse_qs(comp.query) machine_name = comp.path - machine_params: dict[str, Any] = {} - for dfield in dataclasses.fields(MachineParams): - if dfield.name in query: - values = query[dfield.name] - if len(values) > 1: - raise ClanError(f"Multiple values for parameter: {dfield.name}") - machine_params[dfield.name] = values[0] - - # Remove the field from the query dictionary - # clan uri and nested uri share one namespace for query parameters - # we need to make sure there are no conflicts - del query[dfield.name] - params = MachineParams(**machine_params) - machine = MachineData(flake_id=self.flake_id, name=machine_name, params=params) + machine = MachineData(flake_id=self.flake_id, name=machine_name) return machine @property diff --git a/pkgs/clan-cli/tests/test_clan_uri.py b/pkgs/clan-cli/tests/test_clan_uri.py index efddafa6..63196fd7 100644 --- a/pkgs/clan-cli/tests/test_clan_uri.py +++ b/pkgs/clan-cli/tests/test_clan_uri.py @@ -51,10 +51,9 @@ def test_remote_with_clanparams() -> None: def test_remote_with_all_params() -> None: - uri = ClanURI("clan://https://example.com?password=12345#myVM#secondVM?dummy_opt=1") + uri = ClanURI("clan://https://example.com?password=12345#myVM#secondVM") assert uri.machine.name == "myVM" assert uri._machines[1].name == "secondVM" - assert uri._machines[1].params.dummy_opt == "1" assert uri.flake_id.url == "https://example.com?password=12345"