virsh: Implement managedsave-define 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:53 +05:30 committed by Peter Krempa
parent 021f7c132b
commit fc2c73b565
2 changed files with 90 additions and 0 deletions

View 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,

View 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