interface: clean up virInterfaceDefParseXML
the switch cases for the 4 different interface types had repetitive code which has now been pulled out as common. While touching those lines, some extra usage of "!= NULL" etc has been eliminated to make things more compact and inline with current coding practices. NB: parentIfType == VIR_INTERFACE_TYPE_LAST means that this is a toplevel interface (not a subordinate of a bridge or bond). Only toplevel interfaces can have a start mode, mtu, or IP address element.
This commit is contained in:
parent
7edc46ac26
commit
3aa8197393
@ -724,6 +724,19 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
|
|||||||
}
|
}
|
||||||
def->type = type;
|
def->type = type;
|
||||||
|
|
||||||
|
if (virInterfaceDefParseName(def, ctxt) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
|
||||||
|
/* only recognize these in toplevel bond interfaces */
|
||||||
|
if (virInterfaceDefParseStartMode(def, ctxt) < 0)
|
||||||
|
goto error;
|
||||||
|
if (virInterfaceDefParseMtu(def, ctxt) < 0)
|
||||||
|
goto error;
|
||||||
|
if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (type != VIR_INTERFACE_TYPE_BRIDGE) {
|
if (type != VIR_INTERFACE_TYPE_BRIDGE) {
|
||||||
/* link status makes no sense for a bridge */
|
/* link status makes no sense for a bridge */
|
||||||
lnk = virXPathNode("./link", ctxt);
|
lnk = virXPathNode("./link", ctxt);
|
||||||
@ -732,38 +745,14 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case VIR_INTERFACE_TYPE_ETHERNET: {
|
case VIR_INTERFACE_TYPE_ETHERNET:
|
||||||
if (virInterfaceDefParseName(def, ctxt) < 0)
|
if ((tmp = virXPathString("string(./mac/@address)", ctxt)))
|
||||||
goto error;
|
|
||||||
tmp = virXPathString("string(./mac/@address)", ctxt);
|
|
||||||
if (tmp != NULL)
|
|
||||||
def->mac = tmp;
|
def->mac = tmp;
|
||||||
|
|
||||||
if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
|
|
||||||
/* only recognize these in toplevel bond interfaces */
|
|
||||||
if (virInterfaceDefParseStartMode(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
if (virInterfaceDefParseMtu(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case VIR_INTERFACE_TYPE_BRIDGE: {
|
case VIR_INTERFACE_TYPE_BRIDGE: {
|
||||||
xmlNodePtr bridge;
|
xmlNodePtr bridge;
|
||||||
|
|
||||||
if (virInterfaceDefParseName(def, ctxt) < 0)
|
if (!(bridge = virXPathNode("./bridge[1]", ctxt))) {
|
||||||
goto error;
|
|
||||||
if (virInterfaceDefParseStartMode(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
if (virInterfaceDefParseMtu(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
bridge = virXPathNode("./bridge[1]", ctxt);
|
|
||||||
if (bridge == NULL) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
"%s", _("bridge interface misses the bridge element"));
|
"%s", _("bridge interface misses the bridge element"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -776,20 +765,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
|
|||||||
case VIR_INTERFACE_TYPE_BOND: {
|
case VIR_INTERFACE_TYPE_BOND: {
|
||||||
xmlNodePtr bond;
|
xmlNodePtr bond;
|
||||||
|
|
||||||
if (virInterfaceDefParseName(def, ctxt) < 0)
|
if (!(bond = virXPathNode("./bond[1]", ctxt))) {
|
||||||
goto error;
|
|
||||||
if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
|
|
||||||
/* only recognize these in toplevel bond interfaces */
|
|
||||||
if (virInterfaceDefParseStartMode(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
if (virInterfaceDefParseMtu(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
bond = virXPathNode("./bond[1]", ctxt);
|
|
||||||
if (bond == NULL) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
"%s", _("bond interface misses the bond element"));
|
"%s", _("bond interface misses the bond element"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -802,15 +778,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
|
|||||||
case VIR_INTERFACE_TYPE_VLAN: {
|
case VIR_INTERFACE_TYPE_VLAN: {
|
||||||
xmlNodePtr vlan;
|
xmlNodePtr vlan;
|
||||||
|
|
||||||
tmp = virXPathString("string(./@name)", ctxt);
|
if (!(vlan = virXPathNode("./vlan[1]", ctxt))) {
|
||||||
if (tmp != NULL)
|
|
||||||
def->name = tmp;
|
|
||||||
if (virInterfaceDefParseStartMode(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
|
|
||||||
goto error;
|
|
||||||
vlan = virXPathNode("./vlan[1]", ctxt);
|
|
||||||
if (vlan == NULL) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
"%s", _("vlan interface misses the vlan element"));
|
"%s", _("vlan interface misses the vlan element"));
|
||||||
goto error;
|
goto error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user