Verified Commit e9df941e authored by Jan Miksik's avatar Jan Miksik
Browse files

bugfix: Fixed pylxd remote images

Use simplestream to obtain images now instead old method.
parent 3bad8c21
......@@ -7,7 +7,7 @@ import pylxd
class LXDConnection:
"""This is generic connection handler for LXD handling both connections to local and images server.
"""
IMAGES_SOURCE = "https://images.linuxcontainers.org"
IMAGES_SOURCE = "https://images.linuxcontainers.org" # this is needed for remote access via simplestream
ROOT_PROFILE = "nsfarm-root"
INTERNET_PROFILE = "nsfarm-internet"
......@@ -18,4 +18,3 @@ class LXDConnection:
logging.getLogger('urllib3').setLevel(logging.ERROR)
self.local = pylxd.Client()
self.images = pylxd.Client(self.IMAGES_SOURCE)
......@@ -40,11 +40,12 @@ class Image:
file.readline() # Skip initial shebang
parent, *params = file.readline()[1:].strip().split() # The initial character is '#' we want to ignore
self._parent = None
if parent.startswith("nsfarm:"):
self._parent = Image(lxd_connection, parent[7:])
elif parent.startswith("images:"):
self._parent = self._lxd.images.images.get_by_alias(parent[7:])
image_type, image_alias = parent.split(':', maxsplit=1)
if image_type == "nsfarm":
self._parent = Image(lxd_connection, image_alias)
elif image_type == "images":
self._parent = self._lxd.local.images.create_from_simplestreams(
self._lxd.IMAGES_SOURCE, image_alias, auto_update=True)
else:
raise LXDImageParentError(self.name, parent)
......@@ -162,11 +163,8 @@ class Image:
self._parent.prepare()
image_source["alias"] = self._parent.alias()
else:
# We have to pull it from images
image_source["mode"] = "pull"
image_source["server"] = self._lxd.IMAGES_SOURCE
image_source["alias"] = self._parent.fingerprint
# we have already the image
image_source["fingerprint"] = self._parent.fingerprint
container_name = f"nsfarm-bootstrap-{self.name}-{self.hash()}"
logger.warning("Bootstrapping image '%s': %s", self.alias(), container_name)
......
......@@ -26,16 +26,18 @@ def clean_images(delta: dateutil.relativedelta.relativedelta, dry_run: bool = Fa
removed = []
for img in connection.local.images.all():
if not any(alias["name"].startswith("nsfarm/") for alias in img.aliases):
# We remove our images and images without alias as those are pulled images
if img.aliases and not any(alias["name"].startswith("nsfarm/") for alias in img.aliases):
continue
last_used = dateutil.parser.parse(
# Special time "0001-01-01T00:00:00Z" means never used so use upload time instead
img.last_used_at if not img.last_used_at.startswith("0001-01-01") else img.uploaded_at
).replace(tzinfo=None)
if last_used < since:
removed.append(img.aliases[0]["name"])
name = f"{img.aliases[0]['name']}({img.fingerprint})" if img.aliases else img.fingerprint
removed.append(name)
if not dry_run:
logger.warning("Removing image: %s %s", img.aliases[0]["name"], img.fingerprint)
logger.warning("Removing image: %s", name)
img.delete()
return removed
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment