Example: added cli pipe

This commit is contained in:
Olof hagsand 2024-04-09 14:20:45 +02:00
parent 826a4c3fb3
commit f9faf1039a
8 changed files with 72 additions and 28 deletions

View file

@ -1371,6 +1371,7 @@ cli_pagination(clixon_handle h,
cxobj **xvec = NULL;
size_t xlen;
int locked = 0;
int argc = 0;
if (cvec_len(argv) != 5){
clixon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <limit>");
@ -1380,14 +1381,12 @@ cli_pagination(clixon_handle h,
if ((cv = cvec_find(cvv, "xpath")) != NULL)
xpath = cv_string_get(cv);
else
xpath = cvec_i_str(argv, 0);
prefix = cvec_i_str(argv, 1);
namespace = cvec_i_str(argv, 2);
str = cv_string_get(cvec_i(argv, 3)); /* Fourthformat: output format */
if ((int)(format = format_str2int(str)) < 0){
clixon_err(OE_PLUGIN, 0, "Not valid format: %s", str);
xpath = cvec_i_str(argv, argc);
argc++;
prefix = cvec_i_str(argv, argc++);
namespace = cvec_i_str(argv, argc++);
if (cli_show_option_format(h, argv, argc++, &format) < 0)
goto done;
}
if ((str = cv_string_get(cvec_i(argv, 4))) != NULL){
if (parse_uint32(str, &limit, NULL) < 1){
clixon_err(OE_UNIX, errno, "error parsing limit:%s", str);

View file

@ -104,6 +104,7 @@ all: $(PLUGINS)
$(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $<
CLISPECS = $(APPNAME)_cli.cli
CLISPECS += $(APPNAME)_pipe.cli
YANGSPECS = clixon-example@2022-11-01.yang

View file

@ -94,13 +94,9 @@ show("Show a particular state of the system"){
xml("Show comparison in xml"), compare_dbs("running", "candidate", "xml");
text("Show comparison in text"), compare_dbs("running", "candidate", "text");
}
pagination("Show list pagination") xpath("Show configuration") <xpath:string>("XPATH expression"){
xml, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "xml", "10");
cli, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "cli", "10");
text, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "text", "10");
json, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "json", "10");
}
pagination("Show list pagination") xpath("Show configuration") <xpath:string>("XPATH expression"), cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "default", "10");
configuration("Show configuration"), cli_show_auto_mode("candidate", "default", true, false, "explicit", "set ");{
@|example_pipe, cli_show_auto_mode("candidate", "xml", true, false, "explicit");
default("With-default mode"){
report-all, cli_show_auto_mode("candidate", "default", true, false, "report-all");
trim, cli_show_auto_mode("candidate", "default", true, false, "trim");
@ -111,7 +107,7 @@ show("Show a particular state of the system"){
}
}
state("Show configuration and state"), cli_show_auto_mode("running", "default", true, true); {
xml("Show configuration and state as XML"), cli_show_auto_mode("running", "default", true, true);{
@|example_pipe, cli_show_auto_mode("running", "xml", true, true);
default("With-default mode"){
report-all, cli_show_auto_mode("running", "default", true, true, "report-all");
trim, cli_show_auto_mode("running", "default", true, true, "trim");
@ -121,7 +117,6 @@ show("Show a particular state of the system"){
report-all-tagged-strip, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-strip");
}
}
}
yang("Show yang specs"), show_yang(); {
clixon-example("Show clixon-example yang spec"), show_yang("clixon-example");
}

View file

@ -0,0 +1,47 @@
# ***** BEGIN LICENSE BLOCK *****
#
# Copyright (C) 2024 Olof Hagsand
#
# This file is part of CLIXON
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Alternatively, the contents of this file may be used under the terms of
# the GNU General Public License Version 3 or later (the "GPL"),
# in which case the provisions of the GPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of the GPL, and not to allow others to
# use your version of this file under the terms of Apache License version 2,
# indicate your decision by deleting the provisions above and replace them with
# the notice and other provisions required by the GPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the Apache License version 2 or the GPL.
#
# ***** END LICENSE BLOCK *****
# Clixon pipe example specification
CLICON_MODE="|example_pipe"; # Must start with |
\| {
grep("Search for pattern") <arg:string>, pipe_grep_fn("-e", "arg");
except("Inverted search") <arg:string>, pipe_grep_fn("-v", "arg");
tail("Output last part") <arg:string>, pipe_tail_fn("-n", "arg");
count("Line count"), pipe_wc_fn("-l");
show("Show other format") {
cli("set Input cli syntax"), pipe_showas_fn("cli", true, "set ");
xml("XML"), pipe_showas_fn("xml", true);
json("JSON"), pipe_showas_fn("json");
text("Text curly braces"), pipe_showas_fn("text");
}
# save("Save configuration to file") <filename:string>("Filename (local filename)"), save_config_file("candidate","filename", "xml"); # XXX
}

View file

@ -50,6 +50,7 @@ cat <<EOF > $cfg
<CLICON_STREAM_DISCOVERY_RFC8040>true</CLICON_STREAM_DISCOVERY_RFC8040>
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
<CLICON_CLI_OUTPUT_FORMAT>cli</CLICON_CLI_OUTPUT_FORMAT>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
<CLICON_VALIDATE_STATE_XML>$validatexml</CLICON_VALIDATE_STATE_XML>
</clixon-config>

View file

@ -28,7 +28,7 @@ set timeout 15
spawn {*}$clixon_cli -f $cfg
send "show pagination xpath $xpath cli\n"
send "show pagination xpath $xpath\n"
expect {
timeout { send_user "\n$line1 not received.\n"; exit 1}

View file

@ -45,6 +45,7 @@ cat <<EOF > $cfg
<CLICON_STREAM_DISCOVERY_RFC8040>true</CLICON_STREAM_DISCOVERY_RFC8040>
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
<CLICON_CLI_OUTPUT_FORMAT>cli</CLICON_CLI_OUTPUT_FORMAT>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
<CLICON_VALIDATE_STATE_XML>$validatexml</CLICON_VALIDATE_STATE_XML>
</clixon-config>

View file

@ -179,7 +179,7 @@ done } 2>&1 | awk '/real/ {print $2}'
# CLI get
cat <<EOF >> $fin
edit interfaces a foo b interface e1
show state xml
show state
EOF
new "cli get test single req"
expectpart "$($clixon_cli -F $fin -f $cfg)" 0 "<name>e1</name>" "<type>eth</type>" "<status>up</status>$"
@ -187,7 +187,7 @@ expectpart "$($clixon_cli -F $fin -f $cfg)" 0 "<name>e1</name>" "<type>eth</type
new "cli get $perfreq single reqs"
{ time -p for (( i=0; i<$perfreq; i++ )); do
rnd=$(( ( RANDOM % $perfnr ) ))
$clixon_cli -1 -f $cfg show state xml interfaces a b interface e$rnd > /dev/null
$clixon_cli -1 -f $cfg show state interfaces a b interface e$rnd > /dev/null
done } 2>&1 | awk '/real/ {print $2}'
# Get config in one large get
@ -199,7 +199,7 @@ new "restconf get large config"
$TIMEFN curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example:interfaces/a=foo/b 2>&1 | awk '/real/ {print $2}'
new "cli get large config"
$TIMEFN $clixon_cli -1f $cfg show state xml interfaces a foo b 2>&1 | awk '/real/ {print $2}'
$TIMEFN $clixon_cli -1f $cfg show state interfaces a foo b 2>&1 | awk '/real/ {print $2}'
# mem test needs sleep here
new "wait restconf"