virsh: Implement managedsave-edit command

Add a simple virsh command handler which makes use of the new API.

Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
This commit is contained in:
Kothapally Madhu Pavan 2017-08-08 13:32:55 +05:30 committed by Peter Krempa
parent c79697bbf4
commit 912bc7204f
2 changed files with 93 additions and 0 deletions

View File

@ -4704,6 +4704,72 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd)
return ret;
}
/*
* "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
*/
@ -14006,6 +14072,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,

View File

@ -1648,6 +1648,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