Support reporting live interface IP/netmask

This patch adds the flag VIR_INTERFACE_XML_INACTIVE to
virInterfaceGetXMLDesc's flags. When it is*not* set (the default), the
live interface info will be returned in the XML (in particular, the IP
address(es) and netmask(s) will be retrieved by querying the interface
directly, rather than  reporting what's in the config file). The
backend of this is in netcf's ncf_if_xml_state() function.

* configure.in libvirt.spec.in: requires netcf >= 0.1.3
* include/libvirt/libvirt.h.in: adds flag VIR_INTERFACE_XML_INACTIVE
* src/conf/interface_conf.c src/interface/netcf_driver.c src/libvirt.c:
  update the parsing and backend routines accordingly
* tools/virsh.c: change interface edit to inactive definition and
  adds the inactive flag for interface dump
This commit is contained in:
Laine Stump 2009-10-28 10:40:54 +01:00 committed by Daniel Veillard
parent ef591ef7b9
commit 753c6c9c75
7 changed files with 55 additions and 39 deletions

View File

@ -33,7 +33,7 @@ GNUTLS_REQUIRED="1.0.25"
AVAHI_REQUIRED="0.6.0" AVAHI_REQUIRED="0.6.0"
POLKIT_REQUIRED="0.6" POLKIT_REQUIRED="0.6"
PARTED_REQUIRED="1.8.0" PARTED_REQUIRED="1.8.0"
NETCF_REQUIRED="0.0.1" NETCF_REQUIRED="0.1.3"
dnl Checks for C compiler. dnl Checks for C compiler.
AC_PROG_CC AC_PROG_CC

View File

@ -930,6 +930,10 @@ virInterfacePtr virInterfaceLookupByMACString (virConnectPtr conn,
const char* virInterfaceGetName (virInterfacePtr iface); const char* virInterfaceGetName (virInterfacePtr iface);
const char* virInterfaceGetMACString (virInterfacePtr iface); const char* virInterfaceGetMACString (virInterfacePtr iface);
typedef enum {
VIR_INTERFACE_XML_INACTIVE = 1 /* dump inactive interface information */
} virInterfaceXMLFlags;
char * virInterfaceGetXMLDesc (virInterfacePtr iface, char * virInterfaceGetXMLDesc (virInterfacePtr iface,
unsigned int flags); unsigned int flags);
virInterfacePtr virInterfaceDefineXML (virConnectPtr conn, virInterfacePtr virInterfaceDefineXML (virConnectPtr conn,

View File

@ -308,7 +308,7 @@ BuildRequires: libcap-ng-devel >= 0.5.0
BuildRequires: libssh2-devel BuildRequires: libssh2-devel
%endif %endif
%if %{with_netcf} %if %{with_netcf}
BuildRequires: netcf-devel BuildRequires: netcf-devel >= 0.1.3
%endif %endif
# Fedora build root suckage # Fedora build root suckage

View File

@ -279,22 +279,19 @@ virInterfaceDefParseIp(virConnectPtr conn, virInterfaceDefPtr def,
static int static int
virInterfaceDefParseProtoIPv4(virConnectPtr conn, virInterfaceDefPtr def, virInterfaceDefParseProtoIPv4(virConnectPtr conn, virInterfaceDefPtr def,
xmlXPathContextPtr ctxt) { xmlXPathContextPtr ctxt) {
xmlNodePtr cur; xmlNodePtr dhcp, ip;
int ret; int ret = 0;
cur = virXPathNode(conn, "./dhcp", ctxt); dhcp = virXPathNode(conn, "./dhcp", ctxt);
if (cur != NULL) if (dhcp != NULL)
ret = virInterfaceDefParseDhcp(conn, def, cur, ctxt); ret = virInterfaceDefParseDhcp(conn, def, dhcp, ctxt);
else {
cur = virXPathNode(conn, "./ip", ctxt); if (ret != 0)
if (cur != NULL) return(ret);
ret = virInterfaceDefParseIp(conn, def, cur, ctxt);
else { ip = virXPathNode(conn, "./ip", ctxt);
virInterfaceReportError(conn, VIR_ERR_XML_ERROR, if (ip != NULL)
"%s", _("interface miss dhcp or ip adressing")); ret = virInterfaceDefParseIp(conn, def, ip, ctxt);
ret = -1;
}
}
return(ret); return(ret);
} }
@ -1012,20 +1009,18 @@ virInterfaceProtocolDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED,
virBufferAddLit(buf, " <dhcp peerdns='yes'/>\n"); virBufferAddLit(buf, " <dhcp peerdns='yes'/>\n");
else else
virBufferAddLit(buf, " <dhcp/>\n"); virBufferAddLit(buf, " <dhcp/>\n");
} else { }
/* theorically if we don't have dhcp we should have an address */ if (def->proto.address != NULL) {
if (def->proto.address != NULL) { if (def->proto.prefix != 0)
if (def->proto.prefix != 0) virBufferVSprintf(buf, " <ip address='%s' prefix='%d'/>\n",
virBufferVSprintf(buf, " <ip address='%s' prefix='%d'/>\n", def->proto.address, def->proto.prefix);
def->proto.address, def->proto.prefix); else
else virBufferVSprintf(buf, " <ip address='%s'/>\n",
virBufferVSprintf(buf, " <ip address='%s'/>\n", def->proto.address);
def->proto.address); }
} if (def->proto.gateway != NULL) {
if (def->proto.gateway != NULL) { virBufferVSprintf(buf, " <route gateway='%s'/>\n",
virBufferVSprintf(buf, " <route gateway='%s'/>\n", def->proto.gateway);
def->proto.gateway);
}
} }
virBufferAddLit(buf, " </protocol>\n"); virBufferAddLit(buf, " </protocol>\n");
return(0); return(0);

View File

@ -326,7 +326,7 @@ cleanup:
} }
static char *interfaceGetXMLDesc(virInterfacePtr ifinfo, static char *interfaceGetXMLDesc(virInterfacePtr ifinfo,
unsigned int flags ATTRIBUTE_UNUSED) unsigned int flags)
{ {
struct interface_driver *driver = ifinfo->conn->interfacePrivateData; struct interface_driver *driver = ifinfo->conn->interfacePrivateData;
struct netcf_if *iface = NULL; struct netcf_if *iface = NULL;
@ -342,7 +342,11 @@ static char *interfaceGetXMLDesc(virInterfacePtr ifinfo,
goto cleanup; goto cleanup;
} }
xmlstr = ncf_if_xml_desc(iface); if ((flags & VIR_INTERFACE_XML_INACTIVE)) {
xmlstr = ncf_if_xml_desc(iface);
} else {
xmlstr = ncf_if_xml_state(iface);
}
if (!xmlstr) { if (!xmlstr) {
const char *errmsg, *details; const char *errmsg, *details;
int errcode = ncf_error(driver->netcf, &errmsg, &details); int errcode = ncf_error(driver->netcf, &errmsg, &details);

View File

@ -6201,10 +6201,17 @@ virInterfaceGetMACString(virInterfacePtr iface)
/** /**
* virInterfaceGetXMLDesc: * virInterfaceGetXMLDesc:
* @iface: an interface object * @iface: an interface object
* @flags: an OR'ed set of extraction flags, not used yet * @flags: an OR'ed set of extraction flags. Current valid bits:
* *
* Provide an XML description of the interface. The description may be reused * VIR_INTERFACE_XML_INACTIVE - return the static configuration,
* later to redefine the interface with virInterfaceDefineXML(). * suitable for use redefining the
* interface via virInterfaceDefineXML()
*
* Provide an XML description of the interface. If
* VIR_INTERFACE_XML_INACTIVE is set, the description may be reused
* later to redefine the interface with virInterfaceDefineXML(). If it
* is not set, the ip address and netmask will be the current live
* setting of the interface, not the settings from the config files.
* *
* Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error. * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
* the caller must free() the returned value. * the caller must free() the returned value.
@ -6221,7 +6228,7 @@ virInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags)
virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__); virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
return (NULL); return (NULL);
} }
if (flags != 0) { if ((flags & ~VIR_INTERFACE_XML_INACTIVE) != 0) {
virLibInterfaceError(iface, VIR_ERR_INVALID_ARG, __FUNCTION__); virLibInterfaceError(iface, VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error; goto error;
} }

View File

@ -2792,7 +2792,7 @@ cmdInterfaceEdit (vshControl *ctl, const vshCmd *cmd)
char *doc = NULL; char *doc = NULL;
char *doc_edited = NULL; char *doc_edited = NULL;
char *doc_reread = NULL; char *doc_reread = NULL;
int flags = 0; int flags = VIR_INTERFACE_XML_INACTIVE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup; goto cleanup;
@ -3326,6 +3326,7 @@ static const vshCmdInfo info_interface_dumpxml[] = {
static const vshCmdOptDef opts_interface_dumpxml[] = { static const vshCmdOptDef opts_interface_dumpxml[] = {
{"interface", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("interface name or MAC address")}, {"interface", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("interface name or MAC address")},
{"inactive", VSH_OT_BOOL, 0, gettext_noop("show inactive defined XML")},
{NULL, 0, 0, NULL} {NULL, 0, 0, NULL}
}; };
@ -3335,6 +3336,11 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
virInterfacePtr iface; virInterfacePtr iface;
int ret = TRUE; int ret = TRUE;
char *dump; char *dump;
int flags = 0;
int inactive = vshCommandOptBool(cmd, "inactive");
if (inactive)
flags |= VIR_INTERFACE_XML_INACTIVE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
@ -3342,7 +3348,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
if (!(iface = vshCommandOptInterface(ctl, cmd, NULL))) if (!(iface = vshCommandOptInterface(ctl, cmd, NULL)))
return FALSE; return FALSE;
dump = virInterfaceGetXMLDesc(iface, 0); dump = virInterfaceGetXMLDesc(iface, flags);
if (dump != NULL) { if (dump != NULL) {
printf("%s", dump); printf("%s", dump);
free(dump); free(dump);