On 08/09/2011 09:13 PM, Eric Blake wrote:
Sometimes, full XML is too much; since most snapshot commands
operate on a snapshot name, there should be an easy way to get
at the current snapshot's name.
* tools/virsh.c (cmdSnapshotCurrent): Add an option.
* tools/virsh.pod (snapshot-current): Document it.
---
tools/virsh.c | 21 ++++++++++++++++++---
tools/virsh.pod | 4 +++-
2 files changed, 21 insertions(+), 4 deletions(-)
@@ -12065,13 +12067,26 @@ cmdSnapshotCurrent(vshControl *ctl, const
vshCmd *cmd)
if (!xml)
goto cleanup;
- vshPrint(ctl, "%s", xml);
- VIR_FREE(xml);
+ if (vshCommandOptBool(cmd, "name")) {
+ char *tmp;
+
+ name = strstr(xml, "<name>");
+ if (!name)
+ goto cleanup;
+ name += strlen("<name>");
+ tmp = strstr(name, "</name>");
Admittedly, this mishandles any XML escapes, such as '<', occurring
in name. A more robust solution involves introducing a new
virDomainSnapshotGetName; however, while that is a good idea, it goes
counter to my goal of no new API for my first round of disk-only
snapshot support. Then again, I'm thinking that even with a new API,
virsh should be smart enough to use the new API where it works, and fall
back to the xml scraping where it doesn't, so I'm debating whether this
needs to switch to full-blown xpath parsing instead of just strstr scraping.
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org