1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

snapshot: simplify indentation of network xml

More simplifications possible due to auto-indent.  Also,
<bandwidth> within <actual> was only using 6 instead of 8 spaces.

* src/util/network.h (virVirtualPortProfileFormat)
(virBandwidthDefFormat): Alter signature.
* src/util/network.c (virVirtualPortProfileFormat)
(virBandwidthDefFormat): Alter indentation.
(virBandwidthChildDefFormat): Tweak to make use easier.
* src/conf/network_conf.c (virPortGroupDefFormat)
(virNetworkDefFormat): Adjust callers.
* src/conf/domain_conf.c (virDomainNetDefFormat): Likewise.
(virDomainActualNetDefFormat): Likewise, and fix bandwidth
indentation.
This commit is contained in:
Eric Blake 2011-09-22 12:00:45 -06:00
parent 4eedfd075e
commit e36da1bd8a
4 changed files with 47 additions and 50 deletions

View File

@ -9491,15 +9491,18 @@ virDomainActualNetDefFormat(virBufferPtr buf,
return ret; return ret;
} }
virBufferAsprintf(buf, " mode='%s'/>\n", mode); virBufferAsprintf(buf, " mode='%s'/>\n", mode);
virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile, virBufferAdjustIndent(buf, 8);
" "); virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile);
virBufferAdjustIndent(buf, -8);
break; break;
default: default:
break; break;
} }
if (virBandwidthDefFormat(buf, def->bandwidth, " ") < 0) virBufferAdjustIndent(buf, 8);
if (virBandwidthDefFormat(buf, def->bandwidth) < 0)
goto error; goto error;
virBufferAdjustIndent(buf, -8);
virBufferAddLit(buf, " </actual>\n"); virBufferAddLit(buf, " </actual>\n");
@ -9538,8 +9541,9 @@ virDomainNetDefFormat(virBufferPtr buf,
def->data.network.portgroup); def->data.network.portgroup);
} }
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
virVirtualPortProfileFormat(buf, def->data.network.virtPortProfile, virBufferAdjustIndent(buf, 6);
" "); virVirtualPortProfileFormat(buf, def->data.network.virtPortProfile);
virBufferAdjustIndent(buf, -6);
if ((flags & VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET) && if ((flags & VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET) &&
(virDomainActualNetDefFormat(buf, def->data.network.actual) < 0)) (virDomainActualNetDefFormat(buf, def->data.network.actual) < 0))
return -1; return -1;
@ -9590,8 +9594,9 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, " mode='%s'", virBufferAsprintf(buf, " mode='%s'",
virMacvtapModeTypeToString(def->data.direct.mode)); virMacvtapModeTypeToString(def->data.direct.mode));
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile, virBufferAdjustIndent(buf, 6);
" "); virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile);
virBufferAdjustIndent(buf, -6);
break; break;
case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_USER:
@ -9656,8 +9661,10 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, " <link state='%s'/>\n", virBufferAsprintf(buf, " <link state='%s'/>\n",
virDomainNetInterfaceLinkStateTypeToString(def->linkstate)); virDomainNetInterfaceLinkStateTypeToString(def->linkstate));
if (virBandwidthDefFormat(buf, def->bandwidth, " ") < 0) virBufferAdjustIndent(buf, 6);
if (virBandwidthDefFormat(buf, def->bandwidth) < 0)
return -1; return -1;
virBufferAdjustIndent(buf, -6);
if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
return -1; return -1;

View File

