1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
pyroute2-cli
============
Synopsis
--------
cat script_file | **pyroute2-cli** [options]
**pyroute2-cli** [options] script_file
Description
-----------
**pyroute2-cli** is an interface towards pyroute2 NDB -- network database.
It can provide both CLI and HTTP interfaces.
Status
------
**pyroute2-cli** is a proof-of-concept for now, it has some auth framework,
but no support for SSL. Don't hesitate to file feature requests and bugs on
the project page.
Options
-------
.. program:: pyroute2-cli
.. option:: -m <C|S>
Mode to use: C (cli, by default) or S (server)
.. rubric:: **CLI mode options**
.. option:: -c <cmd>
Command line to run
.. option:: -r <file>
An rc file to load before the session
.. option:: -s <file>
Load sources spec from a JSON file
.. option:: -l <spec>
Log spec
.. rubric:: **Server mode options**
.. option:: -a <ipaddr>
IP address to listen on
.. option:: -p <port>
TCP port to listen on
.. option:: -s <file>
Load sources spec from a JSON file
.. option:: -l <spec>
Log spec
Examples
--------
Running CLI:
.. code-block:: bash
# bring eth0 up and add an IP address
pyroute2-cli -l debug -c "interfaces eth0 set { state up } => add_ip { 10.0.0.2/24 } => commit"
# same via stdin + pipe:
cat <<EOF | pyroute2-cli
> interfaces eth0
> set { state up }
> add_ip { 10.0.0.2/24 }
> commit
> EOF
# run a script from a file script.pr2:
interfaces eth0
set { state up }
add_ip { 10.0.0.2/24 }
commit
pyroute2-cli -l debug script.pr2
The server mode:
.. code-block:: bash
# start the server
pyroute2-cli -l debug -m S -a 127.0.0.1 -p 8080
# run a request
# text/plain: send a text script to the server
curl \
-H "Content-Type: text/plain" \
-d "neighbours summary | format json" \
http://localhost:8080/v1/
# application/json: send a script as a JSON data
curl \
-H "Content-Type: application/json" \
-d '{"commands": ["neighbours summary | format json"]}'
http://localhost:8080/v1/
curl \
-H "Content-Type: application/json" \
-d '{"commands": ["interfaces eth0", "set state down", "commit"]}'
http://localhost:8080/v1/
|