[lxc-devel] [pylxd/master] Changed the implementation of Containers.migration to match the 'lxc …
gabrik on Github
lxc-bot at linuxcontainers.org
Wed Jul 11 14:41:10 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 557 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180711/f33ee42d/attachment.bin>
-------------- next part --------------
From 7e74b596fb79df725fed8e3794046b6e7a95a029 Mon Sep 17 00:00:00 2001
From: gabrik <gabriele.baldoni at 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.baldoni at 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.
More information about the lxc-devel
mailing list