[lxc-devel] [pylxd/master] Extract the migration data step of migration.
rockstar on Github
lxc-bot at linuxcontainers.org
Fri Oct 21 16:32:11 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 444 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161021/334ea7de/attachment.bin>
-------------- next part --------------
From aee748bddfec9f1d5d060c133b68dbe6b0d38fc9 Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Fri, 21 Oct 2016 10:14:29 -0600
Subject: [PATCH] Extract the migration data step of migration.
This means that this data can be re-used in cases where the client
is a unix socket. The API consumer can then massage the data
accordingly.
---
pylxd/models/container.py | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/pylxd/models/container.py b/pylxd/models/container.py
index c320fea..6f82ca2 100644
--- a/pylxd/models/container.py
+++ b/pylxd/models/container.py
@@ -242,6 +242,16 @@ 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)
+
+ def generate_migration_data(self):
+ """Generate the migration data.
+
+ This method can be used to handle migrations where the client
+ connection uses the local unix socket. For more information on
+ migration, see `Container.migrate`.
+ """
self.sync() # Make sure the object isn't stale
response = self.api.post(json={'migration': True})
operation = self.client.operations.get(response.json()['operation'])
@@ -249,7 +259,7 @@ def migrate(self, new_client, wait=False):
secrets = response.json()['metadata']['metadata']
cert = self.client.host_info['environment']['certificate']
- config = {
+ return {
'name': self.name,
'architecture': self.architecture,
'config': self.config,
@@ -264,7 +274,6 @@ def migrate(self, new_client, wait=False):
'secrets': secrets,
}
}
- return new_client.containers.create(config, wait=wait)
def publish(self, public=False, wait=False):
"""Publish a container as an image.
More information about the lxc-devel
mailing list