mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
virsh-domain: Add --live, --config, --current logic to cmdAttachDevice
Use the approach established in commit 69ce3ffa8d431e9810607c6e00b7cfcc481b491d to improve this function too.
This commit is contained in:
parent
de68895902
commit
f81c95b31f
@ -173,13 +173,21 @@ static const vshCmdOptDef opts_attach_device[] = {
|
|||||||
.help = N_("XML file")
|
.help = N_("XML file")
|
||||||
},
|
},
|
||||||
{.name = "persistent",
|
{.name = "persistent",
|
||||||
.type = VSH_OT_ALIAS,
|
.type = VSH_OT_BOOL,
|
||||||
.help = "config"
|
.help = N_("make live change persistent")
|
||||||
},
|
},
|
||||||
{.name = "config",
|
{.name = "config",
|
||||||
.type = VSH_OT_BOOL,
|
.type = VSH_OT_BOOL,
|
||||||
.help = N_("affect next boot")
|
.help = N_("affect next boot")
|
||||||
},
|
},
|
||||||
|
{.name = "live",
|
||||||
|
.type = VSH_OT_BOOL,
|
||||||
|
.help = N_("affect running domain")
|
||||||
|
},
|
||||||
|
{.name = "current",
|
||||||
|
.type = VSH_OT_BOOL,
|
||||||
|
.help = N_("affect current domain")
|
||||||
|
},
|
||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -191,7 +199,21 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
|
|||||||
char *buffer;
|
char *buffer;
|
||||||
int rv;
|
int rv;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned int flags;
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
||||||
|
bool current = vshCommandOptBool(cmd, "current");
|
||||||
|
bool config = vshCommandOptBool(cmd, "config");
|
||||||
|
bool live = vshCommandOptBool(cmd, "live");
|
||||||
|
bool persistent = vshCommandOptBool(cmd, "persistent");
|
||||||
|
|
||||||
|
VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
|
||||||
|
|
||||||
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
||||||
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
||||||
|
|
||||||
|
if (config || persistent)
|
||||||
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
||||||
|
if (live)
|
||||||
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
@ -199,19 +221,20 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (persistent &&
|
||||||
|
virDomainIsActive(dom) == 1)
|
||||||
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
||||||
|
|
||||||
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
|
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
|
||||||
vshReportError(ctl);
|
vshReportError(ctl);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "config")) {
|
if (flags)
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
||||||
if (virDomainIsActive(dom) == 1)
|
|
||||||
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
||||||
rv = virDomainAttachDeviceFlags(dom, buffer, flags);
|
rv = virDomainAttachDeviceFlags(dom, buffer, flags);
|
||||||
} else {
|
else
|
||||||
rv = virDomainAttachDevice(dom, buffer);
|
rv = virDomainAttachDevice(dom, buffer);
|
||||||
}
|
|
||||||
VIR_FREE(buffer);
|
VIR_FREE(buffer);
|
||||||
|
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
|
@ -1816,7 +1816,8 @@ format of the device sections to get the most accurate set of accepted values.
|
|||||||
|
|
||||||
=over 4
|
=over 4
|
||||||
|
|
||||||
=item B<attach-device> I<domain> I<FILE> [I<--config>]
|
=item B<attach-device> I<domain> I<FILE>
|
||||||
|
[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]]
|
||||||
|
|
||||||
Attach a device to the domain, using a device definition in an XML
|
Attach a device to the domain, using a device definition in an XML
|
||||||
file using a device definition element such as <disk> or <interface>
|
file using a device definition element such as <disk> or <interface>
|
||||||
@ -1824,13 +1825,22 @@ as the top-level element. See the documentation at
|
|||||||
L<http://libvirt.org/formatdomain.html#elementsDevices> to learn about
|
L<http://libvirt.org/formatdomain.html#elementsDevices> to learn about
|
||||||
libvirt XML format for a device. If I<--config> is specified the
|
libvirt XML format for a device. If I<--config> is specified the
|
||||||
command alters the persistent domain configuration with the device
|
command alters the persistent domain configuration with the device
|
||||||
attach taking effect the next time libvirt starts the domain. For
|
attach taking effect the next time libvirt starts the domain.
|
||||||
compatibility purposes, I<--persistent> is an alias of I<--config>.
|
|
||||||
For cdrom and floppy devices, this command only replaces the media
|
For cdrom and floppy devices, this command only replaces the media
|
||||||
within an existing device; consider using B<update-device> for this
|
within an existing device; consider using B<update-device> for this
|
||||||
usage. For passthrough host devices, see also B<nodedev-detach>,
|
usage. For passthrough host devices, see also B<nodedev-detach>,
|
||||||
needed if the device does not use managed mode.
|
needed if the device does not use managed mode.
|
||||||
|
|
||||||
|
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. When no flag is specified legacy API is used whose behavior depends
|
||||||
|
on the hypervisor driver.
|
||||||
|
|
||||||
|
For compatibility purposes, I<--persistent> behaves like I<--config> for
|
||||||
|
an offline domain, and like I<--live> I<--config> for a running domain.
|
||||||
|
|
||||||
B<Note>: using of partial device definition XML files may lead to unexpected
|
B<Note>: using of partial device definition XML files may lead to unexpected
|
||||||
results as some fields may be autogenerated and thus match devices other than
|
results as some fields may be autogenerated and thus match devices other than
|
||||||
expected.
|
expected.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user