From 10635cbe9622e915b138f593225f9ea7cfbfbe49 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Tue, 23 Apr 2024 22:48:55 +0800 Subject: [PATCH 1/2] add vm img support Signed-off-by: charlie4284 --- pylxd/models/image.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pylxd/models/image.py b/pylxd/models/image.py index 2fc486ee..6673b5eb 100644 --- a/pylxd/models/image.py +++ b/pylxd/models/image.py @@ -98,7 +98,7 @@ def all(cls, client): return images @classmethod - def create(cls, client, image_data, metadata=None, public=False, wait=True): + def create(cls, client, image_data, metadata=None, public=False, wait=True, vm=False): """Create an image. If metadata is provided, a multipart form data request is formed to @@ -123,10 +123,17 @@ def create(cls, client, image_data, metadata=None, public=False, wait=True): # Image uploaded as chunked/stream (metadata, rootfs) # multipart message. # Order of parts is important metadata should be passed first - files = collections.OrderedDict( - metadata=("metadata", metadata, "application/octet-stream"), - rootfs=("rootfs", image_data, "application/octet-stream"), - ) + files: collections.OrderedDict + if not vm: + files = collections.OrderedDict( + metadata=("metadata", metadata, "application/octet-stream"), + rootfs=("rootfs", image_data, "application/octet-stream"), + ) + else: + files = collections.OrderedDict({ + "metadata":("metadata", metadata, "application/octet-stream"), + "rootfs.img":("rootfs.img", image_data, "application/octet-stream"), + }) data = MultipartEncoder(files) headers.update({"Content-Type": data.content_type}) else: From 3847fcc68c8f6023ef303e76f7e333237bbdebfd Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Tue, 23 Apr 2024 23:21:33 +0800 Subject: [PATCH 2/2] fix lint Signed-off-by: charlie4284 --- pylxd/models/image.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pylxd/models/image.py b/pylxd/models/image.py index 6673b5eb..53d33662 100644 --- a/pylxd/models/image.py +++ b/pylxd/models/image.py @@ -98,7 +98,9 @@ def all(cls, client): return images @classmethod - def create(cls, client, image_data, metadata=None, public=False, wait=True, vm=False): + def create( + cls, client, image_data, metadata=None, public=False, wait=True, vm=False + ): """Create an image. If metadata is provided, a multipart form data request is formed to @@ -130,10 +132,16 @@ def create(cls, client, image_data, metadata=None, public=False, wait=True, vm=F rootfs=("rootfs", image_data, "application/octet-stream"), ) else: - files = collections.OrderedDict({ - "metadata":("metadata", metadata, "application/octet-stream"), - "rootfs.img":("rootfs.img", image_data, "application/octet-stream"), - }) + files = collections.OrderedDict( + { + "metadata": ("metadata", metadata, "application/octet-stream"), + "rootfs.img": ( + "rootfs.img", + image_data, + "application/octet-stream", + ), + } + ) data = MultipartEncoder(files) headers.update({"Content-Type": data.content_type}) else: