RFC8040 4.8.9. RESTCONF with-defaults Query Parameter
This commit is contained in:
parent
9647177165
commit
6bee1746e0
4 changed files with 90 additions and 2 deletions
|
|
@ -124,6 +124,7 @@ api_data_get2(clicon_handle h,
|
||||||
cxobj *xtop = NULL;
|
cxobj *xtop = NULL;
|
||||||
cxobj *xbot = NULL;
|
cxobj *xbot = NULL;
|
||||||
yang_stmt *y = NULL;
|
yang_stmt *y = NULL;
|
||||||
|
char *with_defaults = NULL;
|
||||||
|
|
||||||
clicon_debug(1, "%s", __FUNCTION__);
|
clicon_debug(1, "%s", __FUNCTION__);
|
||||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||||
|
|
@ -194,8 +195,13 @@ api_data_get2(clicon_handle h,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ((attr = cvec_find_str(qvec, "with-defaults")) != NULL){
|
||||||
|
clicon_debug(1, "%s with_defaults=%s", __FUNCTION__, attr);
|
||||||
|
with_defaults = attr;
|
||||||
|
}
|
||||||
|
|
||||||
clicon_debug(1, "%s path:%s", __FUNCTION__, xpath);
|
clicon_debug(1, "%s path:%s", __FUNCTION__, xpath);
|
||||||
ret = clicon_rpc_get(h, xpath, nsc, content, depth, &xret);
|
ret = clicon_rpc_get2(h, xpath, nsc, content, depth, with_defaults, &xret);
|
||||||
|
|
||||||
if (ret < 0){
|
if (ret < 0){
|
||||||
if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0)
|
if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0)
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ int clicon_rpc_copy_config(clicon_handle h, char *db1, char *db2);
|
||||||
int clicon_rpc_delete_config(clicon_handle h, char *db);
|
int clicon_rpc_delete_config(clicon_handle h, char *db);
|
||||||
int clicon_rpc_lock(clicon_handle h, char *db);
|
int clicon_rpc_lock(clicon_handle h, char *db);
|
||||||
int clicon_rpc_unlock(clicon_handle h, char *db);
|
int clicon_rpc_unlock(clicon_handle h, char *db);
|
||||||
|
int clicon_rpc_get2(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *with_defaults, cxobj **xret);
|
||||||
int clicon_rpc_get(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, cxobj **xret);
|
int clicon_rpc_get(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, cxobj **xret);
|
||||||
int clicon_rpc_get_pageable_list(clicon_handle h, char *datastore, char *xpath,
|
int clicon_rpc_get_pageable_list(clicon_handle h, char *datastore, char *xpath,
|
||||||
cvec *nsc, netconf_content content, int32_t depth,
|
cvec *nsc, netconf_content content, int32_t depth,
|
||||||
|
|
|
||||||
|
|
@ -858,6 +858,21 @@ clicon_rpc_get(clicon_handle h,
|
||||||
netconf_content content,
|
netconf_content content,
|
||||||
int32_t depth,
|
int32_t depth,
|
||||||
cxobj **xt)
|
cxobj **xt)
|
||||||
|
{
|
||||||
|
return clicon_rpc_get2(h, xpath, nsc, content, depth, NULL, xt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! Same functionality as the 'clicon_rpc_get' function, but with an additional input parameter 'with-defaults'.
|
||||||
|
* @see clicon_rpc_get
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
clicon_rpc_get2(clicon_handle h,
|
||||||
|
char *xpath,
|
||||||
|
cvec *nsc, /* namespace context for filter */
|
||||||
|
netconf_content content,
|
||||||
|
int32_t depth,
|
||||||
|
char *with_defaults,
|
||||||
|
cxobj **xt)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
struct clicon_msg *msg = NULL;
|
struct clicon_msg *msg = NULL;
|
||||||
|
|
@ -897,6 +912,8 @@ clicon_rpc_get(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
cprintf(cb, "/>");
|
cprintf(cb, "/>");
|
||||||
}
|
}
|
||||||
|
if (with_defaults != NULL)
|
||||||
|
cprintf(cb, "<with-defaults xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">%s</with-defaults>", with_defaults);
|
||||||
cprintf(cb, "</get></rpc>");
|
cprintf(cb, "</get></rpc>");
|
||||||
if ((msg = clicon_msg_encode(session_id,
|
if ((msg = clicon_msg_encode(session_id,
|
||||||
"%s", cbuf_get(cb))) == NULL)
|
"%s", cbuf_get(cb))) == NULL)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ APPNAME=example
|
||||||
cfg=$dir/conf_yang.xml
|
cfg=$dir/conf_yang.xml
|
||||||
fyang=$dir/example-default.yang
|
fyang=$dir/example-default.yang
|
||||||
fstate=$dir/state.xml
|
fstate=$dir/state.xml
|
||||||
|
RESTCONFIG=$(restconf_config none false)
|
||||||
|
|
||||||
cat <<EOF > $cfg
|
cat <<EOF > $cfg
|
||||||
<clixon-config xmlns="http://clicon.org/config">
|
<clixon-config xmlns="http://clicon.org/config">
|
||||||
|
|
@ -26,13 +27,16 @@ cat <<EOF > $cfg
|
||||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||||
<CLICON_BACKEND_REGEXP>example_backend.so$</CLICON_BACKEND_REGEXP>
|
<CLICON_BACKEND_REGEXP>example_backend.so$</CLICON_BACKEND_REGEXP>
|
||||||
<CLICON_NETCONF_DIR>/usr/local/lib/$APPNAME/netconf</CLICON_NETCONF_DIR>
|
<CLICON_NETCONF_DIR>/usr/local/lib/$APPNAME/netconf</CLICON_NETCONF_DIR>
|
||||||
<CLICON_RESTCONF_DIR>/usr/local/lib/$APPNAME/restconf</CLICON_RESTCONF_DIR>
|
|
||||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||||
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
||||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||||
<CLICON_XMLDB_PRETTY>false</CLICON_XMLDB_PRETTY>
|
<CLICON_XMLDB_PRETTY>false</CLICON_XMLDB_PRETTY>
|
||||||
|
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR>
|
||||||
|
<CLICON_FEATURE>clixon-restconf:allow-auth-none</CLICON_FEATURE> <!-- Use auth-type=none -->
|
||||||
|
<CLICON_FEATURE>clixon-restconf:fcgi</CLICON_FEATURE>
|
||||||
|
$RESTCONFIG
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -155,6 +159,18 @@ if [ $? -ne 0 ]; then
|
||||||
err "<${DATASTORE_TOP}>$XML</${DATASTORE_TOP}>" "$ret"
|
err "<${DATASTORE_TOP}>$XML</${DATASTORE_TOP}>" "$ret"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $RC -ne 0 ]; then
|
||||||
|
new "kill old restconf daemon"
|
||||||
|
stop_restconf_pre
|
||||||
|
|
||||||
|
new "start restconf daemon"
|
||||||
|
start_restconf -f $cfg
|
||||||
|
fi
|
||||||
|
|
||||||
|
new "wait restconf"
|
||||||
|
wait_restconf
|
||||||
|
|
||||||
|
|
||||||
new "rfc4243 4.3. Capability Identifier"
|
new "rfc4243 4.3. Capability Identifier"
|
||||||
expecteof "$clixon_netconf -ef $cfg" 0 "$DEFAULTHELLO" \
|
expecteof "$clixon_netconf -ef $cfg" 0 "$DEFAULTHELLO" \
|
||||||
"<capability>urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit</capability>"
|
"<capability>urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit</capability>"
|
||||||
|
|
@ -317,6 +333,54 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
</interfaces></data></rpc-reply>" ""
|
</interfaces></data></rpc-reply>" ""
|
||||||
|
|
||||||
|
|
||||||
|
new "rfc8040 4.3. RESTCONF GET"
|
||||||
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/example:interfaces)" \
|
||||||
|
0 \
|
||||||
|
"HTTP/$HVER 200" \
|
||||||
|
"Content-Type: application/yang-data+json" \
|
||||||
|
"Cache-Control: no-cache" \
|
||||||
|
'{"example:interfaces":{"interface":\[{"name":"eth0","mtu":8192,"status":"ok"},{"name":"eth1","mtu":1500,"status":"ok"},{"name":"eth2","mtu":9000,"status":"not feeling so good"},{"name":"eth3","mtu":1500,"status":"waking up"}\]}}'
|
||||||
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example:interfaces)" \
|
||||||
|
0 \
|
||||||
|
"HTTP/$HVER 200" \
|
||||||
|
"Content-Type: application/yang-data+xml" \
|
||||||
|
"Cache-Control: no-cache" \
|
||||||
|
'<interfaces xmlns="http://example.com/ns/interfaces"><interface><name>eth0</name><mtu>8192</mtu><status>ok</status></interface><interface><name>eth1</name><mtu>1500</mtu><status>ok</status></interface><interface><name>eth2</name><mtu>9000</mtu><status>not feeling so good</status></interface><interface><name>eth3</name><mtu>1500</mtu><status>waking up</status></interface></interfaces>'
|
||||||
|
|
||||||
|
new "rfc8040 B.3.9. RESTCONF with-defaults parameter = report-all"
|
||||||
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/example:interfaces/interface=eth1?with-defaults=report-all)" \
|
||||||
|
0 \
|
||||||
|
"HTTP/$HVER 200" \
|
||||||
|
"Content-Type: application/yang-data+json" \
|
||||||
|
"Cache-Control: no-cache" \
|
||||||
|
'{"example:interface":\[{"name":"eth1","mtu":1500,"status":"ok"}\]}'
|
||||||
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example:interfaces/interface=eth1?with-defaults=report-all)" \
|
||||||
|
0 \
|
||||||
|
"HTTP/$HVER 200" \
|
||||||
|
"Content-Type: application/yang-data+xml" \
|
||||||
|
"Cache-Control: no-cache" \
|
||||||
|
'<interface xmlns="http://example.com/ns/interfaces"><name>eth1</name><mtu>1500</mtu><status>ok</status></interface>'
|
||||||
|
|
||||||
|
new "rfc8040 B.3.9. RESTONF with-defaults parameter = explicit"
|
||||||
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/example:interfaces/interface=eth1?with-defaults=explicit)" \
|
||||||
|
0 \
|
||||||
|
"HTTP/$HVER 200" \
|
||||||
|
"Content-Type: application/yang-data+json" \
|
||||||
|
"Cache-Control: no-cache" \
|
||||||
|
'{"example:interface":\[{"name":"eth1","status":"ok"}\]}'
|
||||||
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example:interfaces/interface=eth1?with-defaults=explicit)" \
|
||||||
|
0 \
|
||||||
|
"HTTP/$HVER 200" \
|
||||||
|
"Content-Type: application/yang-data+xml" \
|
||||||
|
"Cache-Control: no-cache" \
|
||||||
|
'<interface xmlns="http://example.com/ns/interfaces"><name>eth1</name><status>ok</status></interface>'
|
||||||
|
|
||||||
|
|
||||||
|
if [ $RC -ne 0 ]; then
|
||||||
|
new "Kill restconf daemon"
|
||||||
|
stop_restconf
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $BE -ne 0 ]; then # Bring your own backend
|
if [ $BE -ne 0 ]; then # Bring your own backend
|
||||||
new "Kill backend"
|
new "Kill backend"
|
||||||
# Check if premature kill
|
# Check if premature kill
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue