Add a virsh command called "setguestvcpu" to excercise the
virDomainSetGuestVcpu API.
---
tools/virsh-domain.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 6 ++++
2 files changed, 83 insertions(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 0402aef..6853613 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5866,6 +5866,77 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
}
/*
+ * "setguestvcpu" command
+ */
+static const vshCmdInfo info_setguestvcpu[] = {
+ {.name = "help",
+ .data = N_("modify the state of a guest's virtual CPU")
+ },
+ {.name = "desc",
+ .data = N_("Enable or disable virtual CPUs in a guest using the guest
agent.")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_setguestvcpu[] = {
+ {.name = "domain",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("domain name, id or uuid")
+ },
+ {.name = "id",
+ .type = VSH_OT_INT,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("id of the virtual CPU")
+ },
+ {.name = "online",
+ .type = VSH_OT_BOOL,
+ .help = N_("enable the vCPU")
+ },
+ {.name = "offline",
+ .type = VSH_OT_BOOL,
+ .help = N_("disable the vCPU")
+ },
+ {.name = NULL}
+};
+
+static bool
+cmdSetguestvcpu(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainPtr dom;
+ unsigned int id;
+ bool online = vshCommandOptBool(cmd, "online");
+ bool offline = vshCommandOptBool(cmd, "offline");
+ bool ret = false;
+
+ VSH_EXCLUSIVE_OPTIONS_VAR(online, offline);
+
+ if (!online && !offline) {
+ vshError(ctl, "%s",
+ _("need to specify either --online or --offline"));
+ return false;
+ }
+
+ if (vshCommandOptUInt(cmd, "id", &id) < 0) {
+ vshError(ctl, "%s", _("Invalid or missing cpu ID"));
+ return false;
+ }
+
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+ return false;
+
+ if (virDomainSetGuestVcpu(dom, id, online, 0) < 0)
+ goto cleanup;
+
+ ret = true;
+
+cleanup:
+ virDomainFree(dom);
+ return ret;
+}
+
+
+/*
* "cpu-compare" command
*/
static const vshCmdInfo info_cpu_compare[] = {
@@ -10514,6 +10585,12 @@ const vshCmdDef domManagementCmds[] = {
.info = info_setvcpus,
.flags = 0
},
+ {.name = "setguestvcpu",
+ .handler = cmdSetguestvcpu,
+ .opts = opts_setguestvcpu,
+ .info = info_setguestvcpu,
+ .flags = 0
+ },
{.name = "shutdown",
.handler = cmdShutdown,
.opts = opts_shutdown,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 8037a0d..b34a47d 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1749,6 +1749,12 @@ state of the domain (corresponding to I<--live> if running,
or
I<--config> if inactive); these three flags are mutually exclusive.
Thus, this command always takes exactly zero or two flags.
+=item B<setguestvcpu> I<domain> I<cpu id> [{I<--online> |
I<--offline>}]
+
+Set the online state of a vCPU in the guest. This command
+requires the guest agent configured. The state may be either
+I<--online> or I<--offline>. The flags are mutually exclusive.
+
=item B<vcpuinfo> I<domain>
Returns basic information about the domain virtual CPUs, like the number of
--
1.8.2.1