virsh: Fix '--name' and '--parent' used together in '(snapshot|checkpoint)-list' command

Until now when '--name' was used the parent was not printed and the
option was ignored. One option would be to declare the options mutually
exclusive, but for testing it may come handy to print both the snapshot
name and parent. Adjust the code to print them tab-separated and adjust
the docs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-03-21 13:15:40 +01:00
parent a068dec641
commit 6193c4656e
3 changed files with 34 additions and 17 deletions

View File

@ -7673,9 +7673,11 @@ If *--parent* is specified, add a column to the output table giving
the name of the parent of each snapshot. If *--roots* is specified, the name of the parent of each snapshot. If *--roots* is specified,
the list will be filtered to just snapshots that have no parents. the list will be filtered to just snapshots that have no parents.
If *--tree* is specified, the output will be in a tree format, listing If *--tree* is specified, the output will be in a tree format, listing
just snapshot names. These three options are mutually exclusive. If just snapshot names. These three options are mutually exclusive.
*--name* is specified only the snapshot name is printed. This option is
mutually exclusive with *--tree*. If *--name* is specified only the snapshot name is printed optionally
followed by a tab-separated name of the parent snapshot if *--parent* is used
as well. This option is mutually exclusive with *--tree*.
If *--from* is provided, filter the list to snapshots which are If *--from* is provided, filter the list to snapshots which are
children of the given ``snapshot``; or if *--current* is provided, children of the given ``snapshot``; or if *--current* is provided,
@ -7989,8 +7991,11 @@ the name of the parent of each checkpoint. If *--roots* is
specified, the list will be filtered to just checkpoints that have no specified, the list will be filtered to just checkpoints that have no
parents. If *--tree* is specified, the output will be in a tree parents. If *--tree* is specified, the output will be in a tree
format, listing just checkpoint names. These three options are format, listing just checkpoint names. These three options are
mutually exclusive. If *--name* is specified only the checkpoint name mutually exclusive.
is printed. This option is mutually exclusive with *--tree*.
If *--name* is specified only the checkpoint name is printed optionally
followed by a tab-separated name of the parent checkpoint if *--parent* is used
as well. This option is mutually exclusive with *--tree*.
If *--from* is provided, filter the list to checkpoints which are If *--from* is provided, filter the list to checkpoints which are
children of the given ``checkpoint``. When used in isolation or with children of the given ``checkpoint``. When used in isolation or with

View File

@ -754,12 +754,6 @@ cmdCheckpointList(vshControl *ctl,
chk_name = virDomainCheckpointGetName(checkpoint); chk_name = virDomainCheckpointGetName(checkpoint);
assert(chk_name); assert(chk_name);
if (name) {
/* just print the checkpoint name */
vshPrint(ctl, "%s\n", chk_name);
continue;
}
if (!(doc = virDomainCheckpointGetXMLDesc(checkpoint, 0))) if (!(doc = virDomainCheckpointGetXMLDesc(checkpoint, 0)))
continue; continue;
@ -770,6 +764,18 @@ cmdCheckpointList(vshControl *ctl,
parent_chk = virXPathString("string(/domaincheckpoint/parent/name)", parent_chk = virXPathString("string(/domaincheckpoint/parent/name)",
ctxt); ctxt);
if (name) {
vshPrint(ctl, "%s", chk_name);
if (parent_chk)
vshPrint(ctl, "\t%s", parent_chk);
vshPrint(ctl, "\n");
/* just print the checkpoint name */
continue;
}
if (virXPathLongLong("string(/domaincheckpoint/creationTime)", ctxt, if (virXPathLongLong("string(/domaincheckpoint/creationTime)", ctxt,
&creation_longlong) < 0) &creation_longlong) < 0)
continue; continue;

View File

@ -1516,12 +1516,6 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
snap_name = virDomainSnapshotGetName(snapshot); snap_name = virDomainSnapshotGetName(snapshot);
assert(snap_name); assert(snap_name);
if (name) {
/* just print the snapshot name */
vshPrint(ctl, "%s\n", snap_name);
continue;
}
if (!(doc = virDomainSnapshotGetXMLDesc(snapshot, 0))) if (!(doc = virDomainSnapshotGetXMLDesc(snapshot, 0)))
continue; continue;
@ -1532,6 +1526,18 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
parent_snap = virXPathString("string(/domainsnapshot/parent/name)", parent_snap = virXPathString("string(/domainsnapshot/parent/name)",
ctxt); ctxt);
if (name) {
vshPrint(ctl, "%s", snap_name);
if (parent_snap)
vshPrint(ctl, "\t%s", parent_snap);
vshPrint(ctl, "\n");
/* just print the snapshot name */
continue;
}
if (!(state = virXPathString("string(/domainsnapshot/state)", ctxt))) if (!(state = virXPathString("string(/domainsnapshot/state)", ctxt)))
continue; continue;