]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Add --print-xml flag for attach-disk command
authorPeter Krempa <pkrempa@redhat.com>
Fri, 25 Jan 2013 12:21:23 +0000 (13:21 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 25 Jan 2013 19:53:37 +0000 (20:53 +0100)
The flag causes the XML of the disk that would be attached to be printed
instead.

tools/virsh-domain.c
tools/virsh.pod

index 026dac10839bf3b57637f4e3c99e1f4d27cae737..004fac473462fc90e99b79e42374ed3b8eee868f 100644 (file)
@@ -317,6 +317,12 @@ static const vshCmdOptDef opts_attach_disk[] = {
      .flags = 0,
      .help = N_("use multifunction pci under specified address")
     },
+    {.name = "print-xml",
+     .type = VSH_OT_BOOL,
+     .flags = 0,
+     .help = N_("print XML document rather than attach the disk")
+    },
+
     {.name = NULL}
 };
 
@@ -480,11 +486,11 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     unsigned int flags;
     const char *stype = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
-    char *xml;
+    char *xml = NULL;
     struct stat st;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
-        goto cleanup;
+        return false;
 
     if (vshCommandOptString(cmd, "source", &source) <= 0)
         goto cleanup;
@@ -620,6 +626,12 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
 
     xml = virBufferContentAndReset(&buf);
 
+    if (vshCommandOptBool(cmd, "print-xml")) {
+        vshPrint(ctl, "%s", xml);
+        functionReturn = true;
+        goto cleanup;
+    }
+
     if (vshCommandOptBool(cmd, "config")) {
         flags = VIR_DOMAIN_AFFECT_CONFIG;
         if (virDomainIsActive(dom) == 1)
@@ -629,8 +641,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
         ret = virDomainAttachDevice(dom, xml);
     }
 
-    VIR_FREE(xml);
-
     if (ret != 0) {
         vshError(ctl, "%s", _("Failed to attach disk"));
     } else {
@@ -639,8 +649,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     }
 
  cleanup:
-    if (dom)
-        virDomainFree(dom);
+    VIR_FREE(xml);
+    virDomainFree(dom);
     virBufferFreeAndReset(&buf);
     return functionReturn;
 }
index e2a2aeca9518480e518fdc73517c61a70ceaef7f..fd0f762abb8dd2a59bb34cfb9552c991e4fad8d3 100644 (file)
@@ -1787,7 +1787,7 @@ needed if the device does not use managed mode.
 [I<--driver driver>] [I<--subdriver subdriver>] [I<--cache cache>]
 [I<--type type>] [I<--mode mode>] [I<--config>] [I<--sourcetype soucetype>]
 [I<--serial serial>] [I<--shareable>] [I<--rawio>] [I<--address address>]
-[I<--multifunction>]
+[I<--multifunction>] [I<--print-xml>]
 
 Attach a new disk device to the domain.
 I<source> is path for the files and devices. I<target> controls the bus or
@@ -1817,6 +1817,9 @@ scsi:controller.bus.unit or ide:controller.bus.unit.
 I<multifunction> indicates specified pci address is a multifunction pci device
 address.
 
+If I<--print-xml> is specified, then the XML of the disk that would be attached
+is printed instead.
+
 =item B<attach-interface> I<domain> I<type> I<source>
 [I<--target target>] [I<--mac mac>] [I<--script script>] [I<--model model>]
 [I<--config>] [I<--inbound average,peak,burst>] [I<--outbound average,peak,burst>]