Re: [libvirt] PATCH: 11/12: virsh support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds two node virsh commands for the node device enumeration
APIs. The only change here is to change the command names to have a shorter
prefix,  nodedev-list and nodedev-dumpxml

Daniel

diff -r 0136f215fc06 src/virsh.c
--- a/src/virsh.c	Thu Nov 13 13:06:59 2008 +0000
+++ b/src/virsh.c	Thu Nov 13 13:07:59 2008 +0000
@@ -4410,6 +4410,96 @@
         vshPrint(ctl, _("Running hypervisor: %s %d.%d.%d\n"),
                  hvType, major, minor, rel);
     }
+    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 = cap ? virNodeNumOfDevicesByCap(ctl->conn, cap, 0) :
+        virNodeNumOfDevices(ctl->conn, 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 = cap ?
+        virNodeListDevicesByCap(ctl->conn, cap, devices, num_devices, 0) :
+        virNodeListDevices(ctl->conn, 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;
 }
 
@@ -5565,6 +5655,9 @@
     {"net-uuid", cmdNetworkUuid, opts_network_uuid, info_network_uuid},
     {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo},
 
+    {"node-list-devices", cmdNodeListDevices, opts_node_list_devices, info_node_list_devices},
+    {"node-device-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},

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]