virsh: Expose virDomainDetachDeviceAlias

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2018-05-21 16:25:13 +02:00
parent 18f2e9d500
commit 856fb16492
2 changed files with 83 additions and 0 deletions

View File

@ -11878,6 +11878,72 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
return funcRet;
}
/*
* "detach-device-alias" command
*/
static const vshCmdInfo info_detach_device_alias[] = {
{.name = "help",
.data = N_("detach device from an alias")
},
{.name = "desc",
.data = N_("Detach device identified by the given alias from a domain")
},
{.name = NULL}
};
static const vshCmdOptDef opts_detach_device_alias[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
{.name = "alias",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("device alias")
},
VIRSH_COMMON_OPT_DOMAIN_CONFIG,
VIRSH_COMMON_OPT_DOMAIN_LIVE,
VIRSH_COMMON_OPT_DOMAIN_CURRENT,
{.name = NULL}
};
static bool
cmdDetachDeviceAlias(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
const char *alias = NULL;
bool current = vshCommandOptBool(cmd, "current");
bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live");
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
bool ret = false;
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
if (config)
flags |= VIR_DOMAIN_AFFECT_CONFIG;
if (live)
flags |= VIR_DOMAIN_AFFECT_LIVE;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
if (vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0)
goto cleanup;
if (virDomainDetachDeviceAlias(dom, alias, flags) < 0) {
vshError(ctl, _("Failed to detach device with alias %s"), alias);
goto cleanup;
}
vshPrintExtra(ctl, "%s", _("Device detach request sent successfully\n"));
ret = true;
cleanup:
virshDomainFree(dom);
return ret;
}
/*
* "update-device" command
*/
@ -13994,6 +14060,12 @@ const vshCmdDef domManagementCmds[] = {
.info = info_detach_device,
.flags = 0
},
{.name = "detach-device-alias",
.handler = cmdDetachDeviceAlias,
.opts = opts_detach_device_alias,
.info = info_detach_device_alias,
.flags = 0
},
{.name = "detach-disk",
.handler = cmdDetachDisk,
.opts = opts_detach_disk,

View File

@ -3112,6 +3112,17 @@ an offline domain, and like I<--live> I<--config> for a running domain.
Note that older versions of virsh used I<--config> as an alias for
I<--persistent>.
=item B<detach-device-alias> I<domain> I<alias>
[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]]
Detach a device with given I<alias> from the I<domain>.
If I<--live> is specified, affect a running domain.
If I<--config> is specified, affect the next startup of a persistent domain.
If I<--current> is specified, affect the current domain state.
Both I<--live> and I<--config> flags may be given, but I<--current> is
exclusive.
=item B<detach-disk> I<domain> I<target>
[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]]
[I<--print-xml>]