From abf5502fd44db4238e86b0d4c2fc9956089dd7da Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 5 Dec 2023 21:51:12 +0100 Subject: [PATCH] add examples --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index d9bab9f..b4fe1c1 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ haproxy-cli - A tool to interact with HAProxy. 1. [Install](#install) 1. [Modes](#modes) 1. [CLI Usage](#cli-usage) +1. [Examples](#examples) + - [CLI](#cli) + - [API](#api) 1. [Development](#development) - [Contributing](#contributing) @@ -67,6 +70,42 @@ optional arguments: for protocol, then it assumes a UNIX socket file. ``` +## Examples + +### CLI + +``` +$ haproxy-cli -c frontends + +$ haproxy-cli -c servers -b testing_backend + +$ haproxy-cli -c get-weight -b example_backend -s server1 + +$ haproxy-cli -c set-weight -b example_backend -s server1 -w 99 + +$ haproxy-cli -k /run/haproxy/admin.sock -c backends +``` + +### API + +``` +#!/usr/bin/env python + +from haproxy.conn import HaPConn +from haproxy import cmds + +try: + socket_conn = HaPConn('/var/run/haproxy.socket') + + if socket_conn: + print(socket_conn.sendCmd(cmds.showInfo())) + else: + print('Could not open socket') + +except Exception as exc: + print(exc) +``` + ## Development ### Contributing