Skip to content

Commit

Permalink
Merge pull request FRRouting#18 from ranjanyash54/delete_config
Browse files Browse the repository at this point in the history
cmgd: delete-config command
  • Loading branch information
pushpasis authored Aug 19, 2021
2 parents 54e39de + b423a4c commit 5e8e865
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
39 changes: 31 additions & 8 deletions cmgd/cmgd_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,41 @@ DEFPY(cmgd_commit_abort,
}

DEFPY(cmgd_set_config_data,
cmgd_set_config_data_cmd,
"cmgd set-config xpath WORD$path value WORD$val",
CMGD_STR
"Set configuration data\n"
"XPath expression specifying the YANG data path\n"
"XPath string\n"
"Value of the data to set to\n"
"<value of the data>\n")
cmgd_set_config_data_cmd,
"cmgd set-config xpath WORD$path value WORD$val",
CMGD_STR
"Set configuration data\n"
"XPath expression specifying the YANG data path\n"
"XPath string\n"
"Value of the data to set to\n"
"<value of the data>\n")
{

strlcpy(vty->cfg_changes[0].xpath, path,
sizeof(vty->cfg_changes[0].xpath));
vty->cfg_changes[0].value = val;
vty->cfg_changes[0].operation = NB_OP_CREATE;
vty->num_cfg_changes = 1;

vty_cmgd_send_config_data(vty);
return CMD_SUCCESS;
}

DEFPY(cmgd_delete_config_data,
cmgd_delete_config_data_cmd,
"cmgd delete-config xpath WORD$path",
CMGD_STR
"Delete configuration data\n"
"XPath expression specifying the YANG data path\n"
"XPath string\n")
{

strlcpy(vty->cfg_changes[0].xpath, path,
sizeof(vty->cfg_changes[0].xpath));
vty->cfg_changes[0].value = NULL;
vty->cfg_changes[0].operation = NB_OP_DESTROY;
vty->num_cfg_changes = 1;

vty_cmgd_send_config_data(vty);
return CMD_SUCCESS;
}
Expand Down Expand Up @@ -444,6 +466,7 @@ void cmgd_vty_init(void)
install_element(CONFIG_NODE, &cmgd_lock_db_cand_cmd);
install_element(CONFIG_NODE, &cmgd_unlock_db_cand_cmd);
install_element(CONFIG_NODE, &cmgd_set_config_data_cmd);
install_element(CONFIG_NODE, &cmgd_delete_config_data_cmd);

/*
* TODO: Register and handlers for auto-completion here.
Expand Down
17 changes: 17 additions & 0 deletions lib/northbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,16 @@ int nb_candidate_edit(struct nb_config *candidate,
return NB_OK;
}

static bool nb_is_operation_allowed(struct nb_node *nb_node, struct nb_cfg_change *change)
{
enum nb_operation oper = change->operation;
if(lysc_is_key(nb_node->snode)) {
if (oper == NB_OP_MODIFY || oper == NB_OP_DESTROY)
return false;
}
return true;
}

void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
struct nb_cfg_change cfg_changes[],
size_t num_cfg_changes,
Expand Down Expand Up @@ -787,6 +797,13 @@ void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
*error = true;
continue;
}
/* Find if the node to be edited is not a key node */
if (!nb_is_operation_allowed(nb_node, change))
{
zlog_err(" Xpath %s points to key node", xpath);
*error = true;
break;
}

/* If the value is not set, get the default if it exists. */
if (change->value == NULL)
Expand Down

0 comments on commit 5e8e865

Please sign in to comment.