提交 f81c95b3 编写于 作者: P Peter Krempa

virsh-domain: Add --live, --config, --current logic to cmdAttachDevice

Use the approach established in commit
69ce3ffa to improve this function too.
上级 de688959
......@@ -173,13 +173,21 @@ static const vshCmdOptDef opts_attach_device[] = {
.help = N_("XML file")
},
{.name = "persistent",
.type = VSH_OT_ALIAS,
.help = "config"
.type = VSH_OT_BOOL,
.help = N_("make live change persistent")
},
{.name = "config",
.type = VSH_OT_BOOL,
.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}
};
......@@ -191,7 +199,21 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
char *buffer;
int rv;
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)))
return false;
......@@ -199,19 +221,20 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
goto cleanup;
if (persistent &&
virDomainIsActive(dom) == 1)
flags |= VIR_DOMAIN_AFFECT_LIVE;
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshReportError(ctl);
goto cleanup;
}
if (vshCommandOptBool(cmd, "config")) {
flags = VIR_DOMAIN_AFFECT_CONFIG;
if (virDomainIsActive(dom) == 1)
flags |= VIR_DOMAIN_AFFECT_LIVE;
if (flags)
rv = virDomainAttachDeviceFlags(dom, buffer, flags);
} else {
else
rv = virDomainAttachDevice(dom, buffer);
}
VIR_FREE(buffer);
if (rv < 0) {
......
......@@ -1816,7 +1816,8 @@ format of the device sections to get the most accurate set of accepted values.
=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
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
libvirt XML format for a device. If I<--config> is specified the
command alters the persistent domain configuration with the device
attach taking effect the next time libvirt starts the domain. For
compatibility purposes, I<--persistent> is an alias of I<--config>.
attach taking effect the next time libvirt starts the domain.
For cdrom and floppy devices, this command only replaces the media
within an existing device; consider using B<update-device> for this
usage. For passthrough host devices, see also B<nodedev-detach>,
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
results as some fields may be autogenerated and thus match devices other than
expected.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册