skip+count

This commit is contained in:
Olof hagsand 2020-11-09 11:54:23 +01:00
parent 8008fa01b7
commit 8e266dd136
2 changed files with 30 additions and 13 deletions

View file

@ -1497,6 +1497,7 @@ from_client_get_pageable_list(clicon_handle h,
}
if ((xtop = xml_new("top", NULL, CX_ELMNT)) == NULL)
goto done;
/* Parse xpath -> stuctured path tree */
if ((ret = clixon_instance_id_parse(yspec, &path_tree, "%s", xpath)) < 0)
goto done;
if (ret == 0){
@ -1504,12 +1505,13 @@ from_client_get_pageable_list(clicon_handle h,
goto done;
goto ok;
}
/* get last element */
/* get last element of path, eg /a/b/c, get c */
if ((cp = PREVQ(clixon_path *, path_tree)) == NULL){
if (netconf_bad_element(cbret, "application", "list-target", "path invalid") < 0)
goto done;
goto ok;
}
/* get yang of last element */
if ((y = cp->cp_yang) == NULL){
if (netconf_bad_element(cbret, "application", "list-target", "No yang associated with path") < 0)
goto done;
@ -1520,7 +1522,10 @@ from_client_get_pageable_list(clicon_handle h,
goto done;
goto ok;
}
/* Build a "predicate" cbuf */
/* Build a "predicate" cbuf
* This solution uses xpath predicates to translate "count" and "skip" to
* relational operators <>.
*/
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
@ -1529,9 +1534,9 @@ from_client_get_pageable_list(clicon_handle h,
if (where)
cprintf(cb, "[%s]", where);
if (skip){
cprintf(cb, "[%u < position()", skip);
cprintf(cb, "[%u <= position()", skip);
if (count)
cprintf(cb, " && position() < %u", count+skip);
cprintf(cb, " and position() < %u", count+skip);
cprintf(cb, "]");
}
else if (count)

View file

@ -56,14 +56,22 @@ cat <<'EOF' > $dir/startup_db
<number>2</number>
<number>3</number>
</preference>
<skill>
<name>Problem Solving</name>
<rank>98</rank>
</skill>
<skill>
<name>Conflict Resolution</name>
<rank>93</rank>
</skill>
<skill>
<name>Management</name>
<rank>23</rank>
</skill>
<skill>
<name>Organization</name>
<rank>44</rank>
</skill>
<skill>
<name>Problem Solving</name>
<rank>98</rank>
</skill>
</admin>
<admin>
<name>Joe</name>
@ -296,13 +304,17 @@ if [ $RC -ne 0 ]; then
wait_restconf
fi
# draft-wwlh-netconf-list-pagination-nc-00.txt
new "C.1. 'count' Parameter NETCONF"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><get-pageable-list xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination\"><datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore><list-target xmlns:exm=\"http://example.com/ns/example-module\">/exm:admins/exm:admin[exm:name='Bob']/exm:skill</list-target><count>2</count></get-pageable-list></rpc>]]>]]>" '<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><pageable-list xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination"><skill xmlns="http://example.com/ns/example-module"><name>Conflict Resolution</name><rank>93</rank></skill><skill xmlns="http://example.com/ns/example-module"><name>Problem Solving</name><rank>98</rank></skill></pageable-list></rpc-reply>]]>]]>$'
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><get-pageable-list xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination\"><datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore><list-target xmlns:exm=\"http://example.com/ns/example-module\">/exm:admins/exm:admin[exm:name='Bob']/exm:skill</list-target><count>2</count></get-pageable-list></rpc>]]>]]>" '<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><pageable-list xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination"><skill xmlns="http://example.com/ns/example-module"><name>Conflict Resolution</name><rank>93</rank></skill><skill xmlns="http://example.com/ns/example-module"><name>Management</name><rank>23</rank></skill></pageable-list></rpc-reply>]]>]]>$'
new "C.2. 'skip' Parameter NETCONF"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><get-pageable-list xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination\"><datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore><list-target xmlns:exm=\"http://example.com/ns/example-module\">/exm:admins/exm:admin[exm:name='Bob']/exm:skill</list-target><count>2</count><skip>2</skip></get-pageable-list></rpc>]]>]]>" '<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><pageable-list xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination"><skill xmlns="http://example.com/ns/example-module"><name>Organization</name><rank>44</rank></skill><skill xmlns="http://example.com/ns/example-module"><name>Problem Solving</name><rank>98</rank></skill></pageable-list></rpc-reply>]]>]]>$'
# draft-wwlh-netconf-list-pagination-rc-00.txt
#new "A.1. 'count' Parameter RESTCONF"
#expectpart "$(curl $CURLOPTS -X GET -H "Accept: application/yang.collection+xml" $RCPROTO://localhost/restconf/data/example-module:get-list-pagination/library/artist=Foo%20Fighters/album/?count=2)" 0 "HTTP/1.1 200 OK" "application/yang.collection+xml" '<collection xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-collection"><album xmlns="http://example.com/ns/example-jukebox"><name>Crime and Punishment</name><year>1995</year></album><album xmlns="http://example.com/ns/example-jukebox"><name>One by One</name><year>2002</year></album></collection>'
if false; then # XXX notyet
new "C.1. 'count' Parameter RESTCONF"
expectpart "$(curl $CURLOPTS -X GET -H "Accept: application/yang.collection+xml" $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/library/artist=Foo%20Fighters/album/?count=2)" 0 "HTTP/1.1 200 OK" "application/yang.collection+xml" '<collection xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-collection"><album xmlns="http://example.com/ns/example-jukebox"><name>Crime and Punishment</name><year>1995</year></album><album xmlns="http://example.com/ns/example-jukebox"><name>One by One</name><year>2002</year></album></collection>'
fi
if [ $RC -ne 0 ]; then
new "Kill restconf daemon"
stop_restconf