Гостевой агент был добавлен: машины из готовых образов ставят qemu-guest-agent, панель видит их IP и в домашней сети
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019LEUXMcdZo7b87mjkUsPgg
Этот коммит содержится в:
@@ -27,6 +27,7 @@ def test_user_data_has_user_password_and_keys():
|
|||||||
text = cloudinit.build_user_data("web", "viktor", "$6$abc", ["ssh-ed25519 AAAAC3 me@laptop"])
|
text = cloudinit.build_user_data("web", "viktor", "$6$abc", ["ssh-ed25519 AAAAC3 me@laptop"])
|
||||||
assert "hostname: web" in text and "- name: viktor" in text and "passwd: '$6$abc'" in text
|
assert "hostname: web" in text and "- name: viktor" in text and "passwd: '$6$abc'" in text
|
||||||
assert "- ssh-ed25519 AAAAC3 me@laptop" in text and "ssh_pwauth: true" in text and "growpart" in text
|
assert "- ssh-ed25519 AAAAC3 me@laptop" in text and "ssh_pwauth: true" in text and "growpart" in text
|
||||||
|
assert "packages: [qemu-guest-agent]" in text and "package_update: true" in text
|
||||||
assert "ssh_pwauth: false" in cloudinit.build_user_data("web", "viktor", "", ["ssh-ed25519 AAAAC3 me"])
|
assert "ssh_pwauth: false" in cloudinit.build_user_data("web", "viktor", "", ["ssh-ed25519 AAAAC3 me"])
|
||||||
|
|
||||||
|
|
||||||
@@ -120,6 +121,7 @@ def test_windows11_gets_uefi_tpm_sata_and_e1000e(logged_in, data_dirs, monkeypat
|
|||||||
assert cmd[cmd.index("--boot") + 1] == "uefi,cdrom,hd"
|
assert cmd[cmd.index("--boot") + 1] == "uefi,cdrom,hd"
|
||||||
assert "--tpm" in cmd and "backend.version=2.0" in cmd[cmd.index("--tpm") + 1]
|
assert "--tpm" in cmd and "backend.version=2.0" in cmd[cmd.index("--tpm") + 1]
|
||||||
assert "bus=sata" in cmd[cmd.index("--disk") + 1] and "model=e1000e" in cmd[cmd.index("--network") + 1]
|
assert "bus=sata" in cmd[cmd.index("--disk") + 1] and "model=e1000e" in cmd[cmd.index("--network") + 1]
|
||||||
|
assert "--channel" not in cmd # Windows has no guest agent without extra drivers
|
||||||
|
|
||||||
|
|
||||||
def test_linux_installer_detects_os_and_uses_virtio(logged_in, data_dirs, monkeypatch):
|
def test_linux_installer_detects_os_and_uses_virtio(logged_in, data_dirs, monkeypatch):
|
||||||
@@ -129,6 +131,7 @@ def test_linux_installer_detects_os_and_uses_virtio(logged_in, data_dirs, monkey
|
|||||||
cmd = captured["cmd"]
|
cmd = captured["cmd"]
|
||||||
assert cmd[cmd.index("--osinfo") + 1] == "detect=on,require=off" and cmd[cmd.index("--boot") + 1] == "cdrom,hd"
|
assert cmd[cmd.index("--osinfo") + 1] == "detect=on,require=off" and cmd[cmd.index("--boot") + 1] == "cdrom,hd"
|
||||||
assert "bus=virtio" in cmd[cmd.index("--disk") + 1] and "model=virtio" in cmd[cmd.index("--network") + 1] and "--tpm" not in cmd
|
assert "bus=virtio" in cmd[cmd.index("--disk") + 1] and "model=virtio" in cmd[cmd.index("--network") + 1] and "--tpm" not in cmd
|
||||||
|
assert cmd[cmd.index("--channel") + 1] == "unix,target.type=virtio,target.name=org.qemu.guest_agent.0"
|
||||||
assert create(logged_in, monkeypatch, iso_form(iso, os_type="bsd"))[0].status_code == 400
|
assert create(logged_in, monkeypatch, iso_form(iso, os_type="bsd"))[0].status_code == 400
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -406,8 +406,10 @@ def parse_virsh_list() -> list[dict[str, str]]:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def ip_from_domifaddr(name: str) -> str:
|
def ip_from_domifaddr(name: str) -> str:
|
||||||
|
# DHCP lease first (NAT network), then the guest agent (machines in the home network via br0).
|
||||||
|
for extra in ([], ["--source", "agent"]):
|
||||||
try:
|
try:
|
||||||
result = run_cmd(["virsh", "domifaddr", name], timeout=8)
|
result = run_cmd(["virsh", "domifaddr", name, *extra], timeout=8)
|
||||||
if result.get("ok"):
|
if result.get("ok"):
|
||||||
for ip in re.findall(r"\b(\d{1,3}(?:\.\d{1,3}){3})/\d+", result.get("stdout", "")):
|
for ip in re.findall(r"\b(\d{1,3}(?:\.\d{1,3}){3})/\d+", result.get("stdout", "")):
|
||||||
ip = clean_ip(ip)
|
ip = clean_ip(ip)
|
||||||
@@ -1860,6 +1862,9 @@ def vm_create_submit(request: Request, name: str = Form(...), memory: int = Form
|
|||||||
# Windows 11 refuses to install without a TPM 2.0.
|
# Windows 11 refuses to install without a TPM 2.0.
|
||||||
cmd += ["--tpm", "model=tpm-crb,backend.type=emulator,backend.version=2.0"]
|
cmd += ["--tpm", "model=tpm-crb,backend.type=emulator,backend.version=2.0"]
|
||||||
graphics = ["--graphics", "vnc,listen=127.0.0.1", "--noautoconsole"]
|
graphics = ["--graphics", "vnc,listen=127.0.0.1", "--noautoconsole"]
|
||||||
|
if not windows:
|
||||||
|
# Channel for qemu-guest-agent (installed by cloud-init; on ISO installs — by the user or the distro).
|
||||||
|
graphics = ["--channel", "unix,target.type=virtio,target.name=org.qemu.guest_agent.0", *graphics]
|
||||||
|
|
||||||
seed_file = ""
|
seed_file = ""
|
||||||
login_hint = ""
|
login_hint = ""
|
||||||
|
|||||||
@@ -77,7 +77,11 @@ def build_user_data(hostname: str, user: str, password_hash: str, ssh_keys: list
|
|||||||
" mode: auto",
|
" mode: auto",
|
||||||
" devices: ['/']",
|
" devices: ['/']",
|
||||||
"resize_rootfs: true",
|
"resize_rootfs: true",
|
||||||
"package_update: false",
|
# The guest agent lets the panel see the machine's address in any network and shut it down cleanly.
|
||||||
|
"package_update: true",
|
||||||
|
"packages: [qemu-guest-agent]",
|
||||||
|
"runcmd:",
|
||||||
|
" - [sh, -c, 'systemctl enable --now qemu-guest-agent 2>/dev/null || { rc-update add qemu-guest-agent default && rc-service qemu-guest-agent start; } || true']",
|
||||||
]
|
]
|
||||||
return "\n".join(lines) + "\n"
|
return "\n".join(lines) + "\n"
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user