[lxc-devel] [pylxd/master] added image creation from public lxd server

felix-engelmann on Github lxc-bot at linuxcontainers.org
Thu Oct 17 11:51:37 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 452 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191017/89d58469/attachment.bin>
-------------- next part --------------
From 27dfe23808b857a2e546f6c39ae2af40a1620d61 Mon Sep 17 00:00:00 2001
From: Felix Engelmann <fe-github at nlogn.org>
Date: Thu, 17 Oct 2019 13:49:40 +0200
Subject: [PATCH] added image creation from public lxd server

Signed-off-by: Felix Engelmann <fe-github at nlogn.org>
---
 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(


More information about the lxc-devel mailing list