[PATCH 2/4] native: add virsh command domxml-formats

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

 



I've wanted this command for ages :)

* tools/virsh.c (cmdDomXMLFormats): New function.
* tools/virsh.pod (domxml-formats): Document it.
---
 tools/virsh.c   |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod |   11 +++++++++--
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index c511e2a..b1a0fb7 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -6268,6 +6268,52 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
 }

 /*
+ * "domxml-formats" command
+ */
+static const vshCmdInfo info_domxmlformats[] = {
+    {"help", N_("List native formats compatible with domain XML")},
+    {"desc",
+     N_("List the valid formats for domxml-to-native and domxml-from-native.")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_domxmlformats[] = {
+    {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdDomXMLFormats(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+{
+    bool ret = false;
+    unsigned int flags = 0;
+    char **formats = NULL;
+    int nformats = 0;
+    int i;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return false;
+
+    if ((nformats = virConnectDomainNativeFormats(ctl->conn, NULL, 0,
+                                                  flags)) < 0)
+        goto cleanup;
+
+    formats = vshCalloc(ctl, nformats, sizeof(*formats));
+    if ((nformats = virConnectDomainNativeFormats(ctl->conn, formats, nformats,
+                                                  flags)) < 0)
+        goto cleanup;
+
+    for (i = 0; i < nformats; i++)
+        vshPrint(ctl, "%s\n", formats[i]);
+    ret = true;
+
+cleanup:
+    for (i = 0; i < nformats; i++)
+        VIR_FREE(formats[i]);
+    VIR_FREE(formats);
+    return ret;
+}
+
+/*
  * "domname" command
  */
 static const vshCmdInfo info_domname[] = {
@@ -15930,6 +15976,8 @@ static const vshCmdDef domManagementCmds[] = {
     {"domjobinfo", cmdDomjobinfo, opts_domjobinfo, info_domjobinfo, 0},
     {"domname", cmdDomname, opts_domname, info_domname, 0},
     {"domuuid", cmdDomuuid, opts_domuuid, info_domuuid, 0},
+    {"domxml-formats", cmdDomXMLFormats, opts_domxmlformats,
+     info_domxmlformats, 0},
     {"domxml-from-native", cmdDomXMLFromNative, opts_domxmlfromnative,
      info_domxmlfromnative, 0},
     {"domxml-to-native", cmdDomXMLToNative, opts_domxmltonative,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index c88395b..19f93cf 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -624,19 +624,26 @@ Returns state of an interface to VMM used to control a domain.  For
 states other than "ok" or "error" the command also prints number of
 seconds elapsed since the control interface entered its current state.

+=item B<domxml-formats>
+
+List the valid formats for use by B<domxml-from-native> and
+B<domxml-to-native>.
+
 =item B<domxml-from-native> I<format> I<config>

 Convert the file I<config> in the native guest configuration format
 named by I<format> to a domain XML format. For QEMU/KVM hypervisor,
 the I<format> argument must be B<qemu-argv>. For Xen hypervisor, the
-I<format> argument may be B<xen-xm> or B<xen-sxpr>.
+I<format> argument may be B<xen-xm> or B<xen-sxpr>.  See also
+B<domxml-formats>.

 =item B<domxml-to-native> I<format> I<xml>

 Convert the file I<xml> in domain XML format to the native guest
 configuration format named by I<format>. For QEMU/KVM hypervisor,
 the I<format> argument must be B<qemu-argv>. For Xen hypervisor, the
-I<format> argument may be B<xen-xm> or B<xen-sxpr>.
+I<format> argument may be B<xen-xm> or B<xen-sxpr>.  See also
+B<domxml-formats>.

 =item B<dump> I<domain-id> I<corefilepath> [I<--bypass-cache>]
 { [I<--live>] | [I<--crash>] | [I<--reset>] } [I<--verbose>]
-- 
1.7.7.5

--
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]