Creates XML output which looks like this:
<interfaces>
<interface name="ens2" type="ethernet">
<parameters>
<parameter name="bootproto">dhcp</parameter>
<parameter name="browser_only">0</parameter>
<parameter name="defroute">1</parameter>
<parameter name="ipv4_failure_fatal">0</parameter>
<parameter name="ipv6_autoconf">1</parameter>
<parameter name="ipv6_defroute">1</parameter>
<parameter name="ipv6_failure_fatal">0</parameter>
<parameter name="ipv6init">1</parameter>
<parameter name="netboot">1</parameter>
<parameter name="onboot">1</parameter>
<parameter name="proxy_method">none</parameter>
<parameter
name="uuid">b90eea1d-36df-4196-862c-8f10432bcbc7</parameter>
</parameters>
</interface>
<interface name="lo">
<parameters>
<parameter name="broadcast">127.255.255.255</parameter>
<parameter name="ipaddr">127.0.0.1</parameter>
<parameter name="netmask">255.0.0.0</parameter>
<parameter name="network">127.0.0.0</parameter>
<parameter name="onboot">1</parameter>
</parameters>
</interface>
</interfaces>
---
inspector/inspector.c | 81 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
diff --git a/inspector/inspector.c b/inspector/inspector.c
index 9be8f5110..066ed61bc 100644
--- a/inspector/inspector.c
+++ b/inspector/inspector.c
@@ -66,6 +66,7 @@ static void output_root (xmlTextWriterPtr xo, char *root);
static void output_mountpoints (xmlTextWriterPtr xo, char *root);
static void output_filesystems (xmlTextWriterPtr xo, char *root);
static void output_drive_mappings (xmlTextWriterPtr xo, char *root);
+static void output_interfaces (xmlTextWriterPtr xo, char *root);
static void output_applications (xmlTextWriterPtr xo, char *root);
static void do_xpath (const char *query);
@@ -463,6 +464,8 @@ output_root (xmlTextWriterPtr xo, char *root)
output_drive_mappings (xo, root);
+ output_interfaces (xo, root);
+
/* We need to mount everything up in order to read out the list of
* applications and the icon, ie. everything below this point.
*/
@@ -668,6 +671,84 @@ output_drive_mappings (xmlTextWriterPtr xo, char *root)
XMLERROR (-1, xmlTextWriterEndElement (xo));
}
+static int
+compare_if_name (const void *p1, const void *p2)
+{
+ const struct guestfs_interface *if1 = p1;
+ const struct guestfs_interface *if2 = p2;
+
+ return strcmp (if1->if_name, if2->if_name);
+}
+
+static void
+output_interfaces (xmlTextWriterPtr xo, char *root)
+{
+ CLEANUP_FREE_INTERFACE_LIST struct guestfs_interface_list *interfaces = NULL;
+ size_t i;
+
+ guestfs_push_error_handler (g, NULL, NULL);
+ interfaces = guestfs_inspect_get_interfaces (g, root);
+ guestfs_pop_error_handler (g);
+ if (interfaces == NULL || interfaces->len == 0)
+ return;
+
+ /* Sort by if_name. */
+ qsort (interfaces->val, interfaces->len, sizeof (struct guestfs_interface),
+ compare_if_name);
+
+ XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "interfaces"));
+
+ for (i = 0; i < interfaces->len; ++i) {
+ XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "interface"));
+ if (STRNEQ (interfaces->val[i].if_name, ""))
+ XMLERROR (-1,
+ xmlTextWriterWriteAttribute (xo, BAD_CAST "name",
+ BAD_CAST
+ interfaces->val[i].if_name));
+ if (STRNEQ (interfaces->val[i].if_type, ""))
+ XMLERROR (-1,
+ xmlTextWriterWriteAttribute (xo, BAD_CAST "type",
+ BAD_CAST
+ interfaces->val[i].if_type));
+ if (STRNEQ (interfaces->val[i].if_hwaddr, ""))
+ XMLERROR (-1,
+ xmlTextWriterWriteAttribute (xo, BAD_CAST "hwaddr",
+ BAD_CAST
+ interfaces->val[i].if_hwaddr));
+
+ /* Parameters. */
+ CLEANUP_FREE_STRING_LIST char **params =
+ guestfs_inspect_get_interface_parameters (g, root, (int) i);
+ size_t j;
+
+ if (params == NULL || params[0] == NULL)
+ goto noparams;
+
+ XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "parameters"));
+
+ /* Sort by key. */
+ qsort (params,
+ guestfs_int_count_strings (params) / 2, 2 * sizeof (char *),
+ compare_keys_nocase);
+
+ for (j = 0; params[j] != NULL; j += 2) {
+ XMLERROR (-1,
+ xmlTextWriterStartElement (xo, BAD_CAST "parameter"));
+ XMLERROR (-1,
+ xmlTextWriterWriteAttribute (xo, BAD_CAST "name",
+ BAD_CAST params[j]));
+ XMLERROR (-1, xmlTextWriterWriteString (xo, BAD_CAST params[j+1]));
+ XMLERROR (-1, xmlTextWriterEndElement (xo));
+ }
+
+ XMLERROR (-1, xmlTextWriterEndElement (xo));
+ noparams:
+ XMLERROR (-1, xmlTextWriterEndElement (xo));
+ }
+
+ XMLERROR (-1, xmlTextWriterEndElement (xo));
+}
+
static void
output_applications (xmlTextWriterPtr xo, char *root)
{
--
2.19.0.rc0