mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-09 09:14:57 +00:00
Allow choice of shutdown method via virsh
Extend the 'shutdown' and 'reboot' methods so that they both accept a new argument --mode acpi|agent * tools/virsh.c: New args for shutdown/reboot * tools/virsh.pod: Document new args
This commit is contained in:
parent
fb52a39928
commit
17cfff6f17
@ -3850,6 +3850,7 @@ static const vshCmdInfo info_shutdown[] = {
|
|||||||
|
|
||||||
static const vshCmdOptDef opts_shutdown[] = {
|
static const vshCmdOptDef opts_shutdown[] = {
|
||||||
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
|
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
|
||||||
|
{"mode", VSH_OT_STRING, VSH_OFLAG_NONE, N_("shutdown mode: acpi|agent")},
|
||||||
{NULL, 0, 0, NULL}
|
{NULL, 0, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3859,14 +3860,37 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
const char *mode = NULL;
|
||||||
|
int flags = 0;
|
||||||
|
int rv;
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (vshCommandOptString(cmd, "mode", &mode) < 0) {
|
||||||
|
vshError(ctl, "%s", _("Invalid type"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode) {
|
||||||
|
if (STREQ(mode, "acpi")) {
|
||||||
|
flags |= VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN;
|
||||||
|
} else if (STREQ(mode, "agent")) {
|
||||||
|
flags |= VIR_DOMAIN_SHUTDOWN_GUEST_AGENT;
|
||||||
|
} else {
|
||||||
|
vshError(ctl, _("Unknown mode %s value, expecting 'acpi' or 'agent'"), mode);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virDomainShutdown(dom) == 0) {
|
if (flags)
|
||||||
|
rv = virDomainShutdownFlags(dom, flags);
|
||||||
|
else
|
||||||
|
rv = virDomainShutdown(dom);
|
||||||
|
if (rv == 0) {
|
||||||
vshPrint(ctl, _("Domain %s is being shutdown\n"), name);
|
vshPrint(ctl, _("Domain %s is being shutdown\n"), name);
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, _("Failed to shutdown domain %s"), name);
|
vshError(ctl, _("Failed to shutdown domain %s"), name);
|
||||||
@ -3888,6 +3912,7 @@ static const vshCmdInfo info_reboot[] = {
|
|||||||
|
|
||||||
static const vshCmdOptDef opts_reboot[] = {
|
static const vshCmdOptDef opts_reboot[] = {
|
||||||
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
|
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
|
||||||
|
{"mode", VSH_OT_STRING, VSH_OFLAG_NONE, N_("shutdown mode: acpi|agent")},
|
||||||
{NULL, 0, 0, NULL}
|
{NULL, 0, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3897,14 +3922,32 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
const char *mode = NULL;
|
||||||
|
int flags = 0;
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (vshCommandOptString(cmd, "mode", &mode) < 0) {
|
||||||
|
vshError(ctl, "%s", _("Invalid type"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode) {
|
||||||
|
if (STREQ(mode, "acpi")) {
|
||||||
|
flags |= VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN;
|
||||||
|
} else if (STREQ(mode, "agent")) {
|
||||||
|
flags |= VIR_DOMAIN_SHUTDOWN_GUEST_AGENT;
|
||||||
|
} else {
|
||||||
|
vshError(ctl, _("Unknown mode %s value, expecting 'acpi' or 'agent'"), mode);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virDomainReboot(dom, 0) == 0) {
|
if (virDomainReboot(dom, flags) == 0) {
|
||||||
vshPrint(ctl, _("Domain %s is being rebooted\n"), name);
|
vshPrint(ctl, _("Domain %s is being rebooted\n"), name);
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, _("Failed to reboot domain %s"), name);
|
vshError(ctl, _("Failed to reboot domain %s"), name);
|
||||||
|
@ -807,7 +807,7 @@ If I<--live> is specified, set scheduler information of a running guest.
|
|||||||
If I<--config> is specified, affect the next boot of a persistent guest.
|
If I<--config> is specified, affect the next boot of a persistent guest.
|
||||||
If I<--current> is specified, affect the current guest state.
|
If I<--current> is specified, affect the current guest state.
|
||||||
|
|
||||||
=item B<reboot> I<domain-id>
|
=item B<reboot> I<domain-id> [I<--mode acpi|agent>]
|
||||||
|
|
||||||
Reboot a domain. This acts just as if the domain had the B<reboot>
|
Reboot a domain. This acts just as if the domain had the B<reboot>
|
||||||
command run from the console. The command returns as soon as it has
|
command run from the console. The command returns as soon as it has
|
||||||
@ -817,6 +817,10 @@ domain actually reboots.
|
|||||||
The exact behavior of a domain when it reboots is set by the
|
The exact behavior of a domain when it reboots is set by the
|
||||||
I<on_reboot> parameter in the domain's XML definition.
|
I<on_reboot> parameter in the domain's XML definition.
|
||||||
|
|
||||||
|
By default the hypervisor will try to pick a suitable shutdown
|
||||||
|
method. To specify an alternative method, the I<--mode> parameter
|
||||||
|
can specify C<acpi> or C<agent>.
|
||||||
|
|
||||||
=item B<reset> I<domain-id>
|
=item B<reset> I<domain-id>
|
||||||
|
|
||||||
Reset a domain immediately without any guest shutdown. B<reset>
|
Reset a domain immediately without any guest shutdown. B<reset>
|
||||||
@ -1190,7 +1194,7 @@ The I<--maximum> flag controls the maximum number of virtual cpus that can
|
|||||||
be hot-plugged the next time the domain is booted. As such, it must only be
|
be hot-plugged the next time the domain is booted. As such, it must only be
|
||||||
used with the I<--config> flag, and not with the I<--live> flag.
|
used with the I<--config> flag, and not with the I<--live> flag.
|
||||||
|
|
||||||
=item B<shutdown> I<domain-id>
|
=item B<shutdown> I<domain-id> [I<--mode acpi|agent>]
|
||||||
|
|
||||||
Gracefully shuts down a domain. This coordinates with the domain OS
|
Gracefully shuts down a domain. This coordinates with the domain OS
|
||||||
to perform graceful shutdown, so there is no guarantee that it will
|
to perform graceful shutdown, so there is no guarantee that it will
|
||||||
@ -1205,6 +1209,10 @@ be lost once the guest stops running, but the snapshot contents still
|
|||||||
exist, and a new domain with the same name and UUID can restore the
|
exist, and a new domain with the same name and UUID can restore the
|
||||||
snapshot metadata with B<snapshot-create>.
|
snapshot metadata with B<snapshot-create>.
|
||||||
|
|
||||||
|
By default the hypervisor will try to pick a suitable shutdown
|
||||||
|
method. To specify an alternative method, the I<--mode> parameter
|
||||||
|
can specify C<acpi> or C<agent>.
|
||||||
|
|
||||||
=item B<start> I<domain-name> [I<--console>] [I<--paused>] [I<--autodestroy>]
|
=item B<start> I<domain-name> [I<--console>] [I<--paused>] [I<--autodestroy>]
|
||||||
[I<--bypass-cache>] [I<--force-boot>]
|
[I<--bypass-cache>] [I<--force-boot>]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user