mirror of https://gitee.com/openkylin/libvirt.git
Reverse logic allowing partial DHCP host XML
Before, missing attributes were only OK when adding entries; modification and deletion required all of them. Now, only deletion works with missing attributes, as long as the host is uniquely identified.
This commit is contained in:
parent
43cee32ff5
commit
cf602e7c59
|
@ -3297,6 +3297,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virNetworkIpDefPtr ipdef = virNetworkIpDefByIndex(def, parentIndex);
|
virNetworkIpDefPtr ipdef = virNetworkIpDefByIndex(def, parentIndex);
|
||||||
virNetworkDHCPHostDef host;
|
virNetworkDHCPHostDef host;
|
||||||
|
bool partialOkay = (command == VIR_NETWORK_UPDATE_COMMAND_DELETE);
|
||||||
|
|
||||||
memset(&host, 0, sizeof(host));
|
memset(&host, 0, sizeof(host));
|
||||||
|
|
||||||
|
@ -3307,13 +3308,11 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
|
||||||
if (!ipdef)
|
if (!ipdef)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* parse the xml into a virNetworkDHCPHostDef */
|
if (virNetworkDHCPHostDefParseXML(def->name, ipdef, ctxt->node,
|
||||||
if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) {
|
&host, partialOkay) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (virNetworkDHCPHostDefParseXML(def->name, ipdef,
|
if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) {
|
||||||
ctxt->node, &host, false) < 0) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* search for the entry with this (mac|name),
|
/* search for the entry with this (mac|name),
|
||||||
* and update the IP+(mac|name) */
|
* and update the IP+(mac|name) */
|
||||||
|
@ -3345,11 +3344,6 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
|
||||||
} else if ((command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST) ||
|
} else if ((command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST) ||
|
||||||
(command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST)) {
|
(command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST)) {
|
||||||
|
|
||||||
if (virNetworkDHCPHostDefParseXML(def->name, ipdef,
|
|
||||||
ctxt->node, &host, true) < 0) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* log error if an entry with same name/address/ip already exists */
|
/* log error if an entry with same name/address/ip already exists */
|
||||||
for (i = 0; i < ipdef->nhosts; i++) {
|
for (i = 0; i < ipdef->nhosts; i++) {
|
||||||
if ((host.mac &&
|
if ((host.mac &&
|
||||||
|
@ -3379,11 +3373,6 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) {
|
} else if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) {
|
||||||
|
|
||||||
if (virNetworkDHCPHostDefParseXML(def->name, ipdef,
|
|
||||||
ctxt->node, &host, false) < 0) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* find matching entry - all specified attributes must match */
|
/* find matching entry - all specified attributes must match */
|
||||||
for (i = 0; i < ipdef->nhosts; i++) {
|
for (i = 0; i < ipdef->nhosts; i++) {
|
||||||
if ((!host.mac ||
|
if ((!host.mac ||
|
||||||
|
|
Loading…
Reference in New Issue