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(a)tty.sk>
---
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 4988ba2..128cfac 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9724,6 +9724,57 @@ cmdDomname(vshControl *ctl, const vshCmd *cmd)
}
/*
+ * "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
*/
static const vshCmdInfo info_domid[] = {
@@ -13080,6 +13131,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 5ee9a96..c049f8f 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<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
--
2.1.0