network: fully support/use VIR_NETWORK_XML_INACTIVE flag

commit 52d064f42d added
VIR_NETWORK_XML_INACTIVE in order to allow suppressing the
auto-generated list of VFs in network definitions, and a --inactive
flag to virsh net-dumpxml to take advantage of the flag. However, it
missed out on two opportunities:

1) Use INACTIVE to get the current config of the network as it
   exists on disk, rather than the currently active config.

2) Add INACTIVE to the flags used for the virsh net-edit command, so
   that it won't include the forward-pool interfaces that were
   autogenerated, and so that a re-edit of the network prior to
   restarting it will show any other edits made since the last restart
   of the network. (prior to this patch, if you edited a network a 2nd
   time without restarting, all of the previous edits would magically
   disappear).

In order to fit with the new #define-based generic edit function in
virsh.c, a new function vshNetworkGetXMLDesc() was added. This
function first tries to call virNetworkGetXMLDesc with the INACTIVE
flag added, then retries without if the first attempt fails (in the
manner expected when the server doesn't support it).
This commit is contained in:
Laine Stump 2012-06-04 14:45:16 -04:00
parent 6510c97bf5
commit 1f145b2f0f
3 changed files with 26 additions and 4 deletions

View File

@ -2533,6 +2533,7 @@ static char *networkGetXMLDesc(virNetworkPtr net,
{
struct network_driver *driver = net->conn->networkPrivateData;
virNetworkObjPtr network;
virNetworkDefPtr def;
char *ret = NULL;
virCheckFlags(VIR_NETWORK_XML_INACTIVE, NULL);
@ -2547,7 +2548,12 @@ static char *networkGetXMLDesc(virNetworkPtr net,
goto cleanup;
}
ret = virNetworkDefFormat(network->def, flags);
if ((flags & VIR_NETWORK_XML_INACTIVE) && network->newDef)
def = network->newDef;
else
def = network->def;
ret = virNetworkDefFormat(def, flags);
cleanup:
if (network)

View File

@ -15823,13 +15823,29 @@ static const vshCmdOptDef opts_network_edit[] = {
{NULL, 0, 0, NULL}
};
static char *vshNetworkGetXMLDesc(virNetworkPtr network)
{
unsigned int flags = VIR_NETWORK_XML_INACTIVE;
char *doc = virNetworkGetXMLDesc(network, flags);
if (!doc && last_error->code == VIR_ERR_INVALID_ARG) {
/* The server side libvirt doesn't support
* VIR_NETWORK_XML_INACTIVE, so retry without it.
*/
virFreeError(last_error);
last_error = NULL;
flags &= ~VIR_NETWORK_XML_INACTIVE;
doc = virNetworkGetXMLDesc(network, flags);
}
return doc;
}
static bool
cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
{
bool ret = false;
virNetworkPtr network = NULL;
virNetworkPtr network_edited = NULL;
unsigned int flags = 0;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
@ -15838,7 +15854,7 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
if (network == NULL)
goto cleanup;
#define EDIT_GET_XML virNetworkGetXMLDesc(network, flags)
#define EDIT_GET_XML vshNetworkGetXMLDesc(network)
#define EDIT_NOT_CHANGED \
vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \
virNetworkGetName (network)); \

View File

@ -1823,7 +1823,7 @@ Edit the XML configuration file for a network.
This is equivalent to:
virsh net-dumpxml network > network.xml
virsh net-dumpxml --inactive network > network.xml
vi network.xml (or make changes with your other text editor)
virsh net-define network.xml