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

[libvirt] [PATCH 6/6] normalize_xml: New virsh command to normalize device XML



The command here is just to demo the effect of the API and for
one wants to play with it, it's not much useful as a virsh command
IMO, so it's not for final commit.
---
 tools/virsh.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index e4b812e..0b15c46 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -6050,6 +6050,54 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
 }
 
 /*
+ * "normalize-device-xml" command
+ */
+static const vshCmdInfo info_normalize_device_xml[] = {
+    {"help", N_("normalize the incoming device XML")},
+    {"desc", N_("Output the normalized device XML.")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_normalize_device_xml[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+    {"file",   VSH_OT_DATA, VSH_OFLAG_REQ, N_("Device XML file")},
+    {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdNormalizeDeviceXML(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    const char *xmlfile = NULL;
+    bool ret = false;
+    char *buffer = NULL;
+    char *output = NULL;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return false;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if (vshCommandOptString(cmd, "file", &xmlfile) <= 0)
+        return false;
+
+    if (virFileReadAll(xmlfile, VIRSH_MAX_XML_FILE, &buffer) < 0)
+        return false;
+
+    output = virDomainNormalizeDeviceXML(dom, buffer, 0);
+    if (output) {
+        vshPrint(ctl, "%s", output);
+        VIR_FREE(output);
+        ret = true;
+    }
+
+    VIR_FREE(buffer);
+    virDomainFree(dom);
+    return ret;
+}
+
+/*
  * "domxml-from-native" command
  */
 static const vshCmdInfo info_domxmlfromnative[] = {
@@ -15812,6 +15860,8 @@ static const vshCmdDef domManagementCmds[] = {
      opts_migrate_setspeed, info_migrate_setspeed, 0},
     {"migrate-getspeed", cmdMigrateGetMaxSpeed,
      opts_migrate_getspeed, info_migrate_getspeed, 0},
+    {"normalize-device-xml", cmdNormalizeDeviceXML,
+     opts_normalize_device_xml, info_normalize_device_xml, 0},
     {"numatune", cmdNumatune, opts_numatune, info_numatune, 0},
     {"reboot", cmdReboot, opts_reboot, info_reboot, 0},
     {"reset", cmdReset, opts_reset, info_reset, 0},
-- 
1.7.7.3


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