net: Add support for changing persistent networks to transient

Until now, the network undefine API was able to undefine only inactive
networks. The restriction doesn't make sense any more so this patch
implements changing networks to transient.
This commit is contained in:
Peter Krempa 2012-10-25 16:32:29 +02:00
parent b6dbbae128
commit fa16957ccd

View File

@ -2864,6 +2864,7 @@ networkUndefine(virNetworkPtr net) {
struct network_driver *driver = net->conn->networkPrivateData;
virNetworkObjPtr network;
int ret = -1;
bool active = false;
networkDriverLock(driver);
@ -2874,24 +2875,28 @@ networkUndefine(virNetworkPtr net) {
goto cleanup;
}
if (virNetworkObjIsActive(network)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("network is still active"));
goto cleanup;
}
if (virNetworkObjIsActive(network))
active = true;
if (virNetworkDeleteConfig(driver->networkConfigDir,
driver->networkAutostartDir,
network) < 0)
goto cleanup;
/* make the network transient */
network->persistent = 0;
virNetworkDefFree(network->newDef);
network->newDef = NULL;
VIR_INFO("Undefining network '%s'", network->def->name);
if (networkRemoveInactive(driver, network) < 0) {
if (!active) {
if (networkRemoveInactive(driver, network) < 0) {
network = NULL;
goto cleanup;
}
network = NULL;
goto cleanup;
}
network = NULL;
ret = 0;
cleanup: