vm-provision: image_cache_storage for the SSH fallback, and keep only the newest build per image #79

Open
opened 2026-11-28 01:58:15 +00:00 by christianmanivong · 0 comments
Owner

Prio: P4. The main case is covered: a node with an active import storage downloads through Proxmox (NetOrk/netork#480, option C). This issue covers the remaining fallback path and the cache growth.

Follow-up to NetOrk/netork#480. Decided by Christian on 2026-11-28.

1. image_cache_storage for the SSH fallback (option B of #480)

The SSH download still writes to the hardcoded _IMAGE_CACHE_DIR = "/var/lib/vz/template/netork-images" (vm_provision_mixin.py:84), which is on the node's root filesystem, in three cases:

  • the node has no active storage with content import (_find_import_storage returns None);
  • the image is packed (FreeBSD's .qcow2.xz), because download-url only unpacks ISOs (_cloud_image_on_node);
  • import_volume_name returns None for another reason, for example a missing or unknown extension.

Decided: a driver arg image_cache_storage that names a Proxmox storage ID, for example software.

  • It is resolved with _get_storage_path() plus a netork-images subdirectory.
  • Before any node command runs, the storage must be active on this node (/nodes/{node}/storage) and dir-backed (dir, nfs, cifs, cephfs). Otherwise the download is refused with a clear message, so an unmounted share can no longer fill root through mkdir -p.
  • Unset, the default stays as it is.
  • Two nodes sharing one storage must not collide on the fixed <path>.tmp: use unique temp names (mktemp in the target directory) and an atomic mv.
  • The setting is per hypervisor only (optional_args, settable in the device's Details tab). There is no picker in the provisioning dialog, and netOrk needs no change.

2. Keep only the newest build per image

Nothing is ever evicted, neither in the import storage nor in the SSH cache. The cache key is a hash of the full URL (url_key), so every daily Ubuntu build leaves another file of roughly 600 MB.

Decided: after a successful download, delete the older builds of the same image in that storage or directory.

  • "Same image" means the same name after the hash. That is netork-<key>-<stem>.<ext> in the import storage (import_volume_name) and <key>-<basename> in the SSH cache (cache_name), plus an unpacked file in the SSH cache.
  • Only netOrk's own files are touched: the netork- prefix in the import storage, and only the netork-images directory for the SSH path.
  • The file just downloaded is never deleted.
  • In the import storage, delete through the storage API (DELETE …/content/{volid}), not with rm.

Not part of this

  • Snippet storage: it stays the first storage with snippets content, because snippets are a few KB.
  • Per-VM storage picker: none.
  • Minimum PVE version: none needs to be set, because nodes without import support take the SSH path.

Test-first

  • The constructor reads image_cache_storage.
  • An inactive or non-dir storage is refused before any node command runs.
  • The download writes under the resolved path with a unique temp name.
  • Eviction removes only older netork- builds of the same name and keeps the new file, on both paths.
  • Unset, the behaviour is unchanged.
Prio: P4. The main case is covered: a node with an active `import` storage downloads through Proxmox (NetOrk/netork#480, option C). This issue covers the remaining fallback path and the cache growth. Follow-up to NetOrk/netork#480. Decided by Christian on 2026-11-28. ## 1. `image_cache_storage` for the SSH fallback (option B of #480) The SSH download still writes to the hardcoded `_IMAGE_CACHE_DIR = "/var/lib/vz/template/netork-images"` (`vm_provision_mixin.py`:84), which is on the node's root filesystem, in three cases: - the node has no active storage with content `import` (`_find_import_storage` returns None); - the image is packed (FreeBSD's `.qcow2.xz`), because `download-url` only unpacks ISOs (`_cloud_image_on_node`); - `import_volume_name` returns None for another reason, for example a missing or unknown extension. **Decided:** a driver arg `image_cache_storage` that names a Proxmox storage ID, for example `software`. - It is resolved with `_get_storage_path()` plus a `netork-images` subdirectory. - Before any node command runs, the storage must be `active` on this node (`/nodes/{node}/storage`) and dir-backed (dir, nfs, cifs, cephfs). Otherwise the download is refused with a clear message, so an unmounted share can no longer fill root through `mkdir -p`. - Unset, the default stays as it is. - Two nodes sharing one storage must not collide on the fixed `<path>.tmp`: use unique temp names (`mktemp` in the target directory) and an atomic `mv`. - The setting is per hypervisor only (`optional_args`, settable in the device's Details tab). There is no picker in the provisioning dialog, and netOrk needs no change. ## 2. Keep only the newest build per image Nothing is ever evicted, neither in the import storage nor in the SSH cache. The cache key is a hash of the full URL (`url_key`), so every daily Ubuntu build leaves another file of roughly 600 MB. **Decided:** after a successful download, delete the older builds of the same image in that storage or directory. - "Same image" means the same name after the hash. That is `netork-<key>-<stem>.<ext>` in the import storage (`import_volume_name`) and `<key>-<basename>` in the SSH cache (`cache_name`), plus an unpacked file in the SSH cache. - Only netOrk's own files are touched: the `netork-` prefix in the import storage, and only the `netork-images` directory for the SSH path. - The file just downloaded is never deleted. - In the import storage, delete through the storage API (`DELETE …/content/{volid}`), not with `rm`. ## Not part of this - **Snippet storage:** it stays the first storage with `snippets` content, because snippets are a few KB. - **Per-VM storage picker:** none. - **Minimum PVE version:** none needs to be set, because nodes without `import` support take the SSH path. ## Test-first - The constructor reads `image_cache_storage`. - An inactive or non-dir storage is refused before any node command runs. - The download writes under the resolved path with a unique temp name. - Eviction removes only older `netork-` builds of the same name and keeps the new file, on both paths. - Unset, the behaviour is unchanged.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-proxmox#79