提交 7bfd6e97 编写于 作者: C Cédric Bosdonnat 提交者: Daniel P. Berrange

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.
上级 a41680f8
...@@ -328,6 +328,57 @@ lxcFstabWalkCallback(const char* name, virConfValuePtr value, void * data) ...@@ -328,6 +328,57 @@ lxcFstabWalkCallback(const char* name, virConfValuePtr value, void * data)
return ret; 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 virDomainDefPtr
lxcParseConfigString(const char *config) lxcParseConfigString(const char *config)
{ {
...@@ -388,6 +439,10 @@ lxcParseConfigString(const char *config) ...@@ -388,6 +439,10 @@ lxcParseConfigString(const char *config)
if (virConfWalk(properties, lxcFstabWalkCallback, vmdef) < 0) if (virConfWalk(properties, lxcFstabWalkCallback, vmdef) < 0)
goto error; goto error;
/* Network configuration */
if (lxcConvertNetworkSettings(vmdef, properties) < 0)
goto error;
goto cleanup; goto cleanup;
error: error:
......
lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
lxc.utsname = migrate_test
lxc.autodev=1
lxc.network.type = none
<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>
lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
lxc.utsname = migrate_test
lxc.autodev=1
<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) ...@@ -104,6 +104,8 @@ mymain(void)
DO_TEST("simple", false); DO_TEST("simple", false);
DO_TEST("fstab", true); DO_TEST("fstab", true);
DO_TEST("nonetwork", false);
DO_TEST("nonenetwork", false);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册