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 0616487..e801b2d 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5964,6 +5964,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[] = {
@@ -10615,6 +10686,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 42e39d3..bde1bc6 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1763,6 +1763,12 @@ If I<--agent> is specified, then guest agent commands are
used to retrieve the
count of available vCPUs from the perspective of the guest. This flag is usable
only for live domains.
+=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