virsh: Provide completer for vol-wipe algorithms

Related issue: https://gitlab.com/libvirt/libvirt/-/issues/9

Signed-off-by: Haonan Wang <hnwanga1@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Haonan Wang 2022-03-10 23:22:24 +08:00 committed by Michal Privoznik
parent 688a2c0897
commit 35ba60be36
4 changed files with 28 additions and 1 deletions

View File

@ -26,6 +26,7 @@
#include "virsh-pool.h"
#include "virsh.h"
#include "virstring.h"
#include "virsh-volume.h"
char **
virshStorageVolNameCompleter(vshControl *ctl,
@ -116,3 +117,21 @@ virshStorageVolKeyCompleter(vshControl *ctl,
virshStoragePoolListFree(list);
return ret;
}
char **
virshStorageVolWipeAlgorithmCompleter(vshControl *ctl G_GNUC_UNUSED,
const vshCmd *cmd G_GNUC_UNUSED,
unsigned int flags)
{
char **ret = NULL;
size_t i;
virCheckFlags(0, NULL);
ret = g_new0(char *, VIR_STORAGE_VOL_WIPE_ALG_LAST + 1);
for (i = 0; i < VIR_STORAGE_VOL_WIPE_ALG_LAST; i++)
ret[i] = g_strdup(virshStorageVolWipeAlgorithmTypeToString(i));
return ret;
}

View File

@ -33,3 +33,9 @@ char **
virshStorageVolKeyCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char **
virshStorageVolWipeAlgorithmCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);

View File

@ -902,12 +902,12 @@ static const vshCmdOptDef opts_vol_wipe[] = {
VIRSH_COMMON_OPT_POOL_OPTIONAL,
{.name = "algorithm",
.type = VSH_OT_STRING,
.completer = virshStorageVolWipeAlgorithmCompleter,
.help = N_("perform selected wiping algorithm")
},
{.name = NULL}
};
VIR_ENUM_DECL(virshStorageVolWipeAlgorithm);
VIR_ENUM_IMPL(virshStorageVolWipeAlgorithm,
VIR_STORAGE_VOL_WIPE_ALG_LAST,
"zero", "nnsa", "dod", "bsi", "gutmann", "schneier",

View File

@ -33,3 +33,5 @@ virStorageVolPtr virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
VIRSH_BYUUID | VIRSH_BYNAME)
extern const vshCmdDef storageVolCmds[];
VIR_ENUM_DECL(virshStorageVolWipeAlgorithm);