mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
LXC from native: implement no network conversion
If no network configuration is provided, LXC only provides the loopback interface. To match this, we need to use the privnet feature. LXC will also define a 'none' network type in its 1.0.0 version that fits libvirt LXC driver's default.
This commit is contained in:
parent
a41680f8c5
commit
7bfd6e97ec
@ -328,6 +328,57 @@ lxcFstabWalkCallback(const char* name, virConfValuePtr value, void * data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char *type;
|
||||
bool privnet;
|
||||
size_t networks;
|
||||
} lxcNetworkParseData;
|
||||
|
||||
static int
|
||||
lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
|
||||
{
|
||||
lxcNetworkParseData *parseData = data;
|
||||
|
||||
if (STREQ(name, "lxc.network.type")) {
|
||||
if (parseData->type != NULL && STREQ(parseData->type, "none"))
|
||||
parseData->privnet = false;
|
||||
else if ((parseData->type != NULL) &&
|
||||
STRNEQ(parseData->type, "empty") &&
|
||||
STRNEQ(parseData->type, "")) {
|
||||
parseData->networks++;
|
||||
}
|
||||
|
||||
/* Start a new network interface config */
|
||||
parseData->type = NULL;
|
||||
|
||||
/* Keep the new value */
|
||||
parseData->type = value->str;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
|
||||
{
|
||||
lxcNetworkParseData data = {NULL, true, 0};
|
||||
|
||||
virConfWalk(properties, lxcNetworkWalkCallback, &data);
|
||||
|
||||
if ((data.type != NULL) && STREQ(data.type, "none"))
|
||||
data.privnet = false;
|
||||
else if ((data.type != NULL) && STRNEQ(data.type, "empty") &&
|
||||
STRNEQ(data.type, "")) {
|
||||
data.networks++;
|
||||
}
|
||||
|
||||
if (data.networks == 0 && data.privnet) {
|
||||
/* When no network type is provided LXC only adds loopback */
|
||||
def->features[VIR_DOMAIN_FEATURE_PRIVNET] = VIR_DOMAIN_FEATURE_STATE_ON;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
virDomainDefPtr
|
||||
lxcParseConfigString(const char *config)
|
||||
{
|
||||
@ -388,6 +439,10 @@ lxcParseConfigString(const char *config)
|
||||
if (virConfWalk(properties, lxcFstabWalkCallback, vmdef) < 0)
|
||||
goto error;
|
||||
|
||||
/* Network configuration */
|
||||
if (lxcConvertNetworkSettings(vmdef, properties) < 0)
|
||||
goto error;
|
||||
|
||||
goto cleanup;
|
||||
|
||||
error:
|
||||
|
4
tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.config
Normal file
4
tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.config
Normal file
@ -0,0 +1,4 @@
|
||||
lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
|
||||
lxc.utsname = migrate_test
|
||||
lxc.autodev=1
|
||||
lxc.network.type = none
|
21
tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml
Normal file
21
tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<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>
|
||||
<filesystem type='mount' accessmode='passthrough'>
|
||||
<source dir='/var/lib/lxc/migrate_test/rootfs'/>
|
||||
<target dir='/'/>
|
||||
</filesystem>
|
||||
</devices>
|
||||
</domain>
|
3
tests/lxcconf2xmldata/lxcconf2xml-nonetwork.config
Normal file
3
tests/lxcconf2xmldata/lxcconf2xml-nonetwork.config
Normal file
@ -0,0 +1,3 @@
|
||||
lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
|
||||
lxc.utsname = migrate_test
|
||||
lxc.autodev=1
|
24
tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml
Normal file
24
tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<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>
|
||||
<features>
|
||||
<privnet/>
|
||||
</features>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<filesystem type='mount' accessmode='passthrough'>
|
||||
<source dir='/var/lib/lxc/migrate_test/rootfs'/>
|
||||
<target dir='/'/>
|
||||
</filesystem>
|
||||
</devices>
|
||||
</domain>
|
@ -104,6 +104,8 @@ mymain(void)
|
||||
|
||||
DO_TEST("simple", false);
|
||||
DO_TEST("fstab", true);
|
||||
DO_TEST("nonetwork", false);
|
||||
DO_TEST("nonenetwork", false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user