The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/pylxd/pull/319
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) === This should solve definetively the issue https://github.com/lxc/pylxd/issues/315 And the behaviour of migration will be the same of using ``` lxc move <container_name> <remote_name>: ``` Also added myself to contributors.rst Hope this is usefull
From 7e74b596fb79df725fed8e3794046b6e7a95a029 Mon Sep 17 00:00:00 2001 From: gabrik <gabriele.bald...@gmail.com> Date: Wed, 11 Jul 2018 16:38:32 +0200 Subject: [PATCH] Changed the implementation of Containers.migration to match the 'lxc move <container_name> <remote_name>:' behaviour Signed-off-by: gabrik <gabriele.bald...@gmail.com> --- CONTRIBUTORS.rst | 1 + pylxd/models/container.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 86035b2..f09f5b0 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -34,5 +34,6 @@ These are the contributors to pylxd according to the Github repository. chrismacnaughton Chris MacNaughton ppkt Karol Werner mrtc0 Kohei Morita + gabrik Gabriele Baldoni =============== ================================== diff --git a/pylxd/models/container.py b/pylxd/models/container.py index f55e53e..c5a21c1 100644 --- a/pylxd/models/container.py +++ b/pylxd/models/container.py @@ -421,9 +421,22 @@ def migrate(self, new_client, wait=False): """ if self.api.scheme in ('http+unix',): raise ValueError('Cannot migrate from a local client connection') - - return new_client.containers.create( - self.generate_migration_data(), wait=wait) + + if self.status.upper() == 'RUNNING': + try: + res = new_client.containers.create( + self.generate_migration_data(), wait=wait) + except LXDAPIException as e: + if '{}'.format(e) == "The container is already running": + self.delete() + return new_client.containers.get(self.name) + else: + raise e + else: + res = new_client.containers.create( + self.generate_migration_data(), wait=wait) + self.delete() + return res def generate_migration_data(self): """Generate the migration data.
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel