]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Implement "domrename" command
authorTomas Meszaros <exo@tty.sk>
Mon, 10 Aug 2015 19:59:15 +0000 (21:59 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 14 Aug 2015 08:50:20 +0000 (10:50 +0200)
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>
tools/virsh-domain.c
tools/virsh.pod

index c8b0e76b885052428c5b17609d6be8a5cb5b753a..e2f5a0b2c06542e86921dc6c33c42eef367f63dd 100644 (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,
index 07e6ba739f5d90a2f03836ea71d7b077f8a27f80..83c445d35df3292b10fc10170c24a02523877d95 100644 (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