The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/pylxd/pull/169
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) === Each method has an XXX, i'm not sure we want the wait=False argument as theres no way to find out which image got copied else. Signed-off-by: Rene Jochum <r...@jochums.at>
From 65ba4351b7fabdfff8f9c7449d3bf3a14bcf9487 Mon Sep 17 00:00:00 2001 From: Rene Jochum <r...@jochums.at> Date: Fri, 29 Jul 2016 17:33:15 +0200 Subject: [PATCH] Add image.create_from_simplestreams and image.create_from_url. Signed-off-by: Rene Jochum <r...@jochums.at> --- doc/source/images.rst | 8 +++++++ pylxd/image.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/doc/source/images.rst b/doc/source/images.rst index 37d89ce..88f915e 100644 --- a/doc/source/images.rst +++ b/doc/source/images.rst @@ -14,9 +14,17 @@ methods: - `all()` - Retrieve all images. - `get()` - Get a specific image, by its fingerprint. + +And create through the following methods, +theres also a copy method on an image: + - `create(data, public=False, wait=False)` - Create a new image. The first argument is the binary data of the image itself. If the image is public, set `public` to `True`. + - `create_from_simplestreams(server, alias, public=False, auto_update=False, wait=False)` - + Create an image from simplestreams. + - `create_from_url(url, public=False, auto_update=False, wait=False)` - + Create an image from a url. Image attributes ---------------- diff --git a/pylxd/image.py b/pylxd/image.py index 9e27898..2809783 100644 --- a/pylxd/image.py +++ b/pylxd/image.py @@ -32,6 +32,10 @@ def _image_create_from_config(client, config, wait=False): if wait: Operation.wait_for_operation(client, response.json()['operation']) + return Operation.get(client, response.json()['operation']) + + return None + class Image(model.Model): """A LXD Image.""" @@ -96,6 +100,60 @@ def create(cls, client, image_data, public=False, wait=False): Operation.wait_for_operation(client, response.json()['operation']) return cls(client, fingerprint=fingerprint) + @classmethod + def create_from_simplestreams(cls, client, server, alias, + public=False, auto_update=False, wait=False): + """ Copy an image from simplestreams. + """ + config = { + 'public': public, + 'auto_update': auto_update, + + 'source': { + 'type': 'image', + 'mode': 'pull', + 'server': server, + 'protocol': 'simplestreams', + 'fingerprint': alias + } + } + + op = _image_create_from_config(client, config, wait=wait) + + # XXX: pcdummy (29 Jul 2016) - We might want to remove the wait + # argument, theres no way to retrieve the image without wait as people + # don't know the fingerprint. + if wait: + return client.images.get(op['metadata']['fingerprint']) + + return None + + @classmethod + def create_from_url(cls, client, url, + public=False, auto_update=False, wait=False): + """ Copy an image from an url. + """ + config = { + 'public': public, + 'auto_update': auto_update, + + 'source': { + 'type': 'url', + 'mode': 'pull', + 'url': url + } + } + + op = _image_create_from_config(client, config, wait=wait) + + # XXX: pcdummy (29 Jul 2016) - We might want to remove the wait + # argument, theres no way to retrieve the image without wait as people + # don't know the fingerprint. + if wait: + return client.images.get(op['metadata']['fingerprint']) + + return None + def export(self): """Export the image.""" response = self.api.export.get()
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel