experimental netconf yang spec
This commit is contained in:
parent
822aac18a1
commit
056b5c97dd
16 changed files with 250 additions and 147 deletions
|
|
@ -74,9 +74,9 @@
|
|||
|
||||
/* Command line options to be passed to getopt(3) */
|
||||
#ifdef BACKEND_STARTUP_COMPAT
|
||||
#define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:IRCrg:py:x:" /* substitute s: for IRCc:r */
|
||||
#define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:IRCrg:y:x:" /* substitute s: for IRCc:r */
|
||||
#else
|
||||
#define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:g:py:x:" /* substitute s: for IRCc:r */
|
||||
#define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:g:y:x:" /* substitute s: for IRCc:r */
|
||||
#endif
|
||||
|
||||
/*! Terminate. Cannot use h after this */
|
||||
|
|
@ -148,7 +148,6 @@ usage(char *argv0, clicon_handle h)
|
|||
" -C\t\tCall plugin_reset() in plugins to reset system state in candidate db (use with -I)\n"
|
||||
" -r\t\tReload running database\n"
|
||||
#endif /* BACKEND_STARTUP_COMPAT */
|
||||
" -p \t\tPrint database yang specification\n"
|
||||
" -g <group>\tClient membership required to this group (default: %s)\n"
|
||||
" -y <file>\tOverride yang spec file (dont include .yang suffix)\n"
|
||||
" -x <plugin>\tXMLDB plugin\n",
|
||||
|
|
@ -611,7 +610,6 @@ main(int argc, char **argv)
|
|||
struct stat st;
|
||||
clicon_handle h;
|
||||
int help = 0;
|
||||
int printspec = 0;
|
||||
int pid;
|
||||
char *pidfile;
|
||||
char *sock;
|
||||
|
|
@ -736,9 +734,6 @@ main(int argc, char **argv)
|
|||
case 'g': /* config socket group */
|
||||
clicon_option_str_set(h, "CLICON_SOCK_GROUP", optarg);
|
||||
break;
|
||||
case 'p' : /* Print spec */
|
||||
printspec++;
|
||||
break;
|
||||
case 'y' :{ /* Override yang module or absolute filename */
|
||||
clicon_option_str_set(h, "CLICON_YANG_MODULE_MAIN", optarg);
|
||||
break;
|
||||
|
|
@ -823,7 +818,7 @@ main(int argc, char **argv)
|
|||
if (xmldb_connect(h) < 0)
|
||||
goto done;
|
||||
/* Parse db spec file */
|
||||
if (yang_spec_main(h, stdout, printspec) < 0)
|
||||
if (yang_spec_main(h) == NULL)
|
||||
goto done;
|
||||
|
||||
/* Set options: database dir and yangspec (could be hidden in connect?)*/
|
||||
|
|
|
|||
|
|
@ -242,9 +242,9 @@ main(int argc, char **argv)
|
|||
int logdst = CLICON_LOG_STDERR;
|
||||
char *restarg = NULL; /* what remains after options */
|
||||
int dump_configfile_xml = 0;
|
||||
|
||||
yang_spec *yspec;
|
||||
|
||||
/* Defaults */
|
||||
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
|
||||
/* Initiate CLICON handle */
|
||||
|
|
@ -397,20 +397,17 @@ main(int argc, char **argv)
|
|||
cv_exclude_keys(clicon_cli_varonly(h));
|
||||
|
||||
/* Parse db specification as cli*/
|
||||
if (yang_spec_main(h, stdout, printspec) < 0)
|
||||
if ((yspec = yang_spec_main(h)) == NULL)
|
||||
goto done;
|
||||
if (printspec)
|
||||
yang_print(stdout, (yang_node*)yspec);
|
||||
|
||||
/* Create tree generated from dataspec. If no other trees exists, this is
|
||||
* the only one.
|
||||
*/
|
||||
if (clicon_cli_genmodel(h)){
|
||||
yang_spec *yspec; /* yang spec */
|
||||
parse_tree pt = {0,}; /* cli parse tree */
|
||||
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_FATAL, 0, "No YANG DB_SPEC");
|
||||
goto done;
|
||||
}
|
||||
/* Create cli command tree from dbspec */
|
||||
if (yang2cli(h, yspec, &pt, clicon_cli_genmodel_type(h)) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ process_incoming_packet(clicon_handle h,
|
|||
}
|
||||
str = str0;
|
||||
/* Parse incoming XML message */
|
||||
if (clicon_xml_parse_str(str, NULL, &xreq) < 0){
|
||||
if (clicon_xml_parse_str(str, NULL, &xreq) < 0){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
cprintf(cbret, "<rpc-reply><rpc-error>"
|
||||
"<error-tag>operation-failed</error-tag>"
|
||||
|
|
@ -114,9 +114,8 @@ process_incoming_packet(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
free(str0);
|
||||
if ((xrpc=xpath_first(xreq, "//rpc")) != NULL){
|
||||
if ((xrpc=xpath_first(xreq, "//rpc")) != NULL)
|
||||
isrpc++;
|
||||
}
|
||||
else
|
||||
if (xpath_first(xreq, "//hello") != NULL)
|
||||
;
|
||||
|
|
@ -215,9 +214,10 @@ netconf_input_cb(int s,
|
|||
buf[i],
|
||||
&xml_state)) {
|
||||
/* OK, we have an xml string from a client */
|
||||
if (process_incoming_packet(h, cb) < 0){
|
||||
/* Remove trailer */
|
||||
*(((char*)cbuf_get(cb)) + cbuf_len(cb) - strlen("]]>]]>")) = '\0';
|
||||
if (process_incoming_packet(h, cb) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (cc_closed)
|
||||
break;
|
||||
cbuf_reset(cb);
|
||||
|
|
@ -268,7 +268,6 @@ netconf_terminate(clicon_handle h)
|
|||
{
|
||||
yang_spec *yspec;
|
||||
|
||||
|
||||
clicon_rpc_close_session(h);
|
||||
if ((yspec = clicon_dbspec_yang(h)) != NULL)
|
||||
yspec_free(yspec);
|
||||
|
|
@ -302,7 +301,8 @@ usage(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc,
|
||||
char **argv)
|
||||
{
|
||||
char c;
|
||||
char *tmp;
|
||||
|
|
@ -337,7 +337,6 @@ main(int argc, char **argv)
|
|||
use_syslog = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Logs, error and debug to stderr or syslog, set debug level
|
||||
*/
|
||||
|
|
@ -379,13 +378,18 @@ main(int argc, char **argv)
|
|||
argv += optind;
|
||||
|
||||
/* Parse yang database spec file */
|
||||
if (yang_spec_main(h, stdout, 0) < 0)
|
||||
if (yang_spec_main(h) == NULL)
|
||||
goto done;
|
||||
|
||||
/* Parse netconf yang spec file */
|
||||
if (yang_spec_netconf(h) == NULL)
|
||||
goto done;
|
||||
|
||||
/* Initialize plugins group */
|
||||
if (netconf_plugin_load(h) < 0)
|
||||
return -1;
|
||||
goto done;
|
||||
|
||||
|
||||
/* Call start function is all plugins before we go interactive */
|
||||
tmp = *(argv-1);
|
||||
*(argv-1) = argv0;
|
||||
|
|
|
|||
|
|
@ -196,7 +196,6 @@ catch:
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*! See if there is any callback registered for this tag
|
||||
*
|
||||
|
|
@ -215,7 +214,7 @@ netconf_plugin_callbacks(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
netconf_reg_t *nreg;
|
||||
yang_spec *yspec;
|
||||
yang_spec *yspec = NULL; /* application yspec */
|
||||
yang_stmt *yrpc;
|
||||
yang_stmt *yinput;
|
||||
yang_stmt *youtput;
|
||||
|
|
@ -234,19 +233,32 @@ netconf_plugin_callbacks(clicon_handle h,
|
|||
nreg = NEXTQ(netconf_reg_t *, nreg);
|
||||
} while (nreg != deps);
|
||||
}
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
/* First check system / netconf RPC:s */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, 0, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* create absolute path */
|
||||
cprintf(cb, "/%s:%s", xml_namespace(xn), xml_name(xn));
|
||||
if (xml_namespace(xn))
|
||||
cprintf(cb, "/%s:%s", xml_namespace(xn), xml_name(xn));
|
||||
else
|
||||
cprintf(cb, "/nc:%s", xml_name(xn)); /* Hardcoded for netconf */
|
||||
/* Find yang rpc statement, return yang rpc statement if found */
|
||||
if (yang_abs_schema_nodeid(yspec, cbuf_get(cb), &yrpc) < 0)
|
||||
goto done;
|
||||
if (yrpc == NULL){
|
||||
/* Then check application RPC */
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
cbuf_reset(cb);
|
||||
if (xml_namespace(xn))
|
||||
cprintf(cb, "/%s:%s", xml_namespace(xn), xml_name(xn));
|
||||
else
|
||||
cprintf(cb, "/%s", xml_name(xn)); /* XXX not accepdted by below */
|
||||
/* Find yang rpc statement, return yang rpc statement if found */
|
||||
if (yang_abs_schema_nodeid(yspec, cbuf_get(cb), &yrpc) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Check if found */
|
||||
if (yrpc != NULL){
|
||||
if ((yinput = yang_find((yang_node*)yrpc, Y_INPUT, NULL)) != NULL){
|
||||
|
|
|
|||
|
|
@ -856,51 +856,85 @@ netconf_create_subscription(clicon_handle h,
|
|||
* @param[in] h clicon handle
|
||||
* @param[in] xn Sub-tree (under xorig) at <rpc>...</rpc> level.
|
||||
* @param[out] xret Return XML, error or OK
|
||||
* @retval 0 OK, can also be netconf error
|
||||
* @retval -1 Error, fatal
|
||||
*/
|
||||
int
|
||||
netconf_rpc_dispatch(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xe;
|
||||
int ret = 0;
|
||||
yang_spec *yspec = NULL;
|
||||
|
||||
/* Check incoming RPC against system / netconf RPC:s */
|
||||
if ((yspec = clicon_netconf_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No netconf yang spec");
|
||||
goto done;
|
||||
}
|
||||
xe = NULL;
|
||||
while ((xe = xml_child_each(xn, xe, CX_ELMNT)) != NULL) {
|
||||
if (strcmp(xml_name(xe), "get-config") == 0)
|
||||
return netconf_get_config(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "edit-config") == 0)
|
||||
return netconf_edit_config(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "copy-config") == 0)
|
||||
return netconf_copy_config(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "delete-config") == 0)
|
||||
return netconf_delete_config(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "lock") == 0)
|
||||
return netconf_lock(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "unlock") == 0)
|
||||
return netconf_unlock(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "get") == 0)
|
||||
return netconf_get(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "close-session") == 0)
|
||||
return netconf_close_session(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "kill-session") == 0)
|
||||
return netconf_kill_session(h, xe, xret);
|
||||
if (strcmp(xml_name(xe), "get-config") == 0){
|
||||
if (netconf_get_config(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "edit-config") == 0){
|
||||
if (netconf_edit_config(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "copy-config") == 0){
|
||||
if (netconf_copy_config(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "delete-config") == 0){
|
||||
if (netconf_delete_config(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "lock") == 0) {
|
||||
if (netconf_lock(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "unlock") == 0){
|
||||
if (netconf_unlock(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "get") == 0){
|
||||
if (netconf_get(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "close-session") == 0){
|
||||
if (netconf_close_session(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "kill-session") == 0) {
|
||||
if (netconf_kill_session(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Validate capability :validate */
|
||||
else if (strcmp(xml_name(xe), "validate") == 0)
|
||||
return netconf_validate(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "validate") == 0){
|
||||
if (netconf_validate(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Candidate configuration capability :candidate */
|
||||
else if (strcmp(xml_name(xe), "commit") == 0)
|
||||
return netconf_commit(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "discard-changes") == 0)
|
||||
return netconf_discard_changes(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "commit") == 0){
|
||||
if (netconf_commit(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "discard-changes") == 0){
|
||||
if (netconf_discard_changes(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* RFC 5277 :notification */
|
||||
else if (strcmp(xml_name(xe), "create-subscription") == 0)
|
||||
return netconf_create_subscription(h, xe, xret);
|
||||
else if (strcmp(xml_name(xe), "create-subscription") == 0){
|
||||
if (netconf_create_subscription(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Others */
|
||||
else{
|
||||
if ((ret = netconf_plugin_callbacks(h, xe, xret)) < 0)
|
||||
return -1;
|
||||
if (ret == 0){ /* not handled by callback */
|
||||
else {
|
||||
if ((retval = netconf_plugin_callbacks(h, xe, xret)) < 0)
|
||||
goto done;
|
||||
if (retval == 0){ /* not handled by callback */
|
||||
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
|
||||
"<error-tag>operation-failed</error-tag>"
|
||||
"<error-type>rpc</error-type>"
|
||||
|
|
@ -908,10 +942,11 @@ netconf_rpc_dispatch(clicon_handle h,
|
|||
"<error-message>%s</error-message>"
|
||||
"<error-info>Not recognized</error-info>"
|
||||
"</rpc-error></rpc-reply>", xml_name(xe));
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ main(int argc,
|
|||
return -1;
|
||||
|
||||
/* Parse yang database spec file */
|
||||
if (yang_spec_main(h, NULL, 0) < 0)
|
||||
if (yang_spec_main(h) == NULL)
|
||||
goto done;
|
||||
|
||||
if ((sockpath = clicon_option_str(h, "CLICON_RESTCONF_PATH")) == NULL){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue