[lxc-devel] [lxd/master] lxc-to-lxd: Convert to stable pylxd API
stgraber on Github
lxc-bot at linuxcontainers.org
Sat Apr 23 06:06:31 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 460 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160423/a0b30386/attachment.bin>
-------------- next part --------------
From a111eab2c4b3d2d5d1da06fe22656eb2de48b55c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sat, 23 Apr 2016 07:53:42 +0200
Subject: [PATCH] lxc-to-lxd: Convert to stable pylxd API
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #1901
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
scripts/lxc-to-lxd | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/scripts/lxc-to-lxd b/scripts/lxc-to-lxd
index 88df348..8574e45 100755
--- a/scripts/lxc-to-lxd
+++ b/scripts/lxc-to-lxd
@@ -5,8 +5,7 @@ import json
import lxc
import os
import subprocess
-import time
-from pylxd import api as api
+from pylxd.client import Client
# Fetch a config key as a list
@@ -76,7 +75,7 @@ def convert_container(container_name, args):
# Connect to LXD
if args.lxdpath:
os.environ['LXD_DIR'] = args.lxdpath
- lxd = api.API()
+ lxd = Client()
print("==> Processing container: %s" % container_name)
@@ -107,9 +106,12 @@ def convert_container(container_name, args):
# Make sure we don't have a conflict
print("Checking for existing containers")
- if lxd.container_defined(container_name):
+ try:
+ lxd.containers.get(container_name)
print("Container already exists, skipping...")
return False
+ except NameError:
+ pass
# Validate lxc.utsname
print("Validating container name")
@@ -314,14 +316,14 @@ def convert_container(container_name, args):
# Set the container architecture if set in LXC
print("Converting container architecture configuration")
- arches = {'i686': 1,
- 'x86_64': 2,
- 'armhf': 3,
- 'arm64': 4,
- 'powerpc': 5,
- 'powerpc64': 6,
- 'ppc64el': 7,
- 's390x': 8}
+ arches = {'i686': "i686",
+ 'x86_64': "x86_64",
+ 'armhf': "armv7l",
+ 'arm64': "aarch64",
+ 'powerpc': "ppc",
+ 'powerpc64': "ppc64",
+ 'ppc64el': "ppc64le",
+ 's390x': "s390x"}
arch = None
try:
@@ -344,11 +346,11 @@ def convert_container(container_name, args):
try:
print("Creating the container")
- lxd.container_init(new)
+ lxd.containers.create(new, wait=True)
except Exception as e:
+ raise
print("Failed to create the container: %s" % e)
return False
- time.sleep(1)
# Transfer the filesystem
lxd_rootfs = os.path.join("/var/lib/lxd/", "containers",
More information about the lxc-devel
mailing list