natesales / pathvector

Declarative routing platform that automates BGP route optimization and control plane configuration with secure and repeatable routing policy.
https://pathvector.io
MIT License
218 stars 28 forks source link

Feature protocol cmd (restart, reload, enable and disable) #228

Open Dennis-de-Houx opened 5 months ago

Dennis-de-Houx commented 5 months ago

As ask in "[Request] Restart Command #219" I made a PR for this.

Example use of this "module/feature":

# pathvector -t -v protocol reload device1
*******************************************************************************
WARNING: This is a development build. It is not recommended for production use.
Please submit any bugs to https://github.com/natesales/pathvector/issues
*******************************************************************************
DEBU[0000] Loading config from /etc/pathvector.yml
DEBU[0000] Setting PeeringDB endpoint to https://peeringdb.com/api/
DEBU[0000] Loaded 0 ASNs and 0 prefixes into global blocklist
DEBU[0000] Finished loading config
INFO[0000] Starting bird protocol command
DEBU[0000] Connecting to BIRD socket
DEBU[0000] Connected to BIRD socket
DEBU[0000] BIRD init response: BIRD 2.0.12 ready.
DEBU[0000] Sending BIRD command: reload device1
DEBU[0000] Sent BIRD command: reload device1
DEBU[0000] Reading from socket
DEBU[0000] Done reading from socket
DEBU[0000] Command Output: device1: reloading
Command reload succeeded for protocol: device1

And when session doesn't exists (with debug info)

# pathvector -t -v protocol reload device100
*******************************************************************************
WARNING: This is a development build. It is not recommended for production use.
Please submit any bugs to https://github.com/natesales/pathvector/issues
*******************************************************************************
DEBU[0000] Loading config from /etc/pathvector.yml
DEBU[0000] Setting PeeringDB endpoint to https://peeringdb.com/api/
DEBU[0000] Loaded 0 ASNs and 0 prefixes into global blocklist
DEBU[0000] Finished loading config
INFO[0000] Starting bird protocol command
DEBU[0000] Connecting to BIRD socket
DEBU[0000] Connected to BIRD socket
DEBU[0000] BIRD init response: BIRD 2.0.12 ready.
DEBU[0000] Sending BIRD command: reload device100
DEBU[0000] Sent BIRD command: reload device100
DEBU[0000] Reading from socket
DEBU[0000] Done reading from socket
FATA[0000] The protocol name was not found!

And when session doesn't exists (normal run)

# pathvector protocol reload device100
*******************************************************************************
WARNING: This is a development build. It is not recommended for production use.
Please submit any bugs to https://github.com/natesales/pathvector/issues
*******************************************************************************
INFO[0000] Starting bird protocol command
FATA[0000] The protocol name was not found!

And the help message:

*******************************************************************************
WARNING: This is a development build. It is not recommended for production use.
Please submit any bugs to https://github.com/natesales/pathvector/issues
*******************************************************************************
With this command you can restart, reload, enable or disable a protocol, if you want you can use "all" as the protocol name to for example restart all protocol sessions.

Usage:
  pathvector protocol <(r)estart|re(l)oad|(e)nable|(d)isable> <protocol name> [flags]

Aliases:
  protocol, p, protocols

Flags:
  -h, --help             help for protocol
  -m, --message string   enable/disable custom message

Global Flags:
  -c, --config string   YAML configuration file (default "/etc/pathvector.yml")
  -d, --dry-run         Don't modify configuration
      --lock string     Lock file (check disabled if empty)
  -n, --no-configure    Don't configure BIRD
  -t, --trace           Show trace log messages
  -v, --verbose         Show verbose log messages