Giter VIP home page Giter VIP logo

haproxy-cli's Introduction

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.

haproxy-cli's People

Contributors

egroeper avatar gordonfierce avatar neurogeek avatar ticosax avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.