]> xenbits.xensource.com Git - libvirt.git/commitdiff
Node device support in virsh (David Lively)
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 21 Nov 2008 12:39:48 +0000 (12:39 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 21 Nov 2008 12:39:48 +0000 (12:39 +0000)
ChangeLog
src/virsh.c

index cb5f9588dffda01de9f192edc5f3a87dc5a2707a..9d90bec77fbf841498c74b1308f04799b1ec140c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Nov 21 12:38:14 BST 2008 Daniel P. Berrange <berrange@redhat.com>
+
+       Node device support in virsh (David Lively)
+       * src/virsh.c: Add nodedev-list and nodedev-dumpxml commands
+
 Fri Nov 21 12:30:14 BST 2008 Daniel P. Berrange <berrange@redhat.com>
 
        Remote protocol support for node devices (David Lively)
index 419578140cca6ef3a10eec637aec0a036dfd0b3e..193afba880c47a5a16478fc4cb81eab8962497f6 100644 (file)
@@ -4418,6 +4418,94 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     return TRUE;
 }
 
+/*
+ * "nodedev-list" command
+ */
+static const vshCmdInfo info_node_list_devices[] = {
+    {"syntax", "nodedev-list [--cap <capability>]"},
+    {"help", gettext_noop("enumerate devices on this host")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_node_list_devices[] = {
+    {"cap", VSH_OT_STRING, VSH_OFLAG_NONE, gettext_noop("capability name")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNodeListDevices (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+{
+    char *cap;
+    char **devices;
+    int found, num_devices, i;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    cap = vshCommandOptString(cmd, "cap", &found);
+    if (!found)
+        cap = NULL;
+
+    num_devices = virNodeNumOfDevices(ctl->conn, cap, 0);
+    if (num_devices < 0) {
+        vshError(ctl, FALSE, "%s", _("Failed to count node devices"));
+        return FALSE;
+    } else if (num_devices == 0) {
+        return TRUE;
+    }
+
+    devices = vshMalloc(ctl, sizeof(char *) * num_devices);
+    num_devices =
+        virNodeListDevices(ctl->conn, cap, devices, num_devices, 0);
+    if (num_devices < 0) {
+        vshError(ctl, FALSE, "%s", _("Failed to list node devices"));
+        free(devices);
+        return FALSE;
+    }
+    for (i = 0; i < num_devices; i++) {
+        vshPrint(ctl, "%s\n", devices[i]);
+        free(devices[i]);
+    }
+    free(devices);
+    return TRUE;
+}
+
+/*
+ * "nodedev-dumpxml" command
+ */
+static const vshCmdInfo info_node_device_dumpxml[] = {
+    {"syntax", "nodedev-dumpxml <device>"},
+    {"help", gettext_noop("node device details in XML")},
+    {"desc", gettext_noop("Output the node device details as an XML dump to stdout.")},
+    {NULL, NULL}
+};
+
+
+static const vshCmdOptDef opts_node_device_dumpxml[] = {
+    {"device", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("device key")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd)
+{
+    const char *name;
+    virNodeDevicePtr device;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+    if (!(name = vshCommandOptString(cmd, "device", NULL)))
+        return FALSE;
+    if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
+        vshError(ctl, FALSE, "%s '%s'", _("Could not find matching device"), name);
+        return FALSE;
+    }
+
+    vshPrint(ctl, "%s\n", virNodeDeviceGetXMLDesc(device, 0));
+    virNodeDeviceFree(device);
+    return TRUE;
+}
+
 /*
  * "hostkey" command
  */
@@ -5570,6 +5658,9 @@ static const vshCmdDef commands[] = {
     {"net-uuid", cmdNetworkUuid, opts_network_uuid, info_network_uuid},
     {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo},
 
+    {"nodedev-list", cmdNodeListDevices, opts_node_list_devices, info_node_list_devices},
+    {"nodedev-dumpxml", cmdNodeDeviceDumpXML, opts_node_device_dumpxml, info_node_device_dumpxml},
+
     {"pool-autostart", cmdPoolAutostart, opts_pool_autostart, info_pool_autostart},
     {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build},
     {"pool-create", cmdPoolCreate, opts_pool_create, info_pool_create},