feat(oci): support custom Compose workers and migration jobs

This commit is contained in:
Jonatan
2026-10-28 08:41:41 +01:00
parent b383fb9311
commit 3a0a7eaf14
44 changed files with 3267 additions and 110 deletions
+18 -3
View File
@@ -15,6 +15,7 @@ import re
import subprocess
import sys
import tempfile
import time
import uuid
from oci_installation_state import command, image_from_archive, private_directory, sha
@@ -42,8 +43,22 @@ def location(root, vmid):
return path / 'oci-compose.json'
def _acquire_lock(fd, timeout):
"""Wait only for acquisition; a failure inside the operation is never replayed."""
deadline = time.monotonic() + max(0, float(timeout))
while True:
try:
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
return
except BlockingIOError:
remaining = deadline - time.monotonic()
if remaining <= 0:
raise
time.sleep(min(0.2, remaining))
@contextmanager
def locked(root):
def locked(root, timeout=0):
private_directory(root)
path = root / '.lock'
if path.is_symlink():
@@ -53,12 +68,12 @@ def locked(root):
fd = int(inherited)
if os.fstat(fd).st_ino != path.stat().st_ino or os.fstat(fd).st_dev != path.stat().st_dev:
raise ValueError(translate('Wrong inherited registry lock'))
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
_acquire_lock(fd, timeout)
yield
else:
with path.open('a') as lock:
os.chmod(path, 0o600)
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
_acquire_lock(lock, timeout)
yield