提交 e85df090 编写于 作者: C Cédric Bosdonnat

Report error if a driver can't handle multiple IP addresses

Drivers supporting one and only one IP address raise an error if more IP
addresses are configured.
上级 a4e86390
......@@ -1254,7 +1254,7 @@ vboxAttachSound(virDomainDefPtr def, IMachine *machine)
VBOX_RELEASE(audioAdapter);
}
static void
static int
vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{
ISystemProperties *systemProperties = NULL;
......@@ -1306,10 +1306,14 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
} else if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
VIR_DEBUG("NIC(%zu): brname: %s", i, def->nets[i]->data.bridge.brname);
VIR_DEBUG("NIC(%zu): script: %s", i, def->nets[i]->script);
if (def->nets[i]->nips > 0) {
if (def->nets[i]->nips == 1) {
char *ipStr = virSocketAddrFormat(&def->nets[i]->ips[0]->address);
VIR_DEBUG("NIC(%zu): ipaddr: %s", i, ipStr);
VIR_FREE(ipStr);
} else if (def->nets[i]->nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Driver does not support setting multiple IP addresses"));
return -1;
}
}
......@@ -1393,6 +1397,7 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
gVBoxAPI.UINetworkAdapter.SetMACAddress(adapter, MACAddress);
VBOX_UTF16_FREE(MACAddress);
}
return 0;
}
static void
......@@ -1938,7 +1943,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml)
vboxSetBootDeviceOrder(def, data, machine);
vboxAttachDrives(def, data, machine);
vboxAttachSound(def, machine);
vboxAttachNetwork(def, data, machine);
if (vboxAttachNetwork(def, data, machine) < 0)
goto cleanup;
vboxAttachSerial(def, data, machine);
vboxAttachParallel(def, data, machine);
vboxAttachVideo(def, machine);
......
......@@ -1220,10 +1220,14 @@ xenFormatNet(virConnectPtr conn,
switch (net->type) {
case VIR_DOMAIN_NET_TYPE_BRIDGE:
virBufferAsprintf(&buf, ",bridge=%s", net->data.bridge.brname);
if (net->nips > 0) {
if (net->nips == 1) {
char *ipStr = virSocketAddrFormat(&net->ips[0]->address);
virBufferAsprintf(&buf, ",ip=%s", ipStr);
VIR_FREE(ipStr);
} else if (net->nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Driver does not support setting multiple IP addresses"));
goto cleanup;
}
virBufferAsprintf(&buf, ",script=%s", DEFAULT_VIF_SCRIPT);
break;
......@@ -1231,10 +1235,14 @@ xenFormatNet(virConnectPtr conn,
case VIR_DOMAIN_NET_TYPE_ETHERNET:
if (net->script)
virBufferAsprintf(&buf, ",script=%s", net->script);
if (net->nips > 0) {
if (net->nips == 1) {
char *ipStr = virSocketAddrFormat(&net->ips[0]->address);
virBufferAsprintf(&buf, ",ip=%s", ipStr);
VIR_FREE(ipStr);
} else if (net->nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Driver does not support setting multiple IP addresses"));
goto cleanup;
}
break;
......
......@@ -1898,10 +1898,14 @@ xenFormatSxprNet(virConnectPtr conn,
script = def->script;
virBufferEscapeSexpr(buf, "(script '%s')", script);
if (def->nips > 0) {
if (def->nips == 1) {
char *ipStr = virSocketAddrFormat(&def->ips[0]->address);
virBufferEscapeSexpr(buf, "(ip '%s')", ipStr);
VIR_FREE(ipStr);
} else if (def->nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Driver does not support setting multiple IP addresses"));
return -1;
}
break;
......@@ -1935,10 +1939,14 @@ xenFormatSxprNet(virConnectPtr conn,
if (def->script)
virBufferEscapeSexpr(buf, "(script '%s')",
def->script);
if (def->nips > 0) {
if (def->nips == 1) {
char *ipStr = virSocketAddrFormat(&def->ips[0]->address);
virBufferEscapeSexpr(buf, "(ip '%s')", ipStr);
VIR_FREE(ipStr);
} else if (def->nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Driver does not support setting multiple IP addresses"));
return -1;
}
break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册