Added new option to virsh net-dumpxml called --inactive

The above option helps to differentiate between implicit and explicit
interface pools.
This commit is contained in:
Shradha Shah 2011-12-14 10:50:40 +00:00 committed by Eric Blake
parent 42c81d18c2
commit 52d064f42d
10 changed files with 53 additions and 21 deletions

View File

@ -1882,6 +1882,10 @@ int virNodeGetCellsFreeMemory(virConnectPtr conn,
* Virtual Networks API
*/
typedef enum {
VIR_NETWORK_XML_INACTIVE = (1 << 0), /* dump inactive network information */
} virNetworkXMLFlags;
/**
* virNetwork:
*

View File

@ -1448,7 +1448,7 @@ virPortGroupDefFormat(virBufferPtr buf,
return 0;
}
char *virNetworkDefFormat(const virNetworkDefPtr def)
char *virNetworkDefFormat(const virNetworkDefPtr def, unsigned int flags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
unsigned char *uuid;
@ -1484,7 +1484,8 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
virBufferEscapeString(&buf, " <pf dev='%s'/>\n",
def->forwardPfs[0].dev);
if (def->nForwardIfs) {
if (def->nForwardIfs &&
(!def->nForwardPfs || !(flags & VIR_NETWORK_XML_INACTIVE))) {
for (ii = 0; ii < def->nForwardIfs; ii++) {
virBufferEscapeString(&buf, " <interface dev='%s'/>\n",
def->forwardIfs[ii].dev);
@ -1601,7 +1602,7 @@ int virNetworkSaveConfig(const char *configDir,
int ret = -1;
char *xml;
if (!(xml = virNetworkDefFormat(def)))
if (!(xml = virNetworkDefFormat(def, 0)))
goto cleanup;
if (virNetworkSaveXML(configDir, def, xml))

View File

@ -227,7 +227,7 @@ virNetworkDefPtr virNetworkDefParseFile(const char *filename);
virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
xmlNodePtr root);
char *virNetworkDefFormat(const virNetworkDefPtr def);
char *virNetworkDefFormat(const virNetworkDefPtr def, unsigned int flags);
static inline const char *
virNetworkDefForwardIf(const virNetworkDefPtr def, size_t n)

View File

@ -9835,11 +9835,16 @@ error:
/**
* virNetworkGetXMLDesc:
* @network: a network object
* @flags: extra flags; not used yet, so callers should always pass 0
* @flags: bitwise-OR of virNetworkXMLFlags
*
* Provide an XML description of the network. The description may be reused
* later to relaunch the network with virNetworkCreateXML().
*
* Normally, if a network included a physical function, the output includes
* all virtual functions tied to that physical interface. If @flags includes
* VIR_NETWORK_XML_INACTIVE, then the expansion of virtual interfaces is
* not performed.
*
* Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
* the caller must free() the returned value.
*/

View File

@ -2533,7 +2533,7 @@ static char *networkGetXMLDesc(virNetworkPtr net,
virNetworkObjPtr network;
char *ret = NULL;
virCheckFlags(0, NULL);
virCheckFlags(VIR_NETWORK_XML_INACTIVE, NULL);
networkDriverLock(driver);
network = virNetworkFindByUUID(&driver->networks, net->uuid);
@ -2545,7 +2545,7 @@ static char *networkGetXMLDesc(virNetworkPtr net,
goto cleanup;
}
ret = virNetworkDefFormat(network->def);
ret = virNetworkDefFormat(network->def, flags);
cleanup:
if (network)

View File

@ -1,7 +1,7 @@
/*
* test.c: A "mock" hypervisor for use by application unit tests
*
* Copyright (C) 2006-2011 Red Hat, Inc.
* Copyright (C) 2006-2012 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@ -3233,7 +3233,7 @@ static char *testNetworkGetXMLDesc(virNetworkPtr network,
goto cleanup;
}
ret = virNetworkDefFormat(privnet->def);
ret = virNetworkDefFormat(privnet->def, flags);
cleanup:
if (privnet)

View File

@ -8098,7 +8098,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network,
VBOX_UTF16_FREE(networkInterfaceNameUtf16);
VBOX_RELEASE(host);
ret = virNetworkDefFormat(def);
ret = virNetworkDefFormat(def, 0);
cleanup:
virNetworkDefFree(def);

View File

@ -14,7 +14,8 @@
#include "testutilsqemu.h"
static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
unsigned int flags)
{
char *inXmlData = NULL;
char *outXmlData = NULL;
@ -30,7 +31,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
if (!(dev = virNetworkDefParseString(inXmlData)))
goto fail;
if (!(actual = virNetworkDefFormat(dev)))
if (!(actual = virNetworkDefFormat(dev, flags)))
goto fail;
if (STRNEQ(outXmlData, actual)) {
@ -48,21 +49,27 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
return ret;
}
struct testInfo {
const char *name;
unsigned int flags;
};
static int
testCompareXMLToXMLHelper(const void *data)
{
const struct testInfo *info = data;
int result = -1;
char *inxml = NULL;
char *outxml = NULL;
if (virAsprintf(&inxml, "%s/networkxml2xmlin/%s.xml",
abs_srcdir, (const char*)data) < 0 ||
abs_srcdir, info->name) < 0 ||
virAsprintf(&outxml, "%s/networkxml2xmlout/%s.xml",
abs_srcdir, (const char*)data) < 0) {
abs_srcdir, info->name) < 0) {
goto cleanup;
}
result = testCompareXMLToXMLFiles(inxml, outxml);
result = testCompareXMLToXMLFiles(inxml, outxml, info->flags);
cleanup:
free(inxml);
@ -76,10 +83,14 @@ mymain(void)
{
int ret = 0;
#define DO_TEST(name) \
if (virtTestRun("Network XML-2-XML " name, \
1, testCompareXMLToXMLHelper, (name)) < 0) \
ret = -1
#define DO_TEST_FULL(name, flags) \
do { \
const struct testInfo info = {name, flags}; \
if (virtTestRun("Network XML-2-XML " name, \
1, testCompareXMLToXMLHelper, &info) < 0) \
ret = -1; \
} while (0)
#define DO_TEST(name) DO_TEST_FULL(name, 0)
DO_TEST("isolated-network");
DO_TEST("routed-network");
@ -93,6 +104,7 @@ mymain(void)
DO_TEST("host-bridge-net");
DO_TEST("vepa-net");
DO_TEST("bandwidth-network");
DO_TEST_FULL("passthrough-pf", VIR_NETWORK_XML_INACTIVE);
return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@ -7286,6 +7286,7 @@ static const vshCmdInfo info_network_dumpxml[] = {
static const vshCmdOptDef opts_network_dumpxml[] = {
{"network", VSH_OT_DATA, VSH_OFLAG_REQ, N_("network name or uuid")},
{"inactive", VSH_OT_BOOL, VSH_OFLAG_NONE, N_("network information of an inactive domain")},
{NULL, 0, 0, NULL}
};
@ -7295,6 +7296,8 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
virNetworkPtr network;
bool ret = true;
char *dump;
unsigned int flags = 0;
int inactive;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
@ -7302,7 +7305,12 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
if (!(network = vshCommandOptNetwork(ctl, cmd, NULL)))
return false;
dump = virNetworkGetXMLDesc(network, 0);
inactive = vshCommandOptBool (cmd, "inactive");
if (inactive)
flags |= VIR_NETWORK_XML_INACTIVE;
dump = virNetworkGetXMLDesc(network, flags);
if (dump != NULL) {
vshPrint(ctl, "%s", dump);
VIR_FREE(dump);

View File

@ -1523,9 +1523,11 @@ not instantiated.
Destroy (stop) a given virtual network specified by its name or UUID. This
takes effect immediately.
=item B<net-dumpxml> I<network>
=item B<net-dumpxml> I<network> [I<--inactive>]
Output the virtual network information as an XML dump to stdout.
If I<--inactive> is specified, then physical functions are not
expanded into their associated virtual functions.
=item B<net-edit> I<network>