Merge pull request #4484 from donaldsharp/pbr_tab_complete

Pbr tab complete
This commit is contained in:
Renato Westphal 2019-06-07 21:48:53 -03:00 committed by GitHub
commit 9fd5497f30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 11 deletions

View File

@ -308,7 +308,7 @@ static void nhgc_delete(struct nexthop_group_cmd *nhgc)
DEFINE_QOBJ_TYPE(nexthop_group_cmd)
DEFUN_NOSH(nexthop_group, nexthop_group_cmd, "nexthop-group NAME",
DEFUN_NOSH(nexthop_group, nexthop_group_cmd, "nexthop-group NHGNAME",
"Enter into the nexthop-group submode\n"
"Specify the NAME of the nexthop-group\n")
{
@ -321,7 +321,7 @@ DEFUN_NOSH(nexthop_group, nexthop_group_cmd, "nexthop-group NAME",
return CMD_SUCCESS;
}
DEFUN_NOSH(no_nexthop_group, no_nexthop_group_cmd, "no nexthop-group NAME",
DEFUN_NOSH(no_nexthop_group, no_nexthop_group_cmd, "no nexthop-group NHGNAME",
NO_STR
"Delete the nexthop-group\n"
"Specify the NAME of the nexthop-group\n")
@ -714,6 +714,19 @@ void nexthop_group_interface_state_change(struct interface *ifp,
}
}
static void nhg_name_autocomplete(vector comps, struct cmd_token *token)
{
struct nexthop_group_cmd *nhgc;
RB_FOREACH (nhgc, nhgc_entry_head, &nhgc_entries) {
vector_set(comps, XSTRDUP(MTYPE_COMPLETION, nhgc->name));
}
}
static const struct cmd_variable_handler nhg_name_handlers[] = {
{.tokenname = "NHGNAME", .completions = nhg_name_autocomplete},
{.completions = NULL}};
void nexthop_group_init(void (*new)(const char *name),
void (*add_nexthop)(const struct nexthop_group_cmd *nhg,
const struct nexthop *nhop),
@ -723,6 +736,8 @@ void nexthop_group_init(void (*new)(const char *name),
{
RB_INIT(nhgc_entry_head, &nhgc_entries);
cmd_variable_handler_register(nhg_name_handlers);
install_node(&nexthop_group_node, nexthop_group_write);
install_element(CONFIG_NODE, &nexthop_group_cmd);
install_element(CONFIG_NODE, &no_nexthop_group_cmd);

View File

@ -38,7 +38,7 @@
#include "pbrd/pbr_vty_clippy.c"
#endif
DEFUN_NOSH(pbr_map, pbr_map_cmd, "pbr-map WORD seq (1-700)",
DEFUN_NOSH(pbr_map, pbr_map_cmd, "pbr-map PBRMAP seq (1-700)",
"Create pbr-map or enter pbr-map command mode\n"
"The name of the PBR MAP\n"
"Sequence to insert in existing pbr-map entry\n"
@ -54,7 +54,7 @@ DEFUN_NOSH(pbr_map, pbr_map_cmd, "pbr-map WORD seq (1-700)",
return CMD_SUCCESS;
}
DEFUN_NOSH(no_pbr_map, no_pbr_map_cmd, "no pbr-map WORD [seq (1-700)]",
DEFUN_NOSH(no_pbr_map, no_pbr_map_cmd, "no pbr-map PBRMAP [seq (1-700)]",
NO_STR
"Delete pbr-map\n"
"The name of the PBR MAP\n"
@ -172,7 +172,7 @@ DEFPY(pbr_map_match_dst, pbr_map_match_dst_cmd,
}
DEFPY(pbr_map_nexthop_group, pbr_map_nexthop_group_cmd,
"[no] set nexthop-group NAME$name",
"[no] set nexthop-group NHGNAME$name",
NO_STR
"Set for the PBR-MAP\n"
"nexthop-group to use\n"
@ -348,7 +348,7 @@ DEFPY(pbr_map_nexthop, pbr_map_nexthop_cmd,
DEFPY (pbr_policy,
pbr_policy_cmd,
"[no] pbr-policy NAME$mapname",
"[no] pbr-policy PBRMAP$mapname",
NO_STR
"Policy to use\n"
"Name of the pbr-map to apply\n")
@ -661,8 +661,27 @@ static int pbr_vty_map_config_write(struct vty *vty)
return 1;
}
static void pbr_map_completer(vector comps, struct cmd_token *token)
{
struct pbr_map *pbrm;
RB_FOREACH (pbrm, pbr_map_entry_head, &pbr_maps)
vector_set(comps, XSTRDUP(MTYPE_COMPLETION, pbrm->name));
}
static const struct cmd_variable_handler pbr_map_name[] = {
{
.tokenname = "PBRMAP", .completions = pbr_map_completer,
},
{
.completions = NULL
}
};
void pbr_vty_init(void)
{
cmd_variable_handler_register(pbr_map_name);
install_node(&interface_node,
pbr_interface_config_write);
if_cmd_init();

View File

@ -157,7 +157,7 @@ DEFPY (install_routes_data_dump,
DEFPY (install_routes,
install_routes_cmd,
"sharp install routes [vrf NAME$name] <A.B.C.D$start4|X:X::X:X$start6> <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|nexthop-group NAME$nexthop_group> (1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt]",
"sharp install routes [vrf NAME$name] <A.B.C.D$start4|X:X::X:X$start6> <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|nexthop-group NHGNAME$nexthop_group> (1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt]",
"Sharp routing Protocol\n"
"install some routes\n"
"Routes to install\n"

View File

@ -1678,7 +1678,7 @@ DEFUNSH(VTYSH_RMAP, vtysh_route_map, vtysh_route_map_cmd,
}
DEFUNSH(VTYSH_PBRD, vtysh_pbr_map, vtysh_pbr_map_cmd,
"pbr-map NAME seq (1-700)",
"pbr-map PBRMAP seq (1-700)",
"Create pbr-map or enter pbr-map command mode\n"
"The name of the PBR MAP\n"
"Sequence to insert to/delete from existing pbr-map entry\n"
@ -1714,7 +1714,7 @@ DEFUNSH(VTYSH_BFDD, bfd_peer_enter, bfd_peer_enter_cmd,
}
#endif /* HAVE_BFDD */
DEFSH(VTYSH_PBRD, vtysh_no_pbr_map_cmd, "no pbr-map WORD [seq (1-700)]",
DEFSH(VTYSH_PBRD, vtysh_no_pbr_map_cmd, "no pbr-map PBRMAP [seq (1-700)]",
NO_STR
"Delete pbr-map\n"
"The name of the PBR MAP\n"
@ -2114,7 +2114,7 @@ DEFSH(VTYSH_ZEBRA, vtysh_no_logicalrouter_cmd,
"The file name in " NS_RUN_DIR ", or a full pathname\n")
DEFUNSH(VTYSH_PBRD | VTYSH_SHARPD, vtysh_nexthop_group, vtysh_nexthop_group_cmd,
"nexthop-group NAME",
"nexthop-group NHGNAME",
"Nexthop Group configuration\n"
"Name of the Nexthop Group\n")
{
@ -2123,7 +2123,7 @@ DEFUNSH(VTYSH_PBRD | VTYSH_SHARPD, vtysh_nexthop_group, vtysh_nexthop_group_cmd,
}
DEFSH(VTYSH_PBRD | VTYSH_SHARPD, vtysh_no_nexthop_group_cmd,
"no nexthop-group NAME",
"no nexthop-group NHGNAME",
NO_STR
"Nexthop Group Configuration\n"
"Name of the Nexthop Group\n")