Add a simple virsh command handler which makes use of the new API.
Signed-off-by: Kothapally Madhu Pavan <kmp(a)linux.vnet.ibm.com>
---
tools/virsh-domain.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 21 +++++++++++++++
2 files changed, 93 insertions(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 874cf49..12721e7 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4705,6 +4705,72 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd)
}
/*
+ * "managedsave-edit" command
+ */
+static const vshCmdInfo info_managed_save_edit[] = {
+ {.name = "help",
+ .data = N_("edit XML for a domain's managed save state file")
+ },
+ {.name = "desc",
+ .data = N_("Edit the domain XML associated with the managed save state
file")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_managed_save_edit[] = {
+ VIRSH_COMMON_OPT_DOMAIN_FULL,
+ {.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
+cmdManagedSaveEdit(vshControl *ctl, const vshCmd *cmd)
+{
+ bool ret = false;
+ virDomainPtr dom = NULL;
+ unsigned int getxml_flags = VIR_DOMAIN_XML_SECURE;
+ unsigned int define_flags = 0;
+
+ if (vshCommandOptBool(cmd, "running"))
+ define_flags |= VIR_DOMAIN_SAVE_RUNNING;
+ if (vshCommandOptBool(cmd, "paused"))
+ define_flags |= VIR_DOMAIN_SAVE_PAUSED;
+
+ VSH_EXCLUSIVE_OPTIONS("running", "paused");
+
+ dom = virshCommandOptDomain(ctl, cmd, NULL);
+ if (dom == NULL)
+ goto cleanup;
+
+#define EDIT_GET_XML virDomainManagedSaveGetXMLDesc(dom, getxml_flags)
+#define EDIT_NOT_CHANGED \
+ do { \
+ vshPrintExtra(ctl, _("Managed save image of domain %s XML configuration
" \
+ "not changed.\n"), virDomainGetName(dom));
\
+ ret = true; \
+ goto edit_cleanup; \
+ } while (0)
+#define EDIT_DEFINE \
+ (virDomainManagedSaveDefineXML(dom, doc_edited, define_flags) == 0)
+#include "virsh-edit.c"
+
+ vshPrintExtra(ctl, _("Managed save image of Domain %s XML configuration
edited.\n"),
+ virDomainGetName(dom));
+ ret = true;
+
+ cleanup:
+ virshDomainFree(dom);
+ return ret;
+}
+
+/*
* "managedsave-dumpxml" command
*/
static const vshCmdInfo info_managed_save_dumpxml[] = {
@@ -13912,6 +13978,12 @@ const vshCmdDef domManagementCmds[] = {
.info = info_managedsaveremove,
.flags = 0
},
+ {.name = "managedsave-edit",
+ .handler = cmdManagedSaveEdit,
+ .opts = opts_managed_save_edit,
+ .info = info_managed_save_edit,
+ .flags = 0
+ },
{.name = "managedsave-dumpxml",
.handler = cmdManagedSaveDumpxml,
.opts = opts_managed_save_dumpxml,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index e93460e..639391a 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1644,6 +1644,27 @@ Extract the domain XML that was in effect at the time the saved
state
file I<file> was created with the B<managedsave> command. Using
I<--security-info> will also include security sensitive information.
+=item B<managedsave-edit> I<domain> [{I<--running> |
I<--paused>}]
+
+Edit the XML configuration associated with a saved state file of a
+I<domain> was created by the B<managedsave> command.
+
+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<restore> should use.
+
+This is equivalent to:
+
+ virsh managedsave-dumpxml domain-name > state-file.xml
+ vi state-file.xml (or make changes with your other text editor)
+ virsh managedsave-define domain-name state-file-xml
+
+except that it does some error checking.
+
+The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment
+variables, and defaults to C<vi>.
+
=item B<maxvcpus> [I<type>]
Provide the maximum number of virtual CPUs supported for a guest VM on
--
1.8.3.1