Skip to content

Commit

Permalink
Merge pull request FRRouting#24 from ranjanyash54/dump_in_file
Browse files Browse the repository at this point in the history
cmgd: Dump tree into file
  • Loading branch information
pushpasis authored Aug 25, 2021
2 parents 9f7a857 + 99aaf21 commit 24740d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
12 changes: 9 additions & 3 deletions cmgd/cmgd_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ int cmgd_db_hndl_send_get_data_req(

void cmgd_db_dump_tree(
struct vty *vty, cmgd_db_hndl_t db_hndl, const char* xpath,
LYD_FORMAT format)
FILE *f, LYD_FORMAT format)
{
cmgd_db_ctxt_t *db_ctxt;
struct ly_out *out;
Expand All @@ -538,10 +538,16 @@ void cmgd_db_dump_tree(
cmgd_remove_trailing_separator(base_xpath, '/');
}

ly_out_new_memory(&str, 0, &out);
if (f)
ly_out_new_file(f, &out);
else
ly_out_new_memory(&str, 0, &out);

cmgd_db_dump_in_memory(db_hndl, base_xpath, format, out);

vty_out(vty, "%s", str);
if (!f)
vty_out(vty, "%s", str);

ly_out_free(out, NULL, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion cmgd/cmgd_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ extern int cmgd_db_hndl_send_get_data_req(
cmgd_yang_getdata_req_t *data_req, int num_reqs);
extern void cmgd_db_dump_tree(
struct vty *vty, cmgd_db_hndl_t db_hndl, const char* xpath,
LYD_FORMAT format);
FILE *f, LYD_FORMAT format);

extern void cmgd_db_status_write_one(
struct vty *vty, cmgd_db_hndl_t db_hndl);
Expand Down
19 changes: 17 additions & 2 deletions cmgd/cmgd_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,20 +418,23 @@ DEFPY(show_cmgd_get_data,

DEFPY(show_cmgd_dump_data,
show_cmgd_dump_data_cmd,
"show cmgd database-contents db-name WORD$dbname [xpath WORD$path] format WORD$format_str",
"show cmgd database-contents db-name WORD$dbname [xpath WORD$path] [filepath WORD$filepath] format WORD$format_str",
SHOW_STR
CMGD_STR
"Get Database Contenents from a specific database\n"
"DB name\n"
"<candidate running operational\n"
"XPath expression specifying the YANG data path\n"
"XPath string\n"
"Path to the file\n"
"Path string\n"
"Format the output\n"
"JSON|XML")
{
cmgd_database_id_t database = CMGD_DB_CANDIDATE;
cmgd_db_hndl_t db_hndl;
LYD_FORMAT format = LYD_UNKNOWN;
FILE *f = NULL;

database = cmgd_db_name2id(dbname);

Expand All @@ -447,14 +450,26 @@ DEFPY(show_cmgd_dump_data,
return CMD_ERR_NO_MATCH;
}

if (filepath) {
f = fopen(filepath, "w");
if (!f) {
vty_out(vty, "Could not open file pointed by filepath %s\n",
filepath);
return CMD_SUCCESS;
}
}

format = cmgd_str2format(format_str);
if (format == LYD_UNKNOWN) {
vty_out(vty, "String Format %s does not matches existing format\n",
format_str);
return CMD_SUCCESS;
}

cmgd_db_dump_tree(vty, db_hndl, path, format);
cmgd_db_dump_tree(vty, db_hndl, path, f, format);

if (f)
fclose(f);
return CMD_SUCCESS;
}

Expand Down

0 comments on commit 24740d4

Please sign in to comment.