Merge pull request #15947 from anlancs/isisd/fix-lsp-json

isisd: fix json display for database command
This commit is contained in:
Russ White 2024-05-07 11:29:46 -04:00 committed by GitHub
commit 8756deffbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 5 deletions

View file

@ -822,15 +822,24 @@ int lsp_print_all(struct vty *vty, struct json_object *json,
{ {
struct isis_lsp *lsp; struct isis_lsp *lsp;
int lsp_count = 0; int lsp_count = 0;
struct json_object *lsp_json = NULL;
if (detail == ISIS_UI_LEVEL_BRIEF) { if (detail == ISIS_UI_LEVEL_BRIEF) {
frr_each (lspdb, head, lsp) { frr_each (lspdb, head, lsp) {
lsp_print_common(lsp, vty, json, dynhost, isis); if (json) {
lsp_json = json_object_new_object();
json_object_array_add(json, lsp_json);
}
lsp_print_common(lsp, vty, lsp_json, dynhost, isis);
lsp_count++; lsp_count++;
} }
} else if (detail == ISIS_UI_LEVEL_DETAIL) { } else if (detail == ISIS_UI_LEVEL_DETAIL) {
frr_each (lspdb, head, lsp) { frr_each (lspdb, head, lsp) {
lsp_print_detail(lsp, vty, json, dynhost, isis); if (json) {
lsp_json = json_object_new_object();
json_object_array_add(json, lsp_json);
}
lsp_print_detail(lsp, vty, lsp_json, dynhost, isis);
lsp_count++; lsp_count++;
} }
} }

View file

@ -2651,6 +2651,7 @@ void show_isis_database_lspdb_json(struct json_object *json,
{ {
struct isis_lsp *lsp; struct isis_lsp *lsp;
int lsp_count; int lsp_count;
struct json_object *lsp_arr_json;
if (lspdb_count(lspdb) > 0) { if (lspdb_count(lspdb) > 0) {
lsp = lsp_for_sysid(lspdb, sysid_str, area->isis); lsp = lsp_for_sysid(lspdb, sysid_str, area->isis);
@ -2667,9 +2668,12 @@ void show_isis_database_lspdb_json(struct json_object *json,
lsp_print_json(lsp, json, area->dynhostname, lsp_print_json(lsp, json, area->dynhostname,
area->isis); area->isis);
} else if (sysid_str == NULL) { } else if (sysid_str == NULL) {
lsp_count = lsp_arr_json = json_object_new_array();
lsp_print_all(NULL, json, lspdb, ui_level, json_object_object_add(json, "lsps", lsp_arr_json);
area->dynhostname, area->isis);
lsp_count = lsp_print_all(NULL, lsp_arr_json, lspdb,
ui_level, area->dynhostname,
area->isis);
json_object_int_add(json, "count", lsp_count); json_object_int_add(json, "count", lsp_count);
} }