0008-Step-8-of-8-Add-virsh-support.patch 4.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
From 193cc4abbb6c2fc5557d3699f86ff0103d5a21ef Mon Sep 17 00:00:00 2001
From: David Allan <dallan@redhat.com>
Date: Tue, 19 May 2009 16:47:31 -0400
Subject: [PATCH 8/8] Step 8 of 8 Add virsh support

---
 src/virsh.c |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 103 insertions(+), 0 deletions(-)

diff --git a/src/virsh.c b/src/virsh.c
index cb32ede..ab2a2b7 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -2962,6 +2962,107 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
 
 
 /*
+ * "nodedev-create" command
+ */
+static const vshCmdInfo info_node_device_create[] = {
+    {"help", gettext_noop("create a device defined "
+                          "by an XML file on the node")},
+    {"desc", gettext_noop("Create a device on the node.  Note that this "
+                          "command creates devices on the physical host "
+                          "that can then be assigned to a virtual machine.")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_node_device_create[] = {
+    {"file", VSH_OT_DATA, VSH_OFLAG_REQ,
+     gettext_noop("file containing an XML description of the device")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
+{
+    virNodeDevicePtr dev = NULL;
+    char *from;
+    int found = 0;
+    int ret = TRUE;
+    char *buffer;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    from = vshCommandOptString(cmd, "file", &found);
+    if (!found) {
+        return FALSE;
+    }
+
+    if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+        return FALSE;
+    }
+
+    dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0);
+    free (buffer);
+
+    if (dev != NULL) {
+        vshPrint(ctl, _("Node device %s created from %s\n"),
+                 virNodeDeviceGetName(dev), from);
+    } else {
+        vshError(ctl, FALSE, _("Failed to create node device from %s"), from);
+        ret = FALSE;
+    }
+
+    return ret;
+}
+
+
+/*
+ * "nodedev-destroy" command
+ */
+static const vshCmdInfo info_node_device_destroy[] = {
+    {"help", gettext_noop("destroy a device on the node")},
+    {"desc", gettext_noop("Destroy a device on the node.  Note that this "
+                          "command destroys devices on the physical host ")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_node_device_destroy[] = {
+    {"name", VSH_OT_DATA, VSH_OFLAG_REQ,
+     gettext_noop("name of the device to be destroyed")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
+{
+    virNodeDevicePtr dev = NULL;
+    int ret = TRUE;
+    int found = 0;
+    char *name;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) {
+        return FALSE;
+    }
+
+    name = vshCommandOptString(cmd, "name", &found);
+    if (!found) {
+        return FALSE;
+    }
+
+    dev = virNodeDeviceLookupByName(ctl->conn, name);
+
+    if (virNodeDeviceDestroy(dev) == 0) {
+        vshPrint(ctl, _("Destroyed node device '%s'\n"), name);
+    } else {
+        vshError(ctl, FALSE, _("Failed to destroy node device '%s'"), name);
+        ret = FALSE;
+    }
+
+    virNodeDeviceFree(dev);
+    return ret;
+}
+
+
+/*
  * XML Building helper for pool-define-as and pool-create-as
  */
 static const vshCmdOptDef opts_pool_X_as[] = {
@@ -5895,6 +5996,8 @@ static const vshCmdDef commands[] = {
     {"nodedev-dettach", cmdNodeDeviceDettach, opts_node_device_dettach, info_node_device_dettach},
     {"nodedev-reattach", cmdNodeDeviceReAttach, opts_node_device_reattach, info_node_device_reattach},
     {"nodedev-reset", cmdNodeDeviceReset, opts_node_device_reset, info_node_device_reset},
+    {"nodedev-create", cmdNodeDeviceCreate, opts_node_device_create, info_node_device_create},
+    {"nodedev-destroy", cmdNodeDeviceDestroy, opts_node_device_destroy, info_node_device_destroy},
 
     {"pool-autostart", cmdPoolAutostart, opts_pool_autostart, info_pool_autostart},
     {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build},
-- 
1.6.0.6