mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
LXC driver: started implementing connectDomainXMLFromNative
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.
This commit is contained in:
committed by
Daniel P. Berrange
parent
3daa14834a
commit
7195c807b2
@@ -200,7 +200,7 @@ test_programs += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest \
|
||||
endif WITH_QEMU
|
||||
|
||||
if WITH_LXC
|
||||
test_programs += lxcxml2xmltest
|
||||
test_programs += lxcxml2xmltest lxcconf2xmltest
|
||||
endif WITH_LXC
|
||||
|
||||
if WITH_OPENVZ
|
||||
@@ -523,6 +523,11 @@ lxcxml2xmltest_SOURCES = \
|
||||
lxcxml2xmltest.c testutilslxc.c testutilslxc.h \
|
||||
testutils.c testutils.h
|
||||
lxcxml2xmltest_LDADD = $(lxc_LDADDS)
|
||||
|
||||
lxcconf2xmltest_SOURCES = \
|
||||
lxcconf2xmltest.c \
|
||||
testutils.c testutils.h
|
||||
lxcconf2xmltest_LDADD = $(lxc_LDADDS)
|
||||
else ! WITH_LXC
|
||||
EXTRA_DIST += lxcxml2xmltest.c testutilslxc.c testutilslxc.h
|
||||
endif ! WITH_LXC
|
||||
|
||||
38
tests/lxcconf2xmldata/lxcconf2xml-simple.config
Normal file
38
tests/lxcconf2xmldata/lxcconf2xml-simple.config
Normal file
@@ -0,0 +1,38 @@
|
||||
# Template used to create this container: opensuse
|
||||
# Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef
|
||||
|
||||
lxc.network.type = veth
|
||||
lxc.network.flags = up
|
||||
lxc.network.link = virbr0
|
||||
lxc.network.hwaddr = 02:00:15:8f:05:c1
|
||||
lxc.network.name = eth0
|
||||
|
||||
#remove next line if host DNS configuration should not be available to container
|
||||
lxc.mount.entry = /etc/resolv.conf etc/resolv.conf none bind,ro 0 0
|
||||
lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
|
||||
lxc.utsname = migrate_test
|
||||
lxc.autodev=1
|
||||
lxc.tty = 2
|
||||
lxc.pts = 1024
|
||||
lxc.mount = /var/lib/lxc/migrate_test/fstab
|
||||
lxc.cap.drop = sys_module mac_admin mac_override mknod
|
||||
|
||||
# When using LXC with apparmor, uncomment the next line to run unconfined:
|
||||
#lxc.aa_profile = unconfined
|
||||
|
||||
lxc.cgroup.devices.deny = a
|
||||
# /dev/null and zero
|
||||
lxc.cgroup.devices.allow = c 1:3 rwm
|
||||
lxc.cgroup.devices.allow = c 1:5 rwm
|
||||
# consoles
|
||||
lxc.cgroup.devices.allow = c 5:1 rwm
|
||||
lxc.cgroup.devices.allow = c 5:0 rwm
|
||||
lxc.cgroup.devices.allow = c 4:0 rwm
|
||||
lxc.cgroup.devices.allow = c 4:1 rwm
|
||||
# /dev/{,u}random
|
||||
lxc.cgroup.devices.allow = c 1:9 rwm
|
||||
lxc.cgroup.devices.allow = c 1:8 rwm
|
||||
lxc.cgroup.devices.allow = c 136:* rwm
|
||||
lxc.cgroup.devices.allow = c 5:2 rwm
|
||||
# rtc
|
||||
lxc.cgroup.devices.allow = c 254:0 rwm
|
||||
17
tests/lxcconf2xmldata/lxcconf2xml-simple.xml
Normal file
17
tests/lxcconf2xmldata/lxcconf2xml-simple.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<domain type='lxc'>
|
||||
<name>migrate_test</name>
|
||||
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||
<memory unit='KiB'>65536</memory>
|
||||
<currentMemory unit='KiB'>0</currentMemory>
|
||||
<vcpu placement='static' current='0'>1</vcpu>
|
||||
<os>
|
||||
<type>exe</type>
|
||||
<init>/sbin/init</init>
|
||||
</os>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
</devices>
|
||||
</domain>
|
||||
107
tests/lxcconf2xmltest.c
Normal file
107
tests/lxcconf2xmltest.c
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "testutils.h"
|
||||
|
||||
#ifdef WITH_LXC
|
||||
|
||||
# include "lxc/lxc_native.h"
|
||||
|
||||
# define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
static int
|
||||
blankProblemElements(char *data)
|
||||
{
|
||||
if (virtTestClearLineRegex("<uuid>([[:alnum:]]|-)+</uuid>", data) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
testCompareXMLToConfigFiles(const char *xml,
|
||||
const char *configfile)
|
||||
{
|
||||
int ret = -1;
|
||||
char *config = NULL;
|
||||
char *expectxml = NULL;
|
||||
char *actualxml = NULL;
|
||||
virDomainDefPtr vmdef = NULL;
|
||||
|
||||
if (virtTestLoadFile(configfile, &config) < 0)
|
||||
goto fail;
|
||||
if (virtTestLoadFile(xml, &expectxml) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(vmdef = lxcParseConfigString(config)))
|
||||
goto fail;
|
||||
|
||||
if (!(actualxml = virDomainDefFormat(vmdef, 0)))
|
||||
goto fail;
|
||||
|
||||
if (blankProblemElements(expectxml) < 0 ||
|
||||
blankProblemElements(actualxml) < 0)
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(expectxml, actualxml)) {
|
||||
virtTestDifference(stderr, expectxml, actualxml);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(expectxml);
|
||||
VIR_FREE(actualxml);
|
||||
VIR_FREE(config);
|
||||
virDomainDefFree(vmdef);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
testCompareXMLToConfigHelper(const void *data)
|
||||
{
|
||||
int result = -1;
|
||||
const char *name = data;
|
||||
char *xml = NULL;
|
||||
char *config = NULL;
|
||||
|
||||
if (virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
|
||||
abs_srcdir, name) < 0 ||
|
||||
virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s.config",
|
||||
abs_srcdir, name) < 0)
|
||||
goto cleanup;
|
||||
|
||||
result = testCompareXMLToConfigFiles(xml, config);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(xml);
|
||||
VIR_FREE(config);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
# define DO_TEST(name) \
|
||||
if (virtTestRun("LXC Native-2-XML " name, \
|
||||
testCompareXMLToConfigHelper, \
|
||||
name) < 0) \
|
||||
ret = EXIT_FAILURE
|
||||
|
||||
DO_TEST("simple");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
VIRT_TEST_MAIN(mymain)
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
return EXIT_AM_SKIP;
|
||||
}
|
||||
|
||||
#endif /* WITH_LXC */
|
||||
Reference in New Issue
Block a user