virsh: Implement "domrename" command

This patch implements new virsh command, domrename.

Using domrename, it will be possible to rename domain from the virsh shell by
calling virRenameDomain API.

It takes two arguments, current domain name and new domain name.

Example:

virsh # list --all
 Id    Name                           State
 ----------------------------------------------------
  -     bar                            shut off

virsh # domrename bar foo
Domain successfully renamed

virsh # list --all
 Id    Name                           State
 ----------------------------------------------------
  -     foo                            shut off

virsh #

Signed-off-by: Tomas Meszaros <exo@tty.sk>
This commit is contained in:
Tomas Meszaros 2015-08-10 21:59:15 +02:00 committed by Michal Privoznik
parent 9f7a559a6d
commit ff486e0d29
2 changed files with 64 additions and 0 deletions

View File

@ -9745,6 +9745,57 @@ cmdDomname(vshControl *ctl, const vshCmd *cmd)
return true;
}
/*
* "domrename" command
*/
static const vshCmdInfo info_domrename[] = {
{.name = "help",
.data = N_("rename a domain")
},
{.name = "desc",
.data = "Rename an inactive domain."
},
{.name = NULL}
};
static const vshCmdOptDef opts_domrename[] = {
{.name = "domain",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("domain name, id or uuid")
},
{.name = "new-name",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("new domain name")
},
{.name = NULL}
};
static bool
cmdDomrename(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
const char *new_name = NULL;
bool ret = false;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return ret;
if (vshCommandOptStringReq(ctl, cmd, "new-name", &new_name) < 0)
goto cleanup;
if (virDomainRename(dom, new_name, 0) < 0)
goto cleanup;
vshPrint(ctl, "Domain successfully renamed\n");
ret = true;
cleanup:
virDomainFree(dom);
return false;
}
/*
* "domid" command
*/
@ -13102,6 +13153,12 @@ const vshCmdDef domManagementCmds[] = {
.info = info_domname,
.flags = 0
},
{.name = "domrename",
.handler = cmdDomrename,
.opts = opts_domrename,
.info = info_domrename,
.flags = 0
},
{.name = "dompmsuspend",
.handler = cmdDomPMSuspend,
.opts = opts_dom_pm_suspend,

View File

@ -1258,6 +1258,13 @@ on both of them).
Convert a domain Id (or UUID) to domain name
=item B<domrename> I<domain> I<new-name>
Rename a domain. This command changes current domain name to the new name
specified in the second argument.
B<Note>: Domain must be inactive and without snapshots.
=item B<domstate> I<domain> [I<--reason>]
Returns state about a domain. I<--reason> tells virsh to also print