0

Newbie to python here. I'm in need of adding back end and front ends servers to the haproxy.cfg file and do a graceful reload via a python script. Could some of you point me in the right direction. If you include comments in the code it will immensely help me to understand faster.

Below is a sample block that I want to send in to the cfg, possibly based on raw_input([arg])

frontend fe:some_fe:bind:yyyy
        mode tcp
        bind x.x.x.x:yyyy name some_name
        use_backend be:some_be:x.x.x.x:yyyy

backend be:some_be:x.x.x.x:yyyy
mode http
        balance roundrobin
        server  x.x.x.x:yyyy check port yyyy 
        server  x.x.x.x:yyyy check port yyyy 

Some notes- x.x.x.x signifies an ip and yyyy a port.

Please help! Many thanks in advance.

bindo
  • 87
  • 3
  • 18
  • 1
    You could refer to the [pyhaproxy](https://github.com/imjoey/pyhaproxy) library, which could parse the haproxy config file and write back after some changes. – iterjpnic Jul 27 '17 at 01:06

1 Answers1

0

Read Python » 3.6.1 Documentation 6.1.4. Template strings

Edit your Question accordingly, e.g. replace _fe:some_fe_ with fe:${some_fe}

Read Python » 3.6.1 Documentation argparse.html#module-argparse

Edit your Question and append the commandline you want to use and your argparse code to work with.

stovfl
  • 14,998
  • 7
  • 24
  • 51
  • Thanks so much @stovfl. This should work but I'm wondering if I could varibalise this a little more. For an instance "fe" as a variable and as it's value being passed on? Further string formatting(spaces, tabs, etc) should look exactly like this. PLease if you have the solution try to post everything cos I'm a learner :) `code`frontend fe::bind: mode tcp bind : name use_backend be:::`code` – bindo Apr 17 '17 at 23:36
  • thanks. I was looking for a faster way to understand but guess I'm gonna have to read the documentation and figure things out myself. WIll do and thanks. – bindo Apr 19 '17 at 06:55
  • @bindo: You are wrong, I figure things out for you. You have to read the Documentation to confirm that's what you want. – stovfl Apr 19 '17 at 07:19
  • 2
    There is no need to switch outside. You can edit your Question and add your code you have so far. I advise you to get it running. – stovfl Apr 20 '17 at 08:34