[libvirt] [PATCH RFC 0/2] virsh: Introduce basic autocompletion

This is supposed to go on the top of: https://www.redhat.com/archives/libvir-list/2017-October/msg01367.html Before digging any deeper to this hole I want to make sure that this approach is acceptable. So how does this work. The idea is to have handful of generic functions that fetch names (so called completers). Basically, one completer per each libvirt object. The returned names are then matched against (partial) user input and only matching strings are then offered to the user. Moreover, among having .completer each option has .completer_flags which can refine the completer's behaviour. For instance, in 2/2 I'm introducing virshDomainNameCompleter() which does nothing more than virConnectListAllDomains(). However, since it doesn't make much sense to start already running domain, for the 'start' command .completer_flags is set to VIR_CONNECT_LIST_DOMAINS_INACTIVE so that only inactive domains are returned in the list. What is missing? What is implemented here are vshCmdOptDef completers. The general vshCmdDef completers are still missing. Therefore: virsh # start --domain<TAB><TAB> works and lists inactive domains, but: virsh # start<TAB><TAB> doesn't (well, apart from offering options for the 'start' command). While that would be certainly nice feature to have, it'd require more work, because some arguments are "implicit" based on position. For instance: virsh # attach-interface fedora network default which is equivalent to: virsh # attach-interface --domain fedora --type network --source default Also, bash autocompletion is missing. The idea there is to have an unlisted virsh command that the bash script can call in order to fetch list of options. But again, no movement in that area yet. Michal Privoznik (2): vsh: Call vshCmdOptDef.completer properly virsh: Introduce virshDomainNameCompleter tools/virsh-domain-monitor.c | 30 +++---- tools/virsh-domain.c | 182 ++++++++++++++++++++++--------------------- tools/virsh-snapshot.c | 24 +++--- tools/virsh.c | 43 ++++++++++ tools/virsh.h | 8 +- tools/vsh.c | 45 ++++++----- 6 files changed, 194 insertions(+), 138 deletions(-) -- 2.13.6

The idea is that .completer for vshCmdOptDef would be called if the last token on the input is a cmd opt. For instance: virsh # start --domain<TAB><TAB> However, with current code that's not happening. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tools/vsh.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 10a65c39f..0ae2892a3 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2672,7 +2672,7 @@ vshReadlineParse(const char *text, int state) uint64_t opts_seen; size_t opt_index; static bool cmd_exists, opts_filled, opt_exists; - static bool non_bool_opt_exists, data_complete; + static bool non_bool_opt_exists, complete_data, complete_opts; if (!state) { parser.pos = rl_line_buffer; @@ -2719,7 +2719,7 @@ vshReadlineParse(const char *text, int state) cmd_exists = false; opts_filled = false; non_bool_opt_exists = false; - data_complete = false; + complete_data = false; const_opts_need_arg = 0; const_opts_required = 0; @@ -2785,7 +2785,7 @@ vshReadlineParse(const char *text, int state) } if (STREQ(tkdata, sanitized_text)) { /* auto-complete non-bool option arg */ - data_complete = true; + complete_data = true; break; } non_bool_opt_exists = false; @@ -2832,27 +2832,34 @@ vshReadlineParse(const char *text, int state) virSkipSpaces((const char**)&tkdata); } VIR_FREE(const_tkdata); + complete_opts = opts_filled && !non_bool_opt_exists; } if (!cmd_exists) { res = vshReadlineCommandGenerator(sanitized_text, state); - } else if (opts_filled && !non_bool_opt_exists) { - res = vshReadlineOptionsGenerator(sanitized_text, state, cmd); - } else if (non_bool_opt_exists && data_complete && opt && opt->completer) { - if (!completed_list) - completed_list = opt->completer(autoCompleteOpaque, - opt->completer_flags); - if (completed_list) { - while ((completed_name = completed_list[completed_list_index])) { - completed_list_index++; - if (!STRPREFIX(completed_name, sanitized_text)) - continue; - res = vshStrdup(NULL, completed_name); - return res; + } else { + if (complete_opts) { + res = vshReadlineOptionsGenerator(sanitized_text, state, cmd); + complete_opts = !!res; + } + + if (!complete_opts && complete_data) { + if (!completed_list && opt && opt->completer) + completed_list = opt->completer(autoCompleteOpaque, + opt->completer_flags); + if (completed_list) { + while ((completed_name = completed_list[completed_list_index])) { + completed_list_index++; + if (!STRPREFIX(completed_name, sanitized_text)) + continue; + res = vshStrdup(NULL, completed_name); + return res; + } + res = NULL; + virStringListFree(completed_list); + completed_list = NULL; + completed_list_index = 0; } - res = NULL; - virStringListFree(completed_list); - completed_list_index = 0; } } -- 2.13.6

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tools/virsh-domain-monitor.c | 30 +++---- tools/virsh-domain.c | 182 ++++++++++++++++++++++--------------------- tools/virsh-snapshot.c | 24 +++--- tools/virsh.c | 43 ++++++++++ tools/virsh.h | 8 +- 5 files changed, 168 insertions(+), 119 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index e09508248..d3356fb16 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -40,8 +40,8 @@ #include "virxml.h" #include "virstring.h" -#define VIRSH_COMMON_OPT_DOMAIN_FULL \ - VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid")) +#define VIRSH_COMMON_OPT_DOMAIN_FULL(cflags) \ + VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid"), cflags) VIR_ENUM_DECL(virshDomainIOError) VIR_ENUM_IMPL(virshDomainIOError, @@ -278,7 +278,7 @@ static const vshCmdInfo info_dommemstat[] = { }; static const vshCmdOptDef opts_dommemstat[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "period", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ_OPT, @@ -390,7 +390,7 @@ static const vshCmdInfo info_domblkinfo[] = { }; static const vshCmdOptDef opts_domblkinfo[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "device", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -460,7 +460,7 @@ static const vshCmdInfo info_domblklist[] = { }; static const vshCmdOptDef opts_domblklist[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "inactive", .type = VSH_OT_BOOL, .help = N_("get inactive rather than running configuration") @@ -566,7 +566,7 @@ static const vshCmdInfo info_domiflist[] = { }; static const vshCmdOptDef opts_domiflist[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "inactive", .type = VSH_OT_BOOL, .help = N_("get inactive rather than running configuration") @@ -655,7 +655,7 @@ static const vshCmdInfo info_domif_getlink[] = { }; static const vshCmdOptDef opts_domif_getlink[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "interface", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -752,7 +752,7 @@ static const vshCmdInfo info_domcontrol[] = { }; static const vshCmdOptDef opts_domcontrol[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = NULL} }; @@ -805,7 +805,7 @@ static const vshCmdInfo info_domblkstat[] = { }; static const vshCmdOptDef opts_domblkstat[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "device", .type = VSH_OT_STRING, .flags = VSH_OFLAG_EMPTY_OK, @@ -991,7 +991,7 @@ static const vshCmdInfo info_domifstat[] = { }; static const vshCmdOptDef opts_domifstat[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "interface", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -1064,7 +1064,7 @@ static const vshCmdInfo info_domblkerror[] = { }; static const vshCmdOptDef opts_domblkerror[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = NULL} }; @@ -1125,7 +1125,7 @@ static const vshCmdInfo info_dominfo[] = { }; static const vshCmdOptDef opts_dominfo[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = NULL} }; @@ -1264,7 +1264,7 @@ static const vshCmdInfo info_domstate[] = { }; static const vshCmdOptDef opts_domstate[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "reason", .type = VSH_OT_BOOL, .help = N_("also print reason for the state") @@ -1316,7 +1316,7 @@ static const vshCmdInfo info_domtime[] = { }; static const vshCmdOptDef opts_domtime[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "now", .type = VSH_OT_BOOL, .help = N_("set to the time of the host running virsh") @@ -2145,7 +2145,7 @@ static const vshCmdInfo info_domifaddr[] = { }; static const vshCmdOptDef opts_domifaddr[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "interface", .type = VSH_OT_STRING, .flags = VSH_OFLAG_NONE, diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 53ce5b82f..124d8a5f2 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -65,8 +65,8 @@ # define SA_SIGINFO 0 #endif -#define VIRSH_COMMON_OPT_DOMAIN_FULL \ - VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid")) +#define VIRSH_COMMON_OPT_DOMAIN_FULL(cflags) \ + VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid"), cflags) #define VIRSH_COMMON_OPT_DOMAIN_PERSISTENT \ {.name = "persistent", \ @@ -154,7 +154,7 @@ static const vshCmdInfo info_attach_device[] = { }; static const vshCmdOptDef opts_attach_device[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), VIRSH_COMMON_OPT_FILE(N_("XML file")), VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, VIRSH_COMMON_OPT_DOMAIN_CONFIG, @@ -236,7 +236,7 @@ static const vshCmdInfo info_attach_disk[] = { }; static const vshCmdOptDef opts_attach_disk[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "source", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ | VSH_OFLAG_EMPTY_OK, @@ -727,7 +727,7 @@ static const vshCmdInfo info_attach_interface[] = { }; static const vshCmdOptDef opts_attach_interface[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "type", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -1037,7 +1037,7 @@ static const vshCmdInfo info_autostart[] = { }; static const vshCmdOptDef opts_autostart[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "disable", .type = VSH_OT_BOOL, .help = N_("disable autostarting") @@ -1089,7 +1089,7 @@ static const vshCmdInfo info_blkdeviotune[] = { }; static const vshCmdOptDef opts_blkdeviotune[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "device", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -1416,7 +1416,7 @@ static const vshCmdInfo info_blkiotune[] = { }; static const vshCmdOptDef opts_blkiotune[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "weight", .type = VSH_OT_INT, .help = N_("IO Weight") @@ -1885,7 +1885,7 @@ static const vshCmdInfo info_block_commit[] = { }; static const vshCmdOptDef opts_block_commit[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -2110,7 +2110,7 @@ static const vshCmdInfo info_block_copy[] = { }; static const vshCmdOptDef opts_block_copy[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -2426,7 +2426,7 @@ static const vshCmdInfo info_block_job[] = { }; static const vshCmdOptDef opts_block_job[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -2669,7 +2669,7 @@ static const vshCmdInfo info_block_pull[] = { }; static const vshCmdOptDef opts_block_pull[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -2815,7 +2815,7 @@ static const vshCmdInfo info_block_resize[] = { }; static const vshCmdOptDef opts_block_resize[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -2879,7 +2879,7 @@ static const vshCmdInfo info_console[] = { }; static const vshCmdOptDef opts_console[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "devname", /* sc_prohibit_devname */ .type = VSH_OT_STRING, .help = N_("character device name") @@ -2973,7 +2973,7 @@ static const vshCmdInfo info_domif_setlink[] = { }; static const vshCmdOptDef opts_domif_setlink[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "interface", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -3143,7 +3143,7 @@ static const vshCmdInfo info_domiftune[] = { }; static const vshCmdOptDef opts_domiftune[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "interface", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -3340,7 +3340,7 @@ static const vshCmdInfo info_suspend[] = { }; static const vshCmdOptDef opts_suspend[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_RUNNING), {.name = NULL} }; @@ -3382,7 +3382,7 @@ static const vshCmdInfo info_dom_pm_suspend[] = { }; static const vshCmdOptDef opts_dom_pm_suspend[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_RUNNING), {.name = "target", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -3460,7 +3460,7 @@ static const vshCmdInfo info_dom_pm_wakeup[] = { }; static const vshCmdOptDef opts_dom_pm_wakeup[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_OTHER), {.name = NULL} }; @@ -3505,7 +3505,7 @@ static const vshCmdInfo info_undefine[] = { }; static const vshCmdOptDef opts_undefine[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_PERSISTENT), {.name = "managed-save", .type = VSH_OT_BOOL, .help = N_("remove domain managed state file") @@ -3923,7 +3923,8 @@ static const vshCmdInfo info_start[] = { }; static const vshCmdOptDef opts_start[] = { - VIRSH_COMMON_OPT_DOMAIN(N_("name of the inactive domain")), + VIRSH_COMMON_OPT_DOMAIN(N_("name of the inactive domain"), + VIR_CONNECT_LIST_DOMAINS_SHUTOFF), #ifndef WIN32 {.name = "console", .type = VSH_OT_BOOL, @@ -4098,7 +4099,7 @@ static const vshCmdInfo info_save[] = { }; static const vshCmdOptDef opts_save[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), VIRSH_COMMON_OPT_FILE(N_("where to save the data")), {.name = "bypass-cache", .type = VSH_OT_BOOL, @@ -4544,7 +4545,7 @@ static const vshCmdInfo info_managedsave[] = { }; static const vshCmdOptDef opts_managedsave[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "bypass-cache", .type = VSH_OT_BOOL, .help = N_("avoid file system cache when saving") @@ -4663,7 +4664,7 @@ static const vshCmdInfo info_managedsaveremove[] = { }; static const vshCmdOptDef opts_managedsaveremove[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = NULL} }; @@ -4718,7 +4719,7 @@ static const vshCmdInfo info_managed_save_edit[] = { }; static const vshCmdOptDef opts_managed_save_edit[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "running", .type = VSH_OT_BOOL, .help = N_("set domain to be running on start") @@ -4784,7 +4785,7 @@ static const vshCmdInfo info_managed_save_dumpxml[] = { }; static const vshCmdOptDef opts_managed_save_dumpxml[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "security-info", .type = VSH_OT_BOOL, .help = N_("include security sensitive information in XML dump") @@ -4832,7 +4833,7 @@ static const vshCmdInfo info_managed_save_define[] = { }; static const vshCmdOptDef opts_managed_save_define[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "xml", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -4904,7 +4905,7 @@ static const vshCmdInfo info_schedinfo[] = { }; static const vshCmdOptDef opts_schedinfo[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "weight", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ_OPT, @@ -5215,7 +5216,7 @@ static const vshCmdInfo info_dump[] = { }; static const vshCmdOptDef opts_dump[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), VIRSH_COMMON_OPT_FILE(N_("where to dump the core")), VIRSH_COMMON_OPT_LIVE(N_("perform a live core dump if supported")), {.name = "crash", @@ -5387,7 +5388,7 @@ static const vshCmdInfo info_screenshot[] = { }; static const vshCmdOptDef opts_screenshot[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "file", .type = VSH_OT_STRING, .help = N_("where to store the screenshot") @@ -5530,7 +5531,7 @@ static const vshCmdInfo info_setLifecycleAction[] = { }; static const vshCmdOptDef opts_setLifecycleAction[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "type", .type = VSH_OT_STRING, .flags = VSH_OFLAG_REQ, @@ -5626,7 +5627,7 @@ static const vshCmdInfo info_set_user_password[] = { }; static const vshCmdOptDef opts_set_user_password[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "user", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -5690,7 +5691,7 @@ static const vshCmdInfo info_resume[] = { }; static const vshCmdOptDef opts_resume[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_PAUSED), {.name = NULL} }; @@ -5729,7 +5730,7 @@ static const vshCmdInfo info_shutdown[] = { }; static const vshCmdOptDef opts_shutdown[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "mode", .type = VSH_OT_STRING, .help = N_("shutdown mode: acpi|agent|initctl|signal|paravirt") @@ -5813,7 +5814,7 @@ static const vshCmdInfo info_reboot[] = { }; static const vshCmdOptDef opts_reboot[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "mode", .type = VSH_OT_STRING, .help = N_("shutdown mode: acpi|agent|initctl|signal|paravirt") @@ -5892,7 +5893,7 @@ static const vshCmdInfo info_reset[] = { }; static const vshCmdOptDef opts_reset[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = NULL} }; @@ -5931,7 +5932,7 @@ static const vshCmdInfo info_domjobinfo[] = { }; static const vshCmdOptDef opts_domjobinfo[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "completed", .type = VSH_OT_BOOL, .help = N_("return statistics of a recently completed job") @@ -6275,7 +6276,7 @@ static const vshCmdInfo info_domjobabort[] = { }; static const vshCmdOptDef opts_domjobabort[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = NULL} }; @@ -6309,7 +6310,7 @@ static const vshCmdInfo info_vcpucount[] = { }; static const vshCmdOptDef opts_vcpucount[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "maximum", .type = VSH_OT_BOOL, .help = N_("get maximum count of vcpus") @@ -6506,7 +6507,7 @@ static const vshCmdInfo info_vcpuinfo[] = { }; static const vshCmdOptDef opts_vcpuinfo[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "pretty", .type = VSH_OT_BOOL, .help = N_("return human readable output") @@ -6755,7 +6756,7 @@ static const vshCmdInfo info_vcpupin[] = { }; static const vshCmdOptDef opts_vcpupin[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "vcpu", .type = VSH_OT_INT, .help = N_("vcpu number") @@ -6972,7 +6973,7 @@ static const vshCmdInfo info_emulatorpin[] = { }; static const vshCmdOptDef opts_emulatorpin[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "cpulist", .type = VSH_OT_STRING, .flags = VSH_OFLAG_EMPTY_OK, @@ -7076,7 +7077,7 @@ static const vshCmdInfo info_setvcpus[] = { }; static const vshCmdOptDef opts_setvcpus[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "count", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -7174,7 +7175,7 @@ static const vshCmdInfo info_guestvcpus[] = { }; static const vshCmdOptDef opts_guestvcpus[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "cpulist", .type = VSH_OT_STRING, .help = N_("list of cpus to enable or disable") @@ -7259,7 +7260,7 @@ static const vshCmdInfo info_setvcpu[] = { }; static const vshCmdOptDef opts_setvcpu[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "vcpulist", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -7342,7 +7343,7 @@ static const vshCmdInfo info_domblkthreshold[] = { }; static const vshCmdOptDef opts_domblkthreshold[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "dev", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -7398,7 +7399,7 @@ static const vshCmdInfo info_iothreadinfo[] = { {.name = NULL} }; static const vshCmdOptDef opts_iothreadinfo[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), VIRSH_COMMON_OPT_DOMAIN_CONFIG, VIRSH_COMMON_OPT_DOMAIN_LIVE, VIRSH_COMMON_OPT_DOMAIN_CURRENT, @@ -7474,7 +7475,7 @@ static const vshCmdInfo info_iothreadpin[] = { }; static const vshCmdOptDef opts_iothreadpin[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "iothread", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -7556,7 +7557,7 @@ static const vshCmdInfo info_iothreadadd[] = { }; static const vshCmdOptDef opts_iothreadadd[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "id", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -7621,7 +7622,7 @@ static const vshCmdInfo info_iothreaddel[] = { }; static const vshCmdOptDef opts_iothreaddel[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "id", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -7897,7 +7898,7 @@ static const vshCmdInfo info_cpu_stats[] = { }; static const vshCmdOptDef opts_cpu_stats[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "total", .type = VSH_OT_BOOL, .help = N_("Show total statistics only") @@ -8236,7 +8237,7 @@ static const vshCmdInfo info_destroy[] = { }; static const vshCmdOptDef opts_destroy[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "graceful", .type = VSH_OT_BOOL, .help = N_("terminate gracefully") @@ -8289,7 +8290,7 @@ static const vshCmdInfo info_desc[] = { }; static const vshCmdOptDef opts_desc[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), VIRSH_COMMON_OPT_LIVE(N_("modify/get running state")), VIRSH_COMMON_OPT_CONFIG(N_("modify/get persistent configuration")), VIRSH_COMMON_OPT_CURRENT(N_("modify/get current state configuration")), @@ -8454,7 +8455,7 @@ static const vshCmdInfo info_metadata[] = { }; static const vshCmdOptDef opts_metadata[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "uri", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -8600,7 +8601,7 @@ static const vshCmdInfo info_inject_nmi[] = { }; static const vshCmdOptDef opts_inject_nmi[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = NULL} }; @@ -8634,7 +8635,7 @@ static const vshCmdInfo info_send_key[] = { }; static const vshCmdOptDef opts_send_key[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "codeset", .type = VSH_OT_STRING, .flags = VSH_OFLAG_REQ_OPT, @@ -8730,7 +8731,7 @@ static const vshCmdInfo info_send_process_signal[] = { }; static const vshCmdOptDef opts_send_process_signal[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "pid", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -8835,7 +8836,7 @@ static const vshCmdInfo info_setmem[] = { }; static const vshCmdOptDef opts_setmem[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "kilobytes", .type = VSH_OT_ALIAS, .help = "size" @@ -8916,7 +8917,7 @@ static const vshCmdInfo info_setmaxmem[] = { }; static const vshCmdOptDef opts_setmaxmem[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "kilobytes", .type = VSH_OT_ALIAS, .help = "size" @@ -9004,7 +9005,7 @@ static const vshCmdInfo info_memtune[] = { }; static const vshCmdOptDef opts_memtune[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "hard-limit", .type = VSH_OT_INT, .help = N_("Max memory, as scaled integer (default KiB)") @@ -9181,7 +9182,7 @@ static const vshCmdInfo info_perf[] = { }; static const vshCmdOptDef opts_perf[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "enable", .type = VSH_OT_STRING, .help = N_("perf events which will be enabled") @@ -9315,7 +9316,7 @@ static const vshCmdInfo info_numatune[] = { }; static const vshCmdOptDef opts_numatune[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "mode", .type = VSH_OT_STRING, .help = N_("NUMA mode, one of strict, preferred and interleave \n" @@ -9450,7 +9451,7 @@ static const vshCmdInfo info_qemu_monitor_command[] = { }; static const vshCmdOptDef opts_qemu_monitor_command[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "hmp", .type = VSH_OT_BOOL, .help = N_("command is in human monitor protocol") @@ -9751,7 +9752,7 @@ static const vshCmdInfo info_qemu_agent_command[] = { }; static const vshCmdOptDef opts_qemu_agent_command[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "timeout", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ_OPT, @@ -9873,7 +9874,7 @@ static const vshCmdInfo info_lxc_enter_namespace[] = { }; static const vshCmdOptDef opts_lxc_enter_namespace[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "noseclabel", .type = VSH_OT_BOOL, .help = N_("Do not change process security label") @@ -10014,7 +10015,7 @@ static const vshCmdInfo info_dumpxml[] = { }; static const vshCmdOptDef opts_dumpxml[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "inactive", .type = VSH_OT_BOOL, .help = N_("show inactive defined XML") @@ -10223,7 +10224,7 @@ static const vshCmdInfo info_domname[] = { }; static const vshCmdOptDef opts_domname[] = { - VIRSH_COMMON_OPT_DOMAIN(N_("domain id or uuid")), + VIRSH_COMMON_OPT_DOMAIN(N_("domain id or uuid"), 0), {.name = NULL} }; @@ -10255,7 +10256,7 @@ static const vshCmdInfo info_domrename[] = { }; static const vshCmdOptDef opts_domrename[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_INACTIVE), {.name = "new-name", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -10302,7 +10303,8 @@ static const vshCmdInfo info_domid[] = { }; static const vshCmdOptDef opts_domid[] = { - VIRSH_COMMON_OPT_DOMAIN(N_("domain name or uuid")), + VIRSH_COMMON_OPT_DOMAIN(N_("domain name or uuid"), + VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = NULL} }; @@ -10339,7 +10341,7 @@ static const vshCmdInfo info_domuuid[] = { }; static const vshCmdOptDef opts_domuuid[] = { - VIRSH_COMMON_OPT_DOMAIN(N_("domain id or name")), + VIRSH_COMMON_OPT_DOMAIN(N_("domain id or name"), 0), {.name = NULL} }; @@ -10376,7 +10378,7 @@ static const vshCmdInfo info_migrate[] = { }; static const vshCmdOptDef opts_migrate[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "desturi", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -10974,7 +10976,7 @@ static const vshCmdInfo info_migrate_setmaxdowntime[] = { }; static const vshCmdOptDef opts_migrate_setmaxdowntime[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "downtime", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -11025,7 +11027,7 @@ static const vshCmdInfo info_migrate_getmaxdowntime[] = { }; static const vshCmdOptDef opts_migrate_getmaxdowntime[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = NULL} }; @@ -11066,7 +11068,7 @@ static const vshCmdInfo info_migrate_compcache[] = { }; static const vshCmdOptDef opts_migrate_compcache[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "size", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ_OPT, @@ -11123,7 +11125,7 @@ static const vshCmdInfo info_migrate_setspeed[] = { }; static const vshCmdOptDef opts_migrate_setspeed[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "bandwidth", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -11169,7 +11171,7 @@ static const vshCmdInfo info_migrate_getspeed[] = { }; static const vshCmdOptDef opts_migrate_getspeed[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = NULL} }; @@ -11252,7 +11254,7 @@ static const vshCmdInfo info_domdisplay[] = { }; static const vshCmdOptDef opts_domdisplay[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "include-password", .type = VSH_OT_BOOL, .help = N_("includes the password into the connection URI if available") @@ -11533,7 +11535,7 @@ static const vshCmdInfo info_vncdisplay[] = { }; static const vshCmdOptDef opts_vncdisplay[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = NULL} }; @@ -11609,7 +11611,7 @@ static const vshCmdInfo info_ttyconsole[] = { }; static const vshCmdOptDef opts_ttyconsole[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = NULL} }; @@ -11651,7 +11653,7 @@ static const vshCmdInfo info_domhostname[] = { }; static const vshCmdOptDef opts_domhostname[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = NULL} }; @@ -11810,7 +11812,7 @@ static const vshCmdInfo info_detach_device[] = { }; static const vshCmdOptDef opts_detach_device[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), VIRSH_COMMON_OPT_FILE(N_("XML file")), VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, VIRSH_COMMON_OPT_DOMAIN_CONFIG, @@ -11891,7 +11893,7 @@ static const vshCmdInfo info_update_device[] = { }; static const vshCmdOptDef opts_update_device[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), VIRSH_COMMON_OPT_FILE(N_("XML file")), VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, VIRSH_COMMON_OPT_DOMAIN_CONFIG, @@ -11973,7 +11975,7 @@ static const vshCmdInfo info_detach_interface[] = { }; static const vshCmdOptDef opts_detach_interface[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "type", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -12416,7 +12418,7 @@ static const vshCmdInfo info_detach_disk[] = { }; static const vshCmdOptDef opts_detach_disk[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "target", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -12516,7 +12518,7 @@ static const vshCmdInfo info_edit[] = { }; static const vshCmdOptDef opts_edit[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "skip-validate", .type = VSH_OT_BOOL, .help = N_("skip validation of the XML against the schema") @@ -13475,7 +13477,7 @@ static const vshCmdInfo info_change_media[] = { }; static const vshCmdOptDef opts_change_media[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -13636,7 +13638,7 @@ static const vshCmdInfo info_domfstrim[] = { }; static const vshCmdOptDef opts_domfstrim[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "minimum", .type = VSH_OT_INT, .help = N_("Just a hint to ignore contiguous " @@ -13689,7 +13691,7 @@ static const vshCmdInfo info_domfsfreeze[] = { }; static const vshCmdOptDef opts_domfsfreeze[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "mountpoint", .type = VSH_OT_ARGV, .help = N_("mountpoint path to be frozen") @@ -13742,7 +13744,7 @@ static const vshCmdInfo info_domfsthaw[] = { }; static const vshCmdOptDef opts_domfsthaw[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "mountpoint", .type = VSH_OT_ARGV, .help = N_("mountpoint path to be thawed") @@ -13795,7 +13797,7 @@ static const vshCmdInfo info_domfsinfo[] = { }; static const vshCmdOptDef opts_domfsinfo[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = NULL} }; diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 8789ee7b0..bbb3b4be6 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -42,8 +42,8 @@ #include "virxml.h" #include "conf/snapshot_conf.h" -#define VIRSH_COMMON_OPT_DOMAIN_FULL \ - VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid")) +#define VIRSH_COMMON_OPT_DOMAIN_FULL(cflags) \ + VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid"), cflags) /* Helper for snapshot-create and snapshot-create-as */ static bool @@ -125,7 +125,7 @@ static const vshCmdInfo info_snapshot_create[] = { }; static const vshCmdOptDef opts_snapshot_create[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "xmlfile", .type = VSH_OT_STRING, .help = N_("domain snapshot XML") @@ -319,7 +319,7 @@ static const vshCmdInfo info_snapshot_create_as[] = { }; static const vshCmdOptDef opts_snapshot_create_as[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "name", .type = VSH_OT_STRING, .help = N_("name of snapshot") @@ -508,7 +508,7 @@ static const vshCmdInfo info_snapshot_edit[] = { }; static const vshCmdOptDef opts_snapshot_edit[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "snapshotname", .type = VSH_OT_STRING, .help = N_("snapshot name") @@ -620,7 +620,7 @@ static const vshCmdInfo info_snapshot_current[] = { }; static const vshCmdOptDef opts_snapshot_current[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "name", .type = VSH_OT_BOOL, .help = N_("list the name, rather than the full xml") @@ -851,7 +851,7 @@ static const vshCmdInfo info_snapshot_info[] = { }; static const vshCmdOptDef opts_snapshot_info[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "snapshotname", .type = VSH_OT_STRING, .help = N_("snapshot name") @@ -1401,7 +1401,7 @@ static const vshCmdInfo info_snapshot_list[] = { }; static const vshCmdOptDef opts_snapshot_list[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "parent", .type = VSH_OT_BOOL, .help = N_("add a column showing parent snapshot") @@ -1657,7 +1657,7 @@ static const vshCmdInfo info_snapshot_dumpxml[] = { }; static const vshCmdOptDef opts_snapshot_dumpxml[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "snapshotname", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -1720,7 +1720,7 @@ static const vshCmdInfo info_snapshot_parent[] = { }; static const vshCmdOptDef opts_snapshot_parent[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "snapshotname", .type = VSH_OT_STRING, .help = N_("find parent of snapshot name") @@ -1779,7 +1779,7 @@ static const vshCmdInfo info_snapshot_revert[] = { }; static const vshCmdOptDef opts_snapshot_revert[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "snapshotname", .type = VSH_OT_STRING, .help = N_("snapshot name") @@ -1863,7 +1863,7 @@ static const vshCmdInfo info_snapshot_delete[] = { }; static const vshCmdOptDef opts_snapshot_delete[] = { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name = "snapshotname", .type = VSH_OT_STRING, .help = N_("snapshot name") diff --git a/tools/virsh.c b/tools/virsh.c index d1789f03a..b7f45c84e 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -71,6 +71,7 @@ #include "virsh-secret.h" #include "virsh-snapshot.h" #include "virsh-volume.h" +#include "virsh-util.h" /* Gnulib doesn't guarantee SA_SIGINFO support. */ #ifndef SA_SIGINFO @@ -348,6 +349,48 @@ virshConnectionHandler(vshControl *ctl) } +char ** +virshDomainNameCompleter(void *opaque, unsigned int flags) +{ + vshControl *ctl = opaque; + virshControlPtr priv = ctl->privData; + virDomainPtr *domains; + int ndomains; + size_t i = 0; + char **ret = NULL; + + if (!virshConnectionHandler(ctl)) + return NULL; + + if ((ndomains = virConnectListAllDomains(priv->conn, &domains, flags)) < 0) + return NULL; + + if (VIR_ALLOC_N(ret, ndomains + 1) < 0) + goto error; + + for (i = 0; i < ndomains; i++) { + const char *name = virDomainGetName(domains[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virshDomainFree(domains[i]); + } + VIR_FREE(domains); + + return ret; + error: + + for (; i < ndomains; i++) + virshDomainFree(domains[i]); + VIR_FREE(domains); + for (i = 0; i < ndomains; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return NULL; +} + + /* * Initialize connection. */ diff --git a/tools/virsh.h b/tools/virsh.h index 9bcf467d4..8b79b578e 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -70,11 +70,13 @@ .help = _helpstr \ } -# define VIRSH_COMMON_OPT_DOMAIN(_helpstr) \ +# define VIRSH_COMMON_OPT_DOMAIN(_helpstr, cflags) \ {.name = "domain", \ .type = VSH_OT_DATA, \ .flags = VSH_OFLAG_REQ, \ - .help = _helpstr \ + .help = _helpstr, \ + .completer = virshDomainNameCompleter, \ + .completer_flags = cflags, \ } # define VIRSH_COMMON_OPT_CONFIG(_helpstr) \ @@ -146,4 +148,6 @@ typedef enum { virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly); +char ** virshDomainNameCompleter(void *opaque, unsigned int flags); + #endif /* VIRSH_H */ -- 2.13.6

On Tue, Oct 31, 2017 at 14:10:25 +0100, Michal Privoznik wrote:
This is supposed to go on the top of:
https://www.redhat.com/archives/libvir-list/2017-October/msg01367.html
Before digging any deeper to this hole I want to make sure that this approach is acceptable.
So how does this work. The idea is to have handful of generic functions that fetch names (so called completers). Basically, one completer per each libvirt object. The returned names are then matched against (partial) user input and only matching strings are then offered to the user. Moreover, among having .completer each option has .completer_flags which can refine the completer's behaviour.
For instance, in 2/2 I'm introducing virshDomainNameCompleter() which does nothing more than virConnectListAllDomains(). However, since it doesn't make much sense to start already running domain, for the 'start' command .completer_flags is set to VIR_CONNECT_LIST_DOMAINS_INACTIVE so that only inactive domains are returned in the list.
What is missing? What is implemented here are vshCmdOptDef completers. The general vshCmdDef completers are still missing. Therefore:
virsh # start --domain<TAB><TAB>
works and lists inactive domains, but:
virsh # start<TAB><TAB>
doesn't (well, apart from offering options for the 'start' command). While that would be certainly nice feature to have, it'd require more work, because some arguments are "implicit" based on position. For instance:
virsh # attach-interface fedora network default
which is equivalent to:
virsh # attach-interface --domain fedora --type network --source default
Also, bash autocompletion is missing. The idea there is to have an unlisted virsh command that the bash script can call in order to fetch list of options. But again, no movement in that area yet.
I think we need a way to determine whether the autocompletion is possible without any user input. For bash autocompletion you will invoke virsh to get any other params, but that means that for connections requiring authentication you'd get stuck waiting for input (or openning an ssh connection) which may throw off users. This might happen too often on RHEV boxes since they use polkit auth. It might be possible to work around polkit by connecting without auth callbacks, but for qemu+ssh you don't really have options IMO. Maybe you'll need to specifically disable it on ssh connections using the default transport. For libssh and libssh2 you can allow that but it's rather expensive to instantiate the connection just to query a list of VMs after you press tab. Peter

On 10/31/2017 02:43 PM, Peter Krempa wrote:
On Tue, Oct 31, 2017 at 14:10:25 +0100, Michal Privoznik wrote:
This is supposed to go on the top of:
https://www.redhat.com/archives/libvir-list/2017-October/msg01367.html
Before digging any deeper to this hole I want to make sure that this approach is acceptable.
So how does this work. The idea is to have handful of generic functions that fetch names (so called completers). Basically, one completer per each libvirt object. The returned names are then matched against (partial) user input and only matching strings are then offered to the user. Moreover, among having .completer each option has .completer_flags which can refine the completer's behaviour.
For instance, in 2/2 I'm introducing virshDomainNameCompleter() which does nothing more than virConnectListAllDomains(). However, since it doesn't make much sense to start already running domain, for the 'start' command .completer_flags is set to VIR_CONNECT_LIST_DOMAINS_INACTIVE so that only inactive domains are returned in the list.
What is missing? What is implemented here are vshCmdOptDef completers. The general vshCmdDef completers are still missing. Therefore:
virsh # start --domain<TAB><TAB>
works and lists inactive domains, but:
virsh # start<TAB><TAB>
doesn't (well, apart from offering options for the 'start' command). While that would be certainly nice feature to have, it'd require more work, because some arguments are "implicit" based on position. For instance:
virsh # attach-interface fedora network default
which is equivalent to:
virsh # attach-interface --domain fedora --type network --source default
Also, bash autocompletion is missing. The idea there is to have an unlisted virsh command that the bash script can call in order to fetch list of options. But again, no movement in that area yet.
I think we need a way to determine whether the autocompletion is possible without any user input. For bash autocompletion you will invoke virsh to get any other params, but that means that for connections requiring authentication you'd get stuck waiting for input (or openning an ssh connection) which may throw off users.
Right. I haven't encountered this problem in my local (read limited) testing. For interactive virsh instead of calling virshConnectionHandler() I can check for: if (!priv->conn || virConnectIsAlive(priv->conn) != 0) return NULL; This means that you'd get autocompletion only if you're connected and your connection is valid. For bash we'd be opening autocompletion for each run which would indeed be too expensive. On the other hand, isn't that how every other tool does that? For instance, firewall-cmd must connect to the daemon to fetch list of zones/rules/... On the other hand, that connection is only local (through some UNIX socket I assume). Long story short, we might allow autocompletion in bash only for local connections. Michal
participants (2)
-
Michal Privoznik
-
Peter Krempa