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

-m <C|S>

Mode to use: C (cli, by default) or S (server)

CLI mode options

-c <cmd>

Command line to run

-r <file>

An rc file to load before the session

-s <file>

Load sources spec from a JSON file

-l <spec>

Log spec

Server mode options

-a <ipaddr>

IP address to listen on

-p <port>

TCP port to listen on

-s <file>

Load sources spec from a JSON file

-l <spec>

Log spec

Examples

Running CLI:

# 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:

# 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/