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");
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;
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:
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;
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");
}
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]);
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) {
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,
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
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);
* 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;
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
*
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);