From 912bc7204fbda3f280c25ee142241d7666aaae6f Mon Sep 17 00:00:00 2001 From: Kothapally Madhu Pavan Date: Aug 29 2017 11:40:13 +0000 Subject: virsh: Implement managedsave-edit command Add a simple virsh command handler which makes use of the new API. Signed-off-by: Kothapally Madhu Pavan --- diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 14960c4..f235c66 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[] = { @@ -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, diff --git a/tools/virsh.pod b/tools/virsh.pod index f7b05f8..c13f96f 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1648,6 +1648,27 @@ Extract the domain XML that was in effect at the time the saved state file I was created with the B command. Using I<--security-info> will also include security sensitive information. +=item B I [{I<--running> | I<--paused>}] + +Edit the XML configuration associated with a saved state file of a +I was created by the B 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 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. + =item B [I] Provide the maximum number of virtual CPUs supported for a guest VM on