提交 e36da1bd 编写于 作者: E Eric Blake

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.
上级 4eedfd07
......@@ -9491,15 +9491,18 @@ virDomainActualNetDefFormat(virBufferPtr buf,
return ret;
}
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;
default:
break;
}
if (virBandwidthDefFormat(buf, def->bandwidth, " ") < 0)
virBufferAdjustIndent(buf, 8);
if (virBandwidthDefFormat(buf, def->bandwidth) < 0)
goto error;
virBufferAdjustIndent(buf, -8);
virBufferAddLit(buf, " </actual>\n");
......@@ -9538,8 +9541,9 @@ virDomainNetDefFormat(virBufferPtr buf,
def->data.network.portgroup);
}
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) &&
(virDomainActualNetDefFormat(buf, def->data.network.actual) < 0))
return -1;
......@@ -9590,8 +9594,9 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, " mode='%s'",
virMacvtapModeTypeToString(def->data.direct.mode));
virBufferAddLit(buf, "/>\n");
virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile,
" ");
virBufferAdjustIndent(buf, 6);
virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile);
virBufferAdjustIndent(buf, -6);
break;
case VIR_DOMAIN_NET_TYPE_USER:
......@@ -9656,8 +9661,10 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, " <link state='%s'/>\n",
virDomainNetInterfaceLinkStateTypeToString(def->linkstate));
if (virBandwidthDefFormat(buf, def->bandwidth, " ") < 0)
virBufferAdjustIndent(buf, 6);
if (virBandwidthDefFormat(buf, def->bandwidth) < 0)
return -1;
virBufferAdjustIndent(buf, -6);
if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
return -1;
......
......@@ -1267,8 +1267,10 @@ virPortGroupDefFormat(virBufferPtr buf,
virBufferAddLit(buf, " default='yes'");
}
virBufferAddLit(buf, ">\n");
virVirtualPortProfileFormat(buf, def->virtPortProfile, " ");
virBandwidthDefFormat(buf, def->bandwidth, " ");
virBufferAdjustIndent(buf, 4);
virVirtualPortProfileFormat(buf, def->virtPortProfile);
virBandwidthDefFormat(buf, def->bandwidth);
virBufferAdjustIndent(buf, -4);
virBufferAddLit(buf, " </portgroup>\n");
}
......@@ -1341,15 +1343,19 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
if (virNetworkDNSDefFormat(&buf, def->dns) < 0)
goto error;
if (virBandwidthDefFormat(&buf, def->bandwidth, " ") < 0)
virBufferAdjustIndent(&buf, 2);
if (virBandwidthDefFormat(&buf, def->bandwidth) < 0)
goto error;
virBufferAdjustIndent(&buf, -2);
for (ii = 0; ii < def->nips; ii++) {
if (virNetworkIpDefFormat(&buf, &def->ips[ii]) < 0)
goto error;
}
virVirtualPortProfileFormat(&buf, def->virtPortProfile, " ");
virBufferAdjustIndent(&buf, 2);
virVirtualPortProfileFormat(&buf, def->virtPortProfile);
virBufferAdjustIndent(&buf, -2);
for (ii = 0; ii < def->nPortGroups; ii++)
virPortGroupDefFormat(&buf, &def->portGroups[ii]);
......
......@@ -881,16 +881,14 @@ virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, virVirtualPortProfi
void
virVirtualPortProfileFormat(virBufferPtr buf,
virVirtualPortProfileParamsPtr virtPort,
const char *indent)
virVirtualPortProfileParamsPtr virtPort)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (!virtPort || virtPort->virtPortType == VIR_VIRTUALPORT_NONE)
return;
virBufferAsprintf(buf, "%s<virtualport type='%s'>\n",
indent,
virBufferAsprintf(buf, "<virtualport type='%s'>\n",
virVirtualPortTypeToString(virtPort->virtPortType));
switch (virtPort->virtPortType) {
......@@ -902,9 +900,8 @@ virVirtualPortProfileFormat(virBufferPtr buf,
virUUIDFormat(virtPort->u.virtPort8021Qbg.instanceID,
uuidstr);
virBufferAsprintf(buf,
"%s <parameters managerid='%d' typeid='%d' "
" <parameters managerid='%d' typeid='%d' "
"typeidversion='%d' instanceid='%s'/>\n",
indent,
virtPort->u.virtPort8021Qbg.managerID,
virtPort->u.virtPort8021Qbg.typeID,
virtPort->u.virtPort8021Qbg.typeIDVersion,
......@@ -913,13 +910,12 @@ virVirtualPortProfileFormat(virBufferPtr buf,
case VIR_VIRTUALPORT_8021QBH:
virBufferAsprintf(buf,
"%s <parameters profileid='%s'/>\n",
indent,
" <parameters profileid='%s'/>\n",
virtPort->u.virtPort8021Qbh.profileID);
break;
}
virBufferAsprintf(buf, "%s</virtualport>\n", indent);
virBufferAddLit(buf, "</virtualport>\n");
}
static int
......@@ -1074,11 +1070,14 @@ virBandwidthChildDefFormat(virBufferPtr buf,
virRatePtr def,
const char *elem_name)
{
if (!buf || !def || !elem_name)
if (!buf || !elem_name)
return -1;
if (!def)
return 0;
if (def->average) {
virBufferAsprintf(buf, "<%s average='%llu'", elem_name, def->average);
virBufferAsprintf(buf, " <%s average='%llu'", elem_name,
def->average);
if (def->peak)
virBufferAsprintf(buf, " peak='%llu'", def->peak);
......@@ -1095,17 +1094,15 @@ virBandwidthChildDefFormat(virBufferPtr buf,
* virBandwidthDefFormat:
* @buf: Buffer to print to
* @def: Data source
* @indent: prepend all lines printed with this
*
* 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.
*/
int
virBandwidthDefFormat(virBufferPtr buf,
virBandwidthPtr def,
const char *indent)
virBandwidthPtr def)
{
int ret = -1;
......@@ -1117,23 +1114,11 @@ virBandwidthDefFormat(virBufferPtr buf,
goto cleanup;
}
if (!indent)
indent = "";
virBufferAsprintf(buf, "%s<bandwidth>\n", indent);
if (def->in) {
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);
virBufferAddLit(buf, "<bandwidth>\n");
if (virBandwidthChildDefFormat(buf, def->in, "inbound") < 0 ||
virBandwidthChildDefFormat(buf, def->out, "outbound") < 0)
goto cleanup;
virBufferAddLit(buf, "</bandwidth>\n");
ret = 0;
......
/*
* 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
*
......@@ -147,16 +147,15 @@ virVirtualPortProfileParseXML(xmlNodePtr node,
virVirtualPortProfileParamsPtr *virtPort);
void
virVirtualPortProfileFormat(virBufferPtr buf,
virVirtualPortProfileParamsPtr virtPort,
const char *indent);
virVirtualPortProfileParamsPtr virtPort);
bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, virVirtualPortProfileParamsPtr b);
bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a,
virVirtualPortProfileParamsPtr b);
virBandwidthPtr virBandwidthDefParseNode(xmlNodePtr node);
void virBandwidthDefFree(virBandwidthPtr def);
int virBandwidthDefFormat(virBufferPtr buf,
virBandwidthPtr def,
const char *indent);
virBandwidthPtr def);
int virBandwidthEnable(virBandwidthPtr bandwidth, const char *iface);
int virBandwidthDisable(const char *iface, bool may_fail);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册