virsh: Add --print-xml flag for attach-disk command

The flag causes the XML of the disk that would be attached to be printed
instead.
This commit is contained in:
Peter Krempa 2013-01-25 13:21:23 +01:00
parent 702911496f
commit f8d5119e4f
2 changed files with 20 additions and 7 deletions

View File

@ -317,6 +317,12 @@ static const vshCmdOptDef opts_attach_disk[] = {
.flags = 0, .flags = 0,
.help = N_("use multifunction pci under specified address") .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} {.name = NULL}
}; };
@ -480,11 +486,11 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
unsigned int flags; unsigned int flags;
const char *stype = NULL; const char *stype = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
char *xml; char *xml = NULL;
struct stat st; struct stat st;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup; return false;
if (vshCommandOptString(cmd, "source", &source) <= 0) if (vshCommandOptString(cmd, "source", &source) <= 0)
goto cleanup; goto cleanup;
@ -620,6 +626,12 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
xml = virBufferContentAndReset(&buf); xml = virBufferContentAndReset(&buf);
if (vshCommandOptBool(cmd, "print-xml")) {
vshPrint(ctl, "%s", xml);
functionReturn = true;
goto cleanup;
}
if (vshCommandOptBool(cmd, "config")) { if (vshCommandOptBool(cmd, "config")) {
flags = VIR_DOMAIN_AFFECT_CONFIG; flags = VIR_DOMAIN_AFFECT_CONFIG;
if (virDomainIsActive(dom) == 1) if (virDomainIsActive(dom) == 1)
@ -629,8 +641,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
ret = virDomainAttachDevice(dom, xml); ret = virDomainAttachDevice(dom, xml);
} }
VIR_FREE(xml);
if (ret != 0) { if (ret != 0) {
vshError(ctl, "%s", _("Failed to attach disk")); vshError(ctl, "%s", _("Failed to attach disk"));
} else { } else {
@ -639,8 +649,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
} }
cleanup: cleanup:
if (dom) VIR_FREE(xml);
virDomainFree(dom); virDomainFree(dom);
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return functionReturn; return functionReturn;
} }

View File

@ -1787,7 +1787,7 @@ needed if the device does not use managed mode.
[I<--driver driver>] [I<--subdriver subdriver>] [I<--cache cache>] [I<--driver driver>] [I<--subdriver subdriver>] [I<--cache cache>]
[I<--type type>] [I<--mode mode>] [I<--config>] [I<--sourcetype soucetype>] [I<--type type>] [I<--mode mode>] [I<--config>] [I<--sourcetype soucetype>]
[I<--serial serial>] [I<--shareable>] [I<--rawio>] [I<--address address>] [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. Attach a new disk device to the domain.
I<source> is path for the files and devices. I<target> controls the bus or 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 I<multifunction> indicates specified pci address is a multifunction pci device
address. 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> =item B<attach-interface> I<domain> I<type> I<source>
[I<--target target>] [I<--mac mac>] [I<--script script>] [I<--model model>] [I<--target target>] [I<--mac mac>] [I<--script script>] [I<--model model>]
[I<--config>] [I<--inbound average,peak,burst>] [I<--outbound average,peak,burst>] [I<--config>] [I<--inbound average,peak,burst>] [I<--outbound average,peak,burst>]