The flag causes the XML of the disk that would be attached to be printed instead. --- tools/virsh-domain.c | 46 ++++++++++++++++++++++++++++------------------ tools/virsh.pod | 5 ++++- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 026dac1..829e475 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -317,6 +317,12 @@ static const vshCmdOptDef opts_attach_disk[] = { .flags = 0, .help = N_("use multifunction pci under specified address") }, + {.name = "print-xml", + .type = VSH_OT_BOOL, + .flags = 0, + .help = N_("print XML document rather than attach the disk") + }, + {.name = NULL} }; @@ -480,11 +486,11 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) unsigned int flags; const char *stype = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; - char *xml; + char *xml = NULL; struct stat st; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; if (vshCommandOptString(cmd, "source", &source) <= 0) goto cleanup; @@ -620,27 +626,31 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) xml = virBufferContentAndReset(&buf); - if (vshCommandOptBool(cmd, "config")) { - flags = VIR_DOMAIN_AFFECT_CONFIG; - if (virDomainIsActive(dom) == 1) - flags |= VIR_DOMAIN_AFFECT_LIVE; - ret = virDomainAttachDeviceFlags(dom, xml, flags); - } else { - ret = virDomainAttachDevice(dom, xml); - } - - VIR_FREE(xml); + if (!vshCommandOptBool(cmd, "print-xml")) { + if (vshCommandOptBool(cmd, "config")) { + flags = VIR_DOMAIN_AFFECT_CONFIG; + if (virDomainIsActive(dom) == 1) + flags |= VIR_DOMAIN_AFFECT_LIVE; + ret = virDomainAttachDeviceFlags(dom, xml, flags); + } else { + ret = virDomainAttachDevice(dom, xml); + } - if (ret != 0) { - vshError(ctl, "%s", _("Failed to attach disk")); + if (ret != 0) { + vshError(ctl, "%s", _("Failed to attach disk")); + goto cleanup; + } else { + vshPrint(ctl, "%s", _("Disk attached successfully\n")); + } } else { - vshPrint(ctl, "%s", _("Disk attached successfully\n")); - functionReturn = true; + vshPrint(ctl, "%s", xml); } + functionReturn = true; + cleanup: - if (dom) - virDomainFree(dom); + VIR_FREE(xml); + virDomainFree(dom); virBufferFreeAndReset(&buf); return functionReturn; } diff --git a/tools/virsh.pod b/tools/virsh.pod index e2a2aec..fd0f762 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1787,7 +1787,7 @@ needed if the device does not use managed mode. [I<--driver driver>] [I<--subdriver subdriver>] [I<--cache cache>] [I<--type type>] [I<--mode mode>] [I<--config>] [I<--sourcetype soucetype>] [I<--serial serial>] [I<--shareable>] [I<--rawio>] [I<--address address>] -[I<--multifunction>] +[I<--multifunction>] [I<--print-xml>] Attach a new disk device to the domain. I<source> is path for the files and devices. I<target> controls the bus or @@ -1817,6 +1817,9 @@ scsi:controller.bus.unit or ide:controller.bus.unit. I<multifunction> indicates specified pci address is a multifunction pci device address. +If I<--print-xml> is specified, then the XML of the disk that would be attached +is printed instead. + =item B<attach-interface> I<domain> I<type> I<source> [I<--target target>] [I<--mac mac>] [I<--script script>] [I<--model model>] [I<--config>] [I<--inbound average,peak,burst>] [I<--outbound average,peak,burst>] -- 1.8.1.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list