Skip to main content

A tool to interact with HAProxy.

Project description

haproxy-cli

CI PyPI version

haproxy-cli - A tool to interact with HAProxy.

Table of Contents

  1. Overview
  2. Install
  3. Modes
  4. CLI Usage
  5. Examples
  6. Development

Overview

haproxy-cli is a tool to manage the various aspects of HAProxy that can be controlled by means of its socket. It is based on haproxyctl and is actively used in the OPNsense HAProxy plugin.

Install

pip install haproxy-cli

Modes

haproxy-cli can be used in 2 modes: CLI mode and Python API mode. CLI mode, as the name implies, gives you a command, haproxy-cli, that can be used to control HAProxy.

You can use the Python API mode to integrate haproxy-cli directly in your Python project.

Every command in haproxy-cli has at least two methods: getResult and getResultObj.

The method getResult returns a formatted string with the results obtained by executing the given HAProxy command, while getResultObj returns a Python object with the results, making it easy to use this results in some Python code.

CLI Usage

$ haproxy-cli --help

usage: haproxy-cli [-h] [-v] [-c COMMAND] [-l] [-H] [-s SERVER] [-b BACKEND]
                  [-w WEIGHT] [-k SOCKET]

A tool to interact with HAProxy

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         Be verbose.
  -c COMMAND, --command COMMAND
                        Type of command. Default info
  -l, --list-commands   Lists available commands.
  -H, --help-command    Shows help for the given command.
  -s SERVER, --server SERVER
                        Attempt action on given server.
  -b BACKEND, --backend BACKEND
                        Set backend to act upon.
  -w WEIGHT, --weight WEIGHT
                        Specify weight for a server.
  -k SOCKET, --socket SOCKET
                        Socket to talk to HAProxy. It accepts
                        unix:///path/to/socket or tcp://1.2.3.4[:port]
                        addresses. If there is no match
                        for protocol, then it assumes a UNIX socket file.

Examples

CLI

$ haproxy-cli -c frontends

$ haproxy-cli -c servers -b example_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

Please use the GitHub issues functionality to report any bugs or requests for new features. Feel free to fork and submit pull requests for potential contributions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haproxy_cli-0.7.1.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

haproxy_cli-0.7.1-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file haproxy_cli-0.7.1.tar.gz.

File metadata

  • Download URL: haproxy_cli-0.7.1.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for haproxy_cli-0.7.1.tar.gz
Algorithm Hash digest
SHA256 14d4031a791b76414403cf9c82a858ac8e7ae69eeb510e5adcf959e9cc981be8
MD5 88452f6eeff1d760df9f7aef6a8fa63a
BLAKE2b-256 158629aa60e4298fadee6ec3ec0f026030d7d9cdd12d41d355c5543af7990149

See more details on using hashes here.

File details

Details for the file haproxy_cli-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: haproxy_cli-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for haproxy_cli-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5a40f240c4596ca4b3be3b0c4e797bf9285c0ee55cfbc7fb2107f2aaf6ba0b8f
MD5 0000da65ef5496c91e5582928f7dfb02
BLAKE2b-256 867b6018961eded897a20b123969682eb8bf60b0315cc2824a54b0fccf31e8aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page