@ -1267,8 +1267,10 @@ virPortGroupDefFormat(virBufferPtr buf,
virBufferAddLit(buf, " default='yes'"); virBufferAddLit(buf, " default='yes'");
} }
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
virVirtualPortProfileFormat(buf, def->virtPortProfile, " "); virBufferAdjustIndent(buf, 4);
virBandwidthDefFormat(buf, def->bandwidth, " "); virVirtualPortProfileFormat(buf, def->virtPortProfile);
virBandwidthDefFormat(buf, def->bandwidth);
virBufferAdjustIndent(buf, -4);
virBufferAddLit(buf, " </portgroup>\n"); virBufferAddLit(buf, " </portgroup>\n");
} }
@ -1341,15 +1343,19 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
if (virNetworkDNSDefFormat(&buf, def->dns) < 0) if (virNetworkDNSDefFormat(&buf, def->dns) < 0)
goto error; goto error;
if (virBandwidthDefFormat(&buf, def->bandwidth, " ") < 0) virBufferAdjustIndent(&buf, 2);
if (virBandwidthDefFormat(&buf, def->bandwidth) < 0)
goto error; goto error;
virBufferAdjustIndent(&buf, -2);
for (ii = 0; ii < def->nips; ii++) { for (ii = 0; ii < def->nips; ii++) {
if (virNetworkIpDefFormat(&buf, &def->ips[ii]) < 0) if (virNetworkIpDefFormat(&buf, &def->ips[ii]) < 0)
goto error; goto error;
} }
virVirtualPortProfileFormat(&buf, def->virtPortProfile, " "); virBufferAdjustIndent(&buf, 2);
virVirtualPortProfileFormat(&buf, def->virtPortProfile);
virBufferAdjustIndent(&buf, -2);
for (ii = 0; ii < def->nPortGroups; ii++) for (ii = 0; ii < def->nPortGroups; ii++)
virPortGroupDefFormat(&buf, &def->portGroups[ii]); virPortGroupDefFormat(&buf, &def->portGroups[ii]);

View File

