Merge remote-tracking branch 'origin/main' into fix/half-built-vm-28
# Conflicts: # CHANGELOG.md # tests/quality_baseline.json
This commit is contained in:
commit
0f1918f230
28 files changed
+2720
-162
No files matched your search
@@ -210,12 +210,7 @@ class ProxmoxVMProvisionMixin:
|
||||
timeout=30,
|
||||
)
|
||||
if "EXISTS" not in exists:
|
||||
_logger.info(f"Downloading cloud image {image_url} -> {local_path}")
|
||||
self._run_node_command(
|
||||
f"wget -q -O {local_path}.tmp '{image_url}' "
|
||||
f"&& mv {local_path}.tmp {local_path}",
|
||||
timeout=timeout,
|
||||
)
|
||||
self._fetch_image(image_url, local_path, timeout)
|
||||
|
||||
if not image_checksum:
|
||||
return local_path
|
||||
@@ -240,6 +235,20 @@ class ProxmoxVMProvisionMixin:
|
||||
|
||||
raise AssertionError("unreachable") # loop always returns or raises above
|
||||
|
||||
def _fetch_image(self, image_url: str, local_path: str, timeout: int) -> None:
|
||||
"""Download *image_url* to *local_path* on the node, through a ``.tmp``.
|
||||
|
||||
wget runs with ``-nv`` so its reason ("No space left on device")
|
||||
reaches the error, and a failed download leaves no partial ``.tmp``.
|
||||
"""
|
||||
_logger.info(f"Downloading cloud image {image_url} -> {local_path}")
|
||||
tmp = f"{local_path}.tmp"
|
||||
self._run_node_command(
|
||||
f"wget -nv -O {tmp} '{image_url}' && mv {tmp} {local_path} "
|
||||
f"|| {{ s=$?; rm -f {tmp}; exit $s; }}",
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
def _cloud_image_on_node(self, image_url: str, image_checksum: str | None, timeout: int) -> str:
|
||||
"""The node path of the image, downloaded, verified and unpacked.
|
||||
|
||||
@@ -745,9 +754,9 @@ class ProxmoxVMProvisionMixin:
|
||||
cloud_init_args[f"ipconfig{i}"] = "ip=dhcp"
|
||||
|
||||
if ssh_public_keys:
|
||||
# URL-encode SSH keys for Proxmox API
|
||||
sshkeys = ";".join(ssh_public_keys)
|
||||
cloud_init_args["sshkeys"] = quote(sshkeys)
|
||||
# One key per line, URL-encoded without exception: Proxmox's
|
||||
# "urlencoded" format refuses an unescaped "/" or "+".
|
||||
cloud_init_args["sshkeys"] = quote("\n".join(ssh_public_keys), safe="")
|
||||
|
||||
self._node_api().qemu(vmid).config.post(**cloud_init_args)
|
||||
|
||||
@@ -831,16 +840,7 @@ class ProxmoxVMProvisionMixin:
|
||||
snippets = self._cicustom_snippets(vmid_int)
|
||||
|
||||
# Step 2: Delete VM
|
||||
# Proxmox's API parameter is hyphenated (destroy-unreferenced-disks),
|
||||
# not a valid Python identifier — proxmoxer forwards kwargs to the
|
||||
# request verbatim with no underscore-to-hyphen translation, so this
|
||||
# must be built as a dict and unpacked rather than passed as a kwarg.
|
||||
_logger.debug(f"Deleting VM {vmid} configuration and disks")
|
||||
delete_params = {
|
||||
"purge": 1,
|
||||
"destroy-unreferenced-disks": 1 if remove_disk else 0,
|
||||
}
|
||||
self._node_api().qemu(vmid_int).delete(**delete_params)
|
||||
self._delete_vm(vmid_int, remove_disk, timeout)
|
||||
|
||||
# Step 3: Clean up Cloud-Init snippets
|
||||
# (This is best-effort; snippet files may be unreachable if storage is unavailable)
|
||||
@@ -857,6 +857,21 @@ class ProxmoxVMProvisionMixin:
|
||||
_logger.exception(f"Failed to destroy VM {vmid}: {e}")
|
||||
raise
|
||||
|
||||
def _delete_vm(self, vmid: int, remove_disk: bool, timeout: int) -> None:
|
||||
"""Delete the VM and wait for it to be gone: the delete is a task."""
|
||||
_logger.debug(f"Deleting VM {vmid} configuration and disks")
|
||||
# Proxmox's API parameter is hyphenated (destroy-unreferenced-disks),
|
||||
# not a valid Python identifier — proxmoxer forwards kwargs to the
|
||||
# request verbatim with no underscore-to-hyphen translation, so this
|
||||
# must be built as a dict and unpacked rather than passed as a kwarg.
|
||||
delete_params = {
|
||||
"purge": 1,
|
||||
"destroy-unreferenced-disks": 1 if remove_disk else 0,
|
||||
}
|
||||
upid = self._node_api().qemu(vmid).delete(**delete_params)
|
||||
if upid:
|
||||
self._wait_for_task(upid, timeout=timeout)
|
||||
|
||||
def _cicustom_snippets(self, vmid: int) -> list[tuple[str, str]]:
|
||||
"""``(storage, path)`` of every snippet the VM's cicustom names.
|
||||
|
||||
|
||||
Reference in new issue
Block a user