[lxc-devel] [pylxd/master] WIP: Migration support

rockstar on Github lxc-bot at linuxcontainers.org
Thu Jun 9 03:57:05 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 377 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160609/972e0c8f/attachment.bin>
-------------- next part --------------
From 2cd72cf122515e38317f52a549c35f0906b4d3a0 Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Wed, 8 Jun 2016 21:44:30 -0600
Subject: [PATCH] Add stub for migration

---
 pylxd/container.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/pylxd/container.py b/pylxd/container.py
index 164601b..81450ad 100644
--- a/pylxd/container.py
+++ b/pylxd/container.py
@@ -293,6 +293,34 @@ def execute(self, commands, environment={}):
 
         return stdout.data, stderr.data
 
+    def migrate(self, new_client, wait=False):
+        """Migrate a container.
+
+        Destination host information is contained in the client
+        connection passed in.
+        """
+        self.fetch()  # Make sure the object isn't stale
+        response = self._client.api.containers[self.name].post(
+            json={'migration': True})
+        operation = self._client.operations.get(response.json()['operation'])
+        secrets = response.json()['metadata']['metadata']
+
+        config = {
+            'name': self.name,
+            'architecture': self.architecture,
+            'config': self.config,
+            'devices': self.devices,
+            'epehemeral': self.ephemeral,
+            'default': self.profiles,
+            'source': {
+                'type': 'migration',
+                'operation': self._client.api.operations[operation.id]._api_endpoint,
+                'mode': 'pull',
+                'secrets': secrets,
+            }
+        }
+        new_client.containers.create(config, wait=wait)
+
 
 class _CommandWebsocketClient(WebSocketBaseClient):  # pragma: no cover
     def __init__(self, manager, *args, **kwargs):
@@ -316,6 +344,7 @@ def data(self):
 
 class _StdinWebsocket(WebSocketBaseClient):  # pragma: no cover
     """A websocket client for handling stdin."""
+
     def __init__(self, manager, *args, **kwargs):
         self.manager = manager
         super(_StdinWebsocket, self).__init__(*args, **kwargs)


More information about the lxc-devel mailing list