From ff486e0d29a7c08e7131447ca3c878ed791def4e Mon Sep 17 00:00:00 2001 From: Tomas Meszaros Date: Mon, 10 Aug 2015 21:59:15 +0200 Subject: [PATCH] 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 --- tools/virsh-domain.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 7 ++++++ 2 files changed, 64 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c8b0e76b88..e2f5a0b2c0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -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, diff --git a/tools/virsh.pod b/tools/virsh.pod index 07e6ba739f..83c445d35d 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1258,6 +1258,13 @@ on both of them). Convert a domain Id (or UUID) to domain name +=item B I I + +Rename a domain. This command changes current domain name to the new name +specified in the second argument. + +B: Domain must be inactive and without snapshots. + =item B I [I<--reason>] Returns state about a domain. I<--reason> tells virsh to also print