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