mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 05:45:46 +00:00
virsh: Introduce virshSnapshotNameCompleter
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
bab521d837
commit
4cb4b649c3
@ -478,3 +478,54 @@ virshSecretUUIDCompleter(vshControl *ctl,
|
|||||||
VIR_FREE(ret);
|
VIR_FREE(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char **
|
||||||
|
virshSnapshotNameCompleter(vshControl *ctl,
|
||||||
|
const vshCmd *cmd,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
virDomainPtr dom = NULL;
|
||||||
|
virDomainSnapshotPtr *snapshots = NULL;
|
||||||
|
int nsnapshots = 0;
|
||||||
|
size_t i = 0;
|
||||||
|
char **ret = NULL;
|
||||||
|
|
||||||
|
virCheckFlags(0, NULL);
|
||||||
|
|
||||||
|
if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if ((nsnapshots = virDomainListAllSnapshots(dom, &snapshots, flags)) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (VIR_ALLOC_N(ret, nsnapshots + 1) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
for (i = 0; i < nsnapshots; i++) {
|
||||||
|
const char *name = virDomainSnapshotGetName(snapshots[i]);
|
||||||
|
|
||||||
|
if (VIR_STRDUP(ret[i], name) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
virshDomainSnapshotFree(snapshots[i]);
|
||||||
|
}
|
||||||
|
VIR_FREE(snapshots);
|
||||||
|
virshDomainFree(dom);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
error:
|
||||||
|
for (; i < nsnapshots; i++)
|
||||||
|
virshDomainSnapshotFree(snapshots[i]);
|
||||||
|
VIR_FREE(snapshots);
|
||||||
|
for (i = 0; i < nsnapshots; i++)
|
||||||
|
VIR_FREE(ret[i]);
|
||||||
|
VIR_FREE(ret);
|
||||||
|
virshDomainFree(dom);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
@ -66,4 +66,8 @@ char ** virshSecretUUIDCompleter(vshControl *ctl,
|
|||||||
const vshCmd *cmd,
|
const vshCmd *cmd,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
|
char ** virshSnapshotNameCompleter(vshControl *ctl,
|
||||||
|
const vshCmd *cmd,
|
||||||
|
unsigned int flags);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -511,7 +511,8 @@ static const vshCmdOptDef opts_snapshot_edit[] = {
|
|||||||
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
|
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
|
||||||
{.name = "snapshotname",
|
{.name = "snapshotname",
|
||||||
.type = VSH_OT_STRING,
|
.type = VSH_OT_STRING,
|
||||||
.help = N_("snapshot name")
|
.help = N_("snapshot name"),
|
||||||
|
.completer = virshSnapshotNameCompleter,
|
||||||
},
|
},
|
||||||
VIRSH_COMMON_OPT_CURRENT(N_("also set edited snapshot as current")),
|
VIRSH_COMMON_OPT_CURRENT(N_("also set edited snapshot as current")),
|
||||||
{.name = "rename",
|
{.name = "rename",
|
||||||
@ -631,7 +632,8 @@ static const vshCmdOptDef opts_snapshot_current[] = {
|
|||||||
},
|
},
|
||||||
{.name = "snapshotname",
|
{.name = "snapshotname",
|
||||||
.type = VSH_OT_STRING,
|
.type = VSH_OT_STRING,
|
||||||
.help = N_("name of existing snapshot to make current")
|
.help = N_("name of existing snapshot to make current"),
|
||||||
|
.completer = virshSnapshotNameCompleter,
|
||||||
},
|
},
|
||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
};
|
};
|
||||||
@ -854,7 +856,8 @@ static const vshCmdOptDef opts_snapshot_info[] = {
|
|||||||
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
|
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
|
||||||
{.name = "snapshotname",
|
{.name = "snapshotname",
|
||||||
.type = VSH_OT_STRING,
|
.type = VSH_OT_STRING,
|
||||||
.help = N_("snapshot name")
|
.help = N_("snapshot name"),
|
||||||
|
.completer = virshSnapshotNameCompleter,
|
||||||
},
|
},
|
||||||
VIRSH_COMMON_OPT_CURRENT(N_("info on current snapshot")),
|
VIRSH_COMMON_OPT_CURRENT(N_("info on current snapshot")),
|
||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
@ -1661,7 +1664,8 @@ static const vshCmdOptDef opts_snapshot_dumpxml[] = {
|
|||||||
{.name = "snapshotname",
|
{.name = "snapshotname",
|
||||||
.type = VSH_OT_DATA,
|
.type = VSH_OT_DATA,
|
||||||
.flags = VSH_OFLAG_REQ,
|
.flags = VSH_OFLAG_REQ,
|
||||||
.help = N_("snapshot name")
|
.help = N_("snapshot name"),
|
||||||
|
.completer = virshSnapshotNameCompleter,
|
||||||
},
|
},
|
||||||
{.name = "security-info",
|
{.name = "security-info",
|
||||||
.type = VSH_OT_BOOL,
|
.type = VSH_OT_BOOL,
|
||||||
@ -1723,7 +1727,8 @@ static const vshCmdOptDef opts_snapshot_parent[] = {
|
|||||||
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
|
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
|
||||||
{.name = "snapshotname",
|
{.name = "snapshotname",
|
||||||
.type = VSH_OT_STRING,
|
.type = VSH_OT_STRING,
|
||||||
.help = N_("find parent of snapshot name")
|
.help = N_("find parent of snapshot name"),
|
||||||
|
.completer = virshSnapshotNameCompleter,
|
||||||
},
|
},
|
||||||
VIRSH_COMMON_OPT_CURRENT(N_("find parent of current snapshot")),
|
VIRSH_COMMON_OPT_CURRENT(N_("find parent of current snapshot")),
|
||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
@ -1782,7 +1787,8 @@ static const vshCmdOptDef opts_snapshot_revert[] = {
|
|||||||
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
|
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
|
||||||
{.name = "snapshotname",
|
{.name = "snapshotname",
|
||||||
.type = VSH_OT_STRING,
|
.type = VSH_OT_STRING,
|
||||||
.help = N_("snapshot name")
|
.help = N_("snapshot name"),
|
||||||
|
.completer = virshSnapshotNameCompleter,
|
||||||
},
|
},
|
||||||
VIRSH_COMMON_OPT_CURRENT(N_("revert to current snapshot")),
|
VIRSH_COMMON_OPT_CURRENT(N_("revert to current snapshot")),
|
||||||
{.name = "running",
|
{.name = "running",
|
||||||
@ -1866,7 +1872,8 @@ static const vshCmdOptDef opts_snapshot_delete[] = {
|
|||||||
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
|
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
|
||||||
{.name = "snapshotname",
|
{.name = "snapshotname",
|
||||||
.type = VSH_OT_STRING,
|
.type = VSH_OT_STRING,
|
||||||
.help = N_("snapshot name")
|
.help = N_("snapshot name"),
|
||||||
|
.completer = virshSnapshotNameCompleter,
|
||||||
},
|
},
|
||||||
VIRSH_COMMON_OPT_CURRENT(N_("delete current snapshot")),
|
VIRSH_COMMON_OPT_CURRENT(N_("delete current snapshot")),
|
||||||
{.name = "children",
|
{.name = "children",
|
||||||
|
Loading…
Reference in New Issue
Block a user