interface: report link state for bonds and vlans too

The interface state for bonds and vlans does seem to reflect the state
of the underlying physical devices, at least in some cases, so it
makes sense to allow reporting it (netcf now does).

The link state/speed for bridge devices is meaningless though, so we
don't even look for it.
This commit is contained in:
Laine Stump 2014-06-13 17:07:05 +03:00
parent c8e4220515
commit 69db5f921a
4 changed files with 16 additions and 6 deletions

View File

@ -78,6 +78,7 @@
of the form DEVICE.VLAN
-->
<optional><ref name="name-attr"/></optional>
<ref name="link-speed-state"/>
</define>
<define name="vlan-device">
@ -156,6 +157,7 @@
<value>bond</value>
</attribute>
<ref name="name-attr"/>
<ref name="link-speed-state"/>
</define>
<define name="bond-element">

View File

@ -669,6 +669,8 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
int type;
char *tmp;
xmlNodePtr cur = ctxt->node;
xmlNodePtr lnk;
/* check @type */
tmp = virXPathString("string(./@type)", ctxt);
@ -704,20 +706,22 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
goto error;
}
def->type = type;
if (type != VIR_INTERFACE_TYPE_BRIDGE) {
/* link status makes no sense for a bridge */
lnk = virXPathNode("./link", ctxt);
if (lnk && virInterfaceLinkParseXML(lnk, &def->lnk) < 0)
goto error;
}
switch (type) {
case VIR_INTERFACE_TYPE_ETHERNET: {
xmlNodePtr lnk;
if (virInterfaceDefParseName(def, ctxt) < 0)
goto error;
tmp = virXPathString("string(./mac/@address)", ctxt);
if (tmp != NULL)
def->mac = tmp;
lnk = virXPathNode("./link", ctxt);
if (lnk && virInterfaceLinkParseXML(lnk, &def->lnk) < 0)
goto error;
if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
/* only recognize these in toplevel bond interfaces */
if (virInterfaceDefParseStartMode(def, ctxt) < 0)
@ -1110,6 +1114,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def)
break;
case VIR_INTERFACE_TYPE_BOND:
virInterfaceStartmodeDefFormat(buf, def->startmode);
virInterfaceLinkFormat(buf, &def->lnk);
if (def->mtu != 0)
virBufferAsprintf(buf, "<mtu size='%d'/>\n", def->mtu);
virInterfaceProtocolDefFormat(buf, def);
@ -1119,6 +1124,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def)
virInterfaceStartmodeDefFormat(buf, def->startmode);
if (def->mac != NULL)
virBufferAsprintf(buf, "<mac address='%s'/>\n", def->mac);
virInterfaceLinkFormat(buf, &def->lnk);
if (def->mtu != 0)
virBufferAsprintf(buf, "<mtu size='%d'/>\n", def->mtu);
virInterfaceProtocolDefFormat(buf, def);

View File

@ -1,5 +1,6 @@
<interface type='bond' name='bond0'>
<start mode='none'/>
<link speed='1000' state='up'/>
<protocol family='ipv4'>
<ip address='192.168.50.7' prefix='24'/>
<route gateway='192.168.50.1'/>

View File

@ -1,5 +1,6 @@
<interface type='vlan' name='eth0.42'>
<start mode='onboot'/>
<link state='lowerlayerdown'/>
<protocol family='ipv4'>
<dhcp peerdns='no'/>
</protocol>