@ -881,16 +881,14 @@ virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, virVirtualPortProfi
void void
virVirtualPortProfileFormat(virBufferPtr buf, virVirtualPortProfileFormat(virBufferPtr buf,
virVirtualPortProfileParamsPtr virtPort, virVirtualPortProfileParamsPtr virtPort)
const char *indent)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
if (!virtPort || virtPort->virtPortType == VIR_VIRTUALPORT_NONE) if (!virtPort || virtPort->virtPortType == VIR_VIRTUALPORT_NONE)
return; return;
virBufferAsprintf(buf, "%s<virtualport type='%s'>\n", virBufferAsprintf(buf, "<virtualport type='%s'>\n",
indent,
virVirtualPortTypeToString(virtPort->virtPortType)); virVirtualPortTypeToString(virtPort->virtPortType));
switch (virtPort->virtPortType) { switch (virtPort->virtPortType) {
@ -902,9 +900,8 @@ virVirtualPortProfileFormat(virBufferPtr buf,
virUUIDFormat(virtPort->u.virtPort8021Qbg.instanceID, virUUIDFormat(virtPort->u.virtPort8021Qbg.instanceID,
uuidstr); uuidstr);
virBufferAsprintf(buf, virBufferAsprintf(buf,
"%s <parameters managerid='%d' typeid='%d' " " <parameters managerid='%d' typeid='%d' "
"typeidversion='%d' instanceid='%s'/>\n", "typeidversion='%d' instanceid='%s'/>\n",
indent,
virtPort->u.virtPort8021Qbg.managerID, virtPort->u.virtPort8021Qbg.managerID,
virtPort->u.virtPort8021Qbg.typeID, virtPort->u.virtPort8021Qbg.typeID,
virtPort->u.virtPort8021Qbg.typeIDVersion, virtPort->u.virtPort8021Qbg.typeIDVersion,
@ -913,13 +910,12 @@ virVirtualPortProfileFormat(virBufferPtr buf,
case VIR_VIRTUALPORT_8021QBH: case VIR_VIRTUALPORT_8021QBH:
virBufferAsprintf(buf, virBufferAsprintf(buf,
"%s <parameters profileid='%s'/>\n", " <parameters profileid='%s'/>\n",
indent,
virtPort->u.virtPort8021Qbh.profileID); virtPort->u.virtPort8021Qbh.profileID);
break; break;
} }
virBufferAsprintf(buf, "%s</virtualport>\n", indent); virBufferAddLit(buf, "</virtualport>\n");
} }
static int static int
@ -1074,11 +1070,14 @@ virBandwidthChildDefFormat(virBufferPtr buf,
virRatePtr def, virRatePtr def,
const char *elem_name) const char *elem_name)
{ {
if (!buf || !def || !elem_name) if (!buf || !elem_name)
return -1; return -1;
if (!def)
return 0;
if (def->average) { if (def->average) {
virBufferAsprintf(buf, "<%s average='%llu'", elem_name, def->average); virBufferAsprintf(buf, " <%s average='%llu'", elem_name,
def->average);
if (def->peak) if (def->peak)
virBufferAsprintf(buf, " peak='%llu'", def->peak); virBufferAsprintf(buf, " peak='%llu'", def->peak);
@ -1095,17 +1094,15 @@ virBandwidthChildDefFormat(virBufferPtr buf,
* virBandwidthDefFormat: * virBandwidthDefFormat:
* @buf: Buffer to print to * @buf: Buffer to print to
* @def: Data source * @def: Data source
* @indent: prepend all lines printed with this
* *
* Formats bandwidth and prepend each line with @indent. * Formats bandwidth and prepend each line with @indent.
* Passing NULL to @indent is equivalent passing "". * @buf may use auto-indentation.
* *
* Returns 0 on success, else -1. * Returns 0 on success, else -1.
*/ */
int int
virBandwidthDefFormat(virBufferPtr buf, virBandwidthDefFormat(virBufferPtr buf,
virBandwidthPtr def, virBandwidthPtr def)
const char *indent)
{ {
int ret = -1; int ret = -1;
@ -1117,23 +1114,11 @@ virBandwidthDefFormat(virBufferPtr buf,
goto cleanup; goto cleanup;
} }
if (!indent) virBufferAddLit(buf, "<bandwidth>\n");
indent = ""; if (virBandwidthChildDefFormat(buf, def->in, "inbound") < 0 ||
virBandwidthChildDefFormat(buf, def->out, "outbound") < 0)
virBufferAsprintf(buf, "%s<bandwidth>\n", indent); goto cleanup;
if (def->in) { virBufferAddLit(buf, "</bandwidth>\n");
virBufferAsprintf(buf, "%s ", indent);
if (virBandwidthChildDefFormat(buf, def->in, "inbound") < 0)
goto cleanup;
}
if (def->out) {
virBufferAsprintf(buf, "%s ", indent);
if (virBandwidthChildDefFormat(buf, def->out, "outbound") < 0)
goto cleanup;
}
virBufferAsprintf(buf, "%s</bandwidth>\n", indent);
ret = 0; ret = 0;

View File

@ -1,7 +1,7 @@
/* /*
* network.h: network helper APIs for libvirt * network.h: network helper APIs for libvirt
* *
* Copyright (C) 2009-2009 Red Hat, Inc. * Copyright (C) 2009-2011 Red Hat, Inc.
* *
* See COPYING.LIB for the License of this software * See COPYING.LIB for the License of this software
* *
@ -147,16 +147,15 @@ virVirtualPortProfileParseXML(xmlNodePtr node,
virVirtualPortProfileParamsPtr *virtPort); virVirtualPortProfileParamsPtr *virtPort);
void void
virVirtualPortProfileFormat(virBufferPtr buf, virVirtualPortProfileFormat(virBufferPtr buf,
virVirtualPortProfileParamsPtr virtPort, virVirtualPortProfileParamsPtr virtPort);
const char *indent);
bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, virVirtualPortProfileParamsPtr b); bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a,
virVirtualPortProfileParamsPtr b);
virBandwidthPtr virBandwidthDefParseNode(xmlNodePtr node); virBandwidthPtr virBandwidthDefParseNode(xmlNodePtr node);
void virBandwidthDefFree(virBandwidthPtr def); void virBandwidthDefFree(virBandwidthPtr def);
int virBandwidthDefFormat(virBufferPtr buf, int virBandwidthDefFormat(virBufferPtr buf,
virBandwidthPtr def, virBandwidthPtr def);
const char *indent);
int virBandwidthEnable(virBandwidthPtr bandwidth, const char *iface); int virBandwidthEnable(virBandwidthPtr bandwidth, const char *iface);
int virBandwidthDisable(const char *iface, bool may_fail); int virBandwidthDisable(const char *iface, bool may_fail);