]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Teach vol-create-as to --print-xml
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 10 Feb 2016 15:48:15 +0000 (16:48 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 12 Feb 2016 15:16:09 +0000 (16:16 +0100)
We have the same argument to many other commands that produce an
XML based on what user typed. But unfortunately vol-create-as
was missing it. Maybe nobody had needed it yet. Well, I did
just now.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-volume.c
tools/virsh.pod

index 569f55578acfcf3e0e230c65a098be9acbfec4d7..cfb8cfceddcbaa1ab3a0c9a876103053bd6c27db 100644 (file)
@@ -195,6 +195,10 @@ static const vshCmdOptDef opts_vol_create_as[] = {
      .type = VSH_OT_BOOL,
      .help = N_("preallocate metadata (for qcow2 instead of full allocation)")
     },
+    {.name = "print-xml",
+     .type = VSH_OT_BOOL,
+     .help = N_("print XML document, but don't define/create")
+    },
     {.name = NULL}
 };
 
@@ -213,6 +217,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
     virStoragePoolPtr pool;
     virStorageVolPtr vol = NULL;
     char *xml = NULL;
+    bool printXML = vshCommandOptBool(cmd, "print-xml");
     const char *name, *capacityStr = NULL, *allocationStr = NULL, *format = NULL;
     const char *snapshotStrVol = NULL, *snapshotStrFormat = NULL;
     unsigned long long capacity, allocation = 0;
@@ -337,12 +342,16 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
     }
     xml = virBufferContentAndReset(&buf);
 
-    if (!(vol = virStorageVolCreateXML(pool, xml, flags))) {
-        vshError(ctl, _("Failed to create vol %s"), name);
-        goto cleanup;
+    if (printXML) {
+        vshPrint(ctl, "%s", xml);
+    } else {
+        if (!(vol = virStorageVolCreateXML(pool, xml, flags))) {
+            vshError(ctl, _("Failed to create vol %s"), name);
+            goto cleanup;
+        }
+        vshPrint(ctl, _("Vol %s created\n"), name);
     }
 
-    vshPrint(ctl, _("Vol %s created\n"), name);
     ret = true;
 
  cleanup:
index 435c64907e43bc167f92c22e00f876b2ef3b35d4..466265889310e8bb26701bc23effa9b739c1476b 100644 (file)
@@ -3427,9 +3427,11 @@ If this is not possible, the copy fails.
 =item B<vol-create-as> I<pool-or-uuid> I<name> I<capacity>
 [I<--allocation> I<size>] [I<--format> I<string>] [I<--backing-vol>
 I<vol-name-or-key-or-path>] [I<--backing-vol-format> I<string>]
-[I<--prealloc-metadata>]
+[I<--prealloc-metadata>] [I<--print-xml>]
 
-Create a volume from a set of arguments.
+Create a volume from a set of arguments unless I<--print-xml> is specified, in
+which case just the XML of the volume object is printed out without any actual
+object creation.
 I<pool-or-uuid> is the name or UUID of the storage pool to create the volume
 in.
 I<name> is the name of the new volume. For a disk pool, this must match the