This function aims at converting LXC configuration into a libvirt
domain XML description to help users migrate from LXC to libvirt.
Here is an example of how the lxc configuration works:
virsh -c lxc:/// domxml-from-native lxc-tools /var/lib/lxc/migrate_test/config
It is possible that some parts couldn't be properly mapped into a
domain XML fragment, so users should carefully review the result
before creating the domain.
fstab files in lxc.mount lines will need to be merged into the
configuration file as lxc.mount.entry.
As we can't know the amount of memory of the host, we have to set a
default value for max_balloon that users will probably want to adjust.
---
.gitignore | 1 +
po/POTFILES.in | 1 +
src/Makefile.am | 1 +
src/lxc/lxc_driver.c| 31 +++
src/lxc/lxc_native.c| 86 +++
src/lxc/lxc_native.h| 32 +++
tests/Makefile.am | 7 +-
tests/lxcconf2xmldata/lxcconf2xml-simple.config | 38 +
tests/lxcconf2xmldata/lxcconf2xml-simple.xml| 17
tests/lxcconf2xmltest.c | 107
10 files changed, 320 insertions(+), 1 deletion(-)
create mode 100644 src/lxc/lxc_native.c
create mode 100644 src/lxc/lxc_native.h
create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-simple.config
create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-simple.xml
create mode 100644 tests/lxcconf2xmltest.c
diff --git a/.gitignore b/.gitignore
index 757dfed..65b6763 100644
--- a/.gitignore
+++ b/.gitignore
@@ -157,6 +157,7 @@
/tests/hashtest
/tests/jsontest
/tests/libvirtdconftest
+/tests/lxcconf2xmltest
/tests/metadatatest
/tests/networkxml2argvtest
/tests/nodeinfotest
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0359b2f..fd36bc5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -62,6 +62,7 @@ src/locking/sanlock_helper.c
src/lxc/lxc_cgroup.c
src/lxc/lxc_fuse.c
src/lxc/lxc_hostdev.c
+src/lxc/lxc_native.c
src/lxc/lxc_container.c
src/lxc/lxc_conf.c
src/lxc/lxc_controller.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 3f8d22f..4ac31e2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -619,6 +619,7 @@ LXC_DRIVER_SOURCES =
\
lxc/lxc_monitor.c lxc/lxc_monitor.h \
lxc/lxc_process.c lxc/lxc_process.h \
lxc/lxc_fuse.c lxc/lxc_fuse.h \
+ lxc/lxc_native.c lxc/lxc_native.h \
lxc/lxc_driver.c lxc/lxc_driver.h
LXC_CONTROLLER_SOURCES = \
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 138c706..dc0e8e0 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -44,6 +44,7 @@
#include lxc_container.h
#include lxc_domain.h
#include lxc_driver.h
+#include lxc_native.h
#include lxc_process.h
#include viralloc.h
#include virnetdevbridge.h
@@ -988,6 +989,35 @@ cleanup:
return ret;
}
+static char *lxcConnectDomainXMLFromNative(virConnectPtr conn,
+ const char *nativeFormat,
+ const char *nativeConfig,
+ unsigned int flags)
+{
+char *xml = NULL;
+virDomainDefPtr def = NULL;
+
+virCheckFlags(0, NULL);
+
+if (virConnectDomainXMLFromNativeEnsureACL(conn) 0)
+goto cleanup;
+
+if (STRNEQ(nativeFormat, LXC_CONFIG_FORMAT)) {
+virReportError(VIR_ERR_INVALID_ARG,
+ _(unsupported config type %s), nativeFormat);
+goto cleanup;
+}
+
+if (!(def = lxcParseConfigString(nativeConfig)))
+goto cleanup;
+
+xml = virDomainDefFormat(def, 0);
+
+cleanup:
+virDomainDefFree(def);
+return xml;
+}
+
/**
* lxcDomainCreateWithFiles:
* @dom: domain to start
@@ -5376,6 +5406,7 @@ static virDriver lxcDriver = {
.domainGetSecurityLabel = lxcDomainGetSecurityLabel, /* 0.9.10 */
.nodeGetSecurityModel = lxcNodeGetSecurityModel, /* 0.9.10 */
.domainGetXMLDesc = lxcDomainGetXMLDesc, /* 0.4.2 */
+.connectDomainXMLFromNative = lxcConnectDomainXMLFromNative, /* 1.2.2 */
.connectListDefinedDomains = lxcConnectListDefinedDomains, /* 0.4.2 */
.connectNumOfDefinedDomains = lxcConnectNumOfDefinedDomains, /* 0.4.2 */
.domainCreate = lxcDomainCreate, /* 0.4.4 */
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
new file mode 100644
index 000..723ebcf
--- /dev/null
+++ b/src/lxc/lxc_native.c
@@ -0,0 +1,86 @@
+/*
+ * lxc_native.c: LXC native configuration import
+ *
+ * Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the