The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/pylxd/pull/378

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
There is an option to pull public images from existing lxd instances, similar to simplestream.

Signed-off-by: Felix Engelmann <fe-git...@nlogn.org>
From 27dfe23808b857a2e546f6c39ae2af40a1620d61 Mon Sep 17 00:00:00 2001
From: Felix Engelmann <fe-git...@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-git...@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(
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to