From 27dfe23808b857a2e546f6c39ae2af40a1620d61 Mon Sep 17 00:00:00 2001 From: Felix Engelmann Date: Thu, 17 Oct 2019 13:49:40 +0200 Subject: [PATCH] added image creation from public lxd server Signed-off-by: Felix Engelmann --- pylxd/models/image.py | 20 ++++++++++++++++++++ pylxd/tests/models/test_image.py | 11 +++++++++++ 2 files changed, 31 insertions(+) diff --git a/pylxd/models/image.py b/pylxd/models/image.py index c335d34b..cab78917 100644 --- a/pylxd/models/image.py +++ b/pylxd/models/image.py @@ -156,6 +156,26 @@ def create_from_simplestreams(cls, client, server, alias, return client.images.get(op.metadata['fingerprint']) + @classmethod + def create_from_image(cls, client, server, fingerprint=None, alias=None, public=False, auto_update=False): + """Copy an image from remote lxd.""" + config = { + 'public': public, + 'auto_update': auto_update, + 'source': { + 'type': 'image', + 'mode': 'pull', + 'server': server, + 'protocol': 'lxd', + 'fingerprint': fingerprint, + 'alias': alias + } + } + + op = _image_create_from_config(client, config, wait=True) + + return client.images.get(op.metadata['fingerprint']) + @classmethod def create_from_url(cls, client, url, public=False, auto_update=False): diff --git a/pylxd/tests/models/test_image.py b/pylxd/tests/models/test_image.py index 60d59e83..d8861047 100644 --- a/pylxd/tests/models/test_image.py +++ b/pylxd/tests/models/test_image.py @@ -368,6 +368,17 @@ def test_create_from_simplestreams(self): image.fingerprint ) + def test_create_from_image(self): + """Try to create an image from image at public lxd.""" + image = self.client.images.create_from_image( + 'https://images.nlogn.org:8443', + alias='debian/8' + ) + self.assertEqual( + 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', + image.fingerprint + ) + def test_create_from_url(self): """Try to create an image from an URL.""" image = self.client.images.create_from_url(