]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Implement managedsave-define command
authorKothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
Tue, 8 Aug 2017 08:02:53 +0000 (13:32 +0530)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 29 Aug 2017 11:40:13 +0000 (13:40 +0200)
Add a simple virsh command handler which makes use of the new API.

Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
tools/virsh-domain.c
tools/virsh.pod

index a3410e791c536aa8bc6a0efa1ef1a02394ab931b..8f048f678ac244594441cf802cca4db4bd7a8828 100644 (file)
@@ -4704,6 +4704,78 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd)
     return ret;
 }
 
+/*
+ * "managedsave-define" command
+ */
+static const vshCmdInfo info_managed_save_define[] = {
+    {.name = "help",
+     .data = N_("redefine the XML for a domain's managed save state file")
+    },
+    {.name = "desc",
+     .data = N_("Replace the domain XML associated with a managed save state file")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_managed_save_define[] = {
+    VIRSH_COMMON_OPT_DOMAIN_FULL,
+    {.name = "xml",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("filename containing updated XML for the target")
+    },
+    {.name = "running",
+     .type = VSH_OT_BOOL,
+     .help = N_("set domain to be running on start")
+    },
+    {.name = "paused",
+     .type = VSH_OT_BOOL,
+     .help = N_("set domain to be paused on start")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd)
+{
+    bool ret = false;
+    virDomainPtr dom = NULL;
+    const char *xmlfile = NULL;
+    char *xml = NULL;
+    unsigned int flags = 0;
+
+    if (vshCommandOptBool(cmd, "running"))
+        flags |= VIR_DOMAIN_SAVE_RUNNING;
+    if (vshCommandOptBool(cmd, "paused"))
+        flags |= VIR_DOMAIN_SAVE_PAUSED;
+
+    VSH_EXCLUSIVE_OPTIONS("running", "paused");
+
+    if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0)
+        return false;
+
+    if (virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
+        return false;
+
+    if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+        goto cleanup;
+
+    if (virDomainManagedSaveDefineXML(dom, xml, flags) < 0) {
+        vshError(ctl, _("Failed to update %s XML configuration"),
+                        virDomainGetName(dom));
+        goto cleanup;
+    }
+
+    vshPrintExtra(ctl, _("Managed save state file of domain %s updated.\n"),
+                         virDomainGetName(dom));
+    ret = true;
+
+ cleanup:
+    virshDomainFree(dom);
+    VIR_FREE(xml);
+    return ret;
+}
+
 /*
  * "schedinfo" command
  */
@@ -13886,6 +13958,12 @@ const vshCmdDef domManagementCmds[] = {
      .info = info_managedsaveremove,
      .flags = 0
     },
+    {.name = "managedsave-define",
+     .handler = cmdManagedSaveDefine,
+     .opts = opts_managed_save_define,
+     .info = info_managed_save_define,
+     .flags = 0
+    },
     {.name = "memtune",
      .handler = cmdMemtune,
      .opts = opts_memtune,
index 15a414399db4e7bb984e737e23d7b7fdef011e91..5c87af3026b416fb5b3de8db5ddffc2b2b58b832 100644 (file)
@@ -1630,6 +1630,18 @@ has any managed save image.
 Remove the B<managedsave> state file for a domain, if it exists.  This
 ensures the domain will do a full boot the next time it is started.
 
+=item B<managedsave-define> I<domain> I<xml> [{I<--running> | I<--paused>}]
+
+Update the domain XML that will be used when I<domain> is later
+started. The I<xml> argument must be a file name containing
+the alternative XML, with changes only in the host-specific portions of
+the domain XML. For example, it can be used to change disk file paths.
+
+The managed save image records whether the domain should be started to a
+running or paused state.  Normally, this command does not alter the
+recorded state; passing either the I<--running> or I<--paused> flag
+will allow overriding which state the B<start> should use.
+
 =item B<maxvcpus> [I<type>]
 
 Provide the maximum number of virtual CPUs supported for a guest VM on