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

[libvirt] [PATCH 9/9] Modify virsh commands



Change all virsh commands that invoke virDomain{Attach,Detach}Device()
to use virDomain{Attach,Detach}DeviceFlags() instead.

Add a "--persistent" flag to these virsh commands, allowing user to
specify that the domain persisted config be modified as well.
---
 tools/virsh.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 1fae5e6..a082b89 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -6285,6 +6285,7 @@ static const vshCmdInfo info_attach_device[] = {
 static const vshCmdOptDef opts_attach_device[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
     {"file",   VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("XML file")},
+    {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist device attachment")},
     {NULL, 0, 0, NULL}
 };
 
@@ -6296,6 +6297,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
     char *buffer;
     int ret = TRUE;
     int found;
+    int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
@@ -6309,13 +6311,18 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
         virDomainFree(dom);
         return FALSE;
     }
+    if (vshCommandOptBool(cmd, "persistent"))
+        flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
 
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
         virDomainFree(dom);
         return FALSE;
     }
 
-    ret = virDomainAttachDevice(dom, buffer);
+    if (virDomainIsActive(dom))
+       flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
+
+    ret = virDomainAttachDeviceFlags(dom, buffer, flags);
     VIR_FREE(buffer);
 
     if (ret < 0) {
@@ -6343,6 +6350,7 @@ static const vshCmdInfo info_detach_device[] = {
 static const vshCmdOptDef opts_detach_device[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
     {"file",   VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("XML file")},
+    {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist device detachment")},
     {NULL, 0, 0, NULL}
 };
 
@@ -6354,6 +6362,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
     char *buffer;
     int ret = TRUE;
     int found;
+    int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
@@ -6367,13 +6376,18 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
         virDomainFree(dom);
         return FALSE;
     }
+    if (vshCommandOptBool(cmd, "persistent"))
+        flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
 
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
         virDomainFree(dom);
         return FALSE;
     }
 
-    ret = virDomainDetachDevice(dom, buffer);
+    if (virDomainIsActive(dom))
+       flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
+
+    ret = virDomainDetachDeviceFlags(dom, buffer, flags);
     VIR_FREE(buffer);
 
     if (ret < 0) {
@@ -6405,6 +6419,7 @@ static const vshCmdOptDef opts_attach_interface[] = {
     {"target", VSH_OT_DATA, 0, gettext_noop("target network name")},
     {"mac",    VSH_OT_DATA, 0, gettext_noop("MAC address")},
     {"script", VSH_OT_DATA, 0, gettext_noop("script used to bridge network interface")},
+    {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist interface attachment")},
     {NULL, 0, 0, NULL}
 };
 
@@ -6415,6 +6430,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     char *mac, *target, *script, *type, *source;
     int typ, ret = FALSE;
     char *buf = NULL, *tmp = NULL;
+    int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         goto cleanup;
@@ -6429,6 +6445,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     target = vshCommandOptString(cmd, "target", NULL);
     mac = vshCommandOptString(cmd, "mac", NULL);
     script = vshCommandOptString(cmd, "script", NULL);
+    if (vshCommandOptBool(cmd, "persistent"))
+        flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
 
     /* check interface type */
     if (STREQ(type, "network")) {
@@ -6489,7 +6507,10 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     if (!buf) goto cleanup;
     strcat(buf, "    </interface>\n");
 
-    if (virDomainAttachDevice(dom, buf)) {
+    if (virDomainIsActive(dom))
+       flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
+
+    if (virDomainAttachDeviceFlags(dom, buf, flags)) {
         goto cleanup;
     } else {
         vshPrint(ctl, "%s", _("Interface attached successfully\n"));
@@ -6518,6 +6539,7 @@ static const vshCmdOptDef opts_detach_interface[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
     {"type",   VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("network interface type")},
     {"mac",    VSH_OT_STRING, 0, gettext_noop("MAC address")},
+    {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist interface detachment")},
     {NULL, 0, 0, NULL}
 };
 
@@ -6534,6 +6556,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
     char *doc, *mac =NULL, *type;
     char buf[64];
     int i = 0, diff_mac, ret = FALSE;
+    int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         goto cleanup;
@@ -6545,6 +6568,8 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
 
     mac = vshCommandOptString(cmd, "mac", NULL);
+    if (vshCommandOptBool(cmd, "persistent"))
+        flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
 
     doc = virDomainGetXMLDesc(dom, 0);
     if (!doc)
@@ -6605,7 +6630,10 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    ret = virDomainDetachDevice(dom, (char *)xmlBufferContent(xml_buf));
+    if (virDomainIsActive(dom))
+       flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
+
+    ret = virDomainDetachDeviceFlags(dom, (char *)xmlBufferContent(xml_buf), flags);
     if (ret != 0)
         ret = FALSE;
     else {
@@ -6642,6 +6670,7 @@ static const vshCmdOptDef opts_attach_disk[] = {
     {"subdriver", VSH_OT_STRING, 0, gettext_noop("subdriver of disk device")},
     {"type",    VSH_OT_STRING, 0, gettext_noop("target device type")},
     {"mode",    VSH_OT_STRING, 0, gettext_noop("mode of device reading and writing")},
+    {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist disk attachment")},
     {NULL, 0, 0, NULL}
 };
 
@@ -6652,6 +6681,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     char *source, *target, *driver, *subdriver, *type, *mode;
     int isFile = 0, ret = FALSE;
     char *buf = NULL, *tmp = NULL;
+    int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         goto cleanup;
@@ -6669,6 +6699,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     subdriver = vshCommandOptString(cmd, "subdriver", NULL);
     type = vshCommandOptString(cmd, "type", NULL);
     mode = vshCommandOptString(cmd, "mode", NULL);
+    if (vshCommandOptBool(cmd, "persistent"))
+        flags |=  VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
 
     if (driver) {
         if (STREQ(driver, "file") || STREQ(driver, "tap")) {
@@ -6767,7 +6799,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     if (!buf) goto cleanup;
     strcat(buf, "    </disk>\n");
 
-    if (virDomainAttachDevice(dom, buf))
+    if (virDomainIsActive(dom))
+       flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
+
+    if (virDomainAttachDeviceFlags(dom, buf, flags))
         goto cleanup;
     else
         vshPrint(ctl, "%s", _("Disk attached successfully\n"));
@@ -6794,6 +6829,7 @@ static const vshCmdInfo info_detach_disk[] = {
 static const vshCmdOptDef opts_detach_disk[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
     {"target", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("target of disk device")},
+    {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist disk detachment")},
     {NULL, 0, 0, NULL}
 };
 
@@ -6809,6 +6845,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom = NULL;
     char *doc, *target;
     int i = 0, diff_tgt, ret = FALSE;
+    int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         goto cleanup;
@@ -6819,6 +6856,9 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
     if (!(target = vshCommandOptString(cmd, "target", NULL)))
         goto cleanup;
 
+    if (vshCommandOptBool(cmd, "persistent"))
+        flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
+
     doc = virDomainGetXMLDesc(dom, 0);
     if (!doc)
         goto cleanup;
@@ -6874,7 +6914,10 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    ret = virDomainDetachDevice(dom, (char *)xmlBufferContent(xml_buf));
+    if (virDomainIsActive(dom))
+       flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
+
+    ret = virDomainDetachDeviceFlags(dom, (char *)xmlBufferContent(xml_buf), flags);
     if (ret != 0)
         ret = FALSE;
     else {
-- 
1.6.0.2


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