Example: added cli pipe
This commit is contained in:
parent
826a4c3fb3
commit
f9faf1039a
8 changed files with 72 additions and 28 deletions
|
|
@ -1371,6 +1371,7 @@ cli_pagination(clixon_handle h,
|
||||||
cxobj **xvec = NULL;
|
cxobj **xvec = NULL;
|
||||||
size_t xlen;
|
size_t xlen;
|
||||||
int locked = 0;
|
int locked = 0;
|
||||||
|
int argc = 0;
|
||||||
|
|
||||||
if (cvec_len(argv) != 5){
|
if (cvec_len(argv) != 5){
|
||||||
clixon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <limit>");
|
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)
|
if ((cv = cvec_find(cvv, "xpath")) != NULL)
|
||||||
xpath = cv_string_get(cv);
|
xpath = cv_string_get(cv);
|
||||||
else
|
else
|
||||||
xpath = cvec_i_str(argv, 0);
|
xpath = cvec_i_str(argv, argc);
|
||||||
prefix = cvec_i_str(argv, 1);
|
argc++;
|
||||||
namespace = cvec_i_str(argv, 2);
|
prefix = cvec_i_str(argv, argc++);
|
||||||
str = cv_string_get(cvec_i(argv, 3)); /* Fourthformat: output format */
|
namespace = cvec_i_str(argv, argc++);
|
||||||
if ((int)(format = format_str2int(str)) < 0){
|
if (cli_show_option_format(h, argv, argc++, &format) < 0)
|
||||||
clixon_err(OE_PLUGIN, 0, "Not valid format: %s", str);
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
|
||||||
if ((str = cv_string_get(cvec_i(argv, 4))) != NULL){
|
if ((str = cv_string_get(cvec_i(argv, 4))) != NULL){
|
||||||
if (parse_uint32(str, &limit, NULL) < 1){
|
if (parse_uint32(str, &limit, NULL) < 1){
|
||||||
clixon_err(OE_UNIX, errno, "error parsing limit:%s", str);
|
clixon_err(OE_UNIX, errno, "error parsing limit:%s", str);
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,8 @@ all: $(PLUGINS)
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $<
|
$(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $<
|
||||||
|
|
||||||
CLISPECS = $(APPNAME)_cli.cli
|
CLISPECS = $(APPNAME)_cli.cli
|
||||||
|
CLISPECS += $(APPNAME)_pipe.cli
|
||||||
|
|
||||||
YANGSPECS = clixon-example@2022-11-01.yang
|
YANGSPECS = clixon-example@2022-11-01.yang
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,13 +94,9 @@ show("Show a particular state of the system"){
|
||||||
xml("Show comparison in xml"), compare_dbs("running", "candidate", "xml");
|
xml("Show comparison in xml"), compare_dbs("running", "candidate", "xml");
|
||||||
text("Show comparison in text"), compare_dbs("running", "candidate", "text");
|
text("Show comparison in text"), compare_dbs("running", "candidate", "text");
|
||||||
}
|
}
|
||||||
pagination("Show list pagination") xpath("Show configuration") <xpath:string>("XPATH expression"){
|
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");
|
||||||
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");
|
|
||||||
}
|
|
||||||
configuration("Show configuration"), cli_show_auto_mode("candidate", "default", true, false, "explicit", "set ");{
|
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"){
|
default("With-default mode"){
|
||||||
report-all, cli_show_auto_mode("candidate", "default", true, false, "report-all");
|
report-all, cli_show_auto_mode("candidate", "default", true, false, "report-all");
|
||||||
trim, cli_show_auto_mode("candidate", "default", true, false, "trim");
|
trim, cli_show_auto_mode("candidate", "default", true, false, "trim");
|
||||||
|
|
@ -111,16 +107,15 @@ show("Show a particular state of the system"){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state("Show configuration and state"), cli_show_auto_mode("running", "default", true, true); {
|
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"){
|
default("With-default mode"){
|
||||||
report-all, cli_show_auto_mode("running", "default", true, true, "report-all");
|
report-all, cli_show_auto_mode("running", "default", true, true, "report-all");
|
||||||
trim, cli_show_auto_mode("running", "default", true, true, "trim");
|
trim, cli_show_auto_mode("running", "default", true, true, "trim");
|
||||||
explicit, cli_show_auto_mode("running", "default", true, true, "explicit");
|
explicit, cli_show_auto_mode("running", "default", true, true, "explicit");
|
||||||
report-all-tagged, cli_show_auto_mode("running", "default", true, true, "report-all-tagged");
|
report-all-tagged, cli_show_auto_mode("running", "default", true, true, "report-all-tagged");
|
||||||
report-all-tagged-default, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-default");
|
report-all-tagged-default, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-default");
|
||||||
report-all-tagged-strip, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-strip");
|
report-all-tagged-strip, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-strip");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
yang("Show yang specs"), show_yang(); {
|
yang("Show yang specs"), show_yang(); {
|
||||||
clixon-example("Show clixon-example yang spec"), show_yang("clixon-example");
|
clixon-example("Show clixon-example yang spec"), show_yang("clixon-example");
|
||||||
|
|
|
||||||
47
example/main/example_pipe.cli
Normal file
47
example/main/example_pipe.cli
Normal 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
|
||||||
|
}
|
||||||
|
|
@ -50,6 +50,7 @@ cat <<EOF > $cfg
|
||||||
<CLICON_STREAM_DISCOVERY_RFC8040>true</CLICON_STREAM_DISCOVERY_RFC8040>
|
<CLICON_STREAM_DISCOVERY_RFC8040>true</CLICON_STREAM_DISCOVERY_RFC8040>
|
||||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
<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_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||||
<CLICON_VALIDATE_STATE_XML>$validatexml</CLICON_VALIDATE_STATE_XML>
|
<CLICON_VALIDATE_STATE_XML>$validatexml</CLICON_VALIDATE_STATE_XML>
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ set timeout 15
|
||||||
|
|
||||||
spawn {*}$clixon_cli -f $cfg
|
spawn {*}$clixon_cli -f $cfg
|
||||||
|
|
||||||
send "show pagination xpath $xpath cli\n"
|
send "show pagination xpath $xpath\n"
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
timeout { send_user "\n$line1 not received.\n"; exit 1}
|
timeout { send_user "\n$line1 not received.\n"; exit 1}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ cat <<EOF > $cfg
|
||||||
<CLICON_STREAM_DISCOVERY_RFC8040>true</CLICON_STREAM_DISCOVERY_RFC8040>
|
<CLICON_STREAM_DISCOVERY_RFC8040>true</CLICON_STREAM_DISCOVERY_RFC8040>
|
||||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
<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_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||||
<CLICON_VALIDATE_STATE_XML>$validatexml</CLICON_VALIDATE_STATE_XML>
|
<CLICON_VALIDATE_STATE_XML>$validatexml</CLICON_VALIDATE_STATE_XML>
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ done } 2>&1 | awk '/real/ {print $2}'
|
||||||
# CLI get
|
# CLI get
|
||||||
cat <<EOF >> $fin
|
cat <<EOF >> $fin
|
||||||
edit interfaces a foo b interface e1
|
edit interfaces a foo b interface e1
|
||||||
show state xml
|
show state
|
||||||
EOF
|
EOF
|
||||||
new "cli get test single req"
|
new "cli get test single req"
|
||||||
expectpart "$($clixon_cli -F $fin -f $cfg)" 0 "<name>e1</name>" "<type>eth</type>" "<status>up</status>$"
|
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"
|
new "cli get $perfreq single reqs"
|
||||||
{ time -p for (( i=0; i<$perfreq; i++ )); do
|
{ time -p for (( i=0; i<$perfreq; i++ )); do
|
||||||
rnd=$(( ( RANDOM % $perfnr ) ))
|
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}'
|
done } 2>&1 | awk '/real/ {print $2}'
|
||||||
|
|
||||||
# Get config in one large get
|
# 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}'
|
$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"
|
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
|
# mem test needs sleep here
|
||||||
new "wait restconf"
|
new "wait restconf"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue