HaproxyConfig¶
-
class
playback.haproxy_config.
HaproxyConfig
(user='ubuntu', hosts=None, key_filename=None, password=None, parallel=True, *args, **kwargs)¶ Bases:
playback.common.Common
Configure HAProxy and Keepalived
Parameters: - user(str) – the user for remote server to login
- hosts(list) – this is a second param
- key_filename(str) – the ssh private key to used, default None
- password(str) – the password for remote server
- parallel(bool) – paralleler execute on remote server, default True
Returns: None
Examples: # create two haproxy instances haproxy1 = HaproxyConfig( user='ubuntu', hosts=['haproxy1'] ) haproxy2 = HaproxyConfig( user='ubuntu', hosts=['haproxy2'] ) # generate haproxy configfile example or manually create from playback.templates.haproxy_cfg import conf_haproxy_cfg with open('haproxy.cfg', 'w') as f: f.write(conf_haproxy_cfg) # upload config to haproxy1 and haproxy2 haproxy1.upload_conf('haproxy.cfg') haproxy2.upload_conf('haproxy.cfg') # setup keepalived haproxy1.configure_keepalived( router_id='lb1', priority=150, state='MASTER', interface='eth0', vip='192.168.1.1' ) haproxy2.configure_keepalived( router_id='lb2', priority=100, state='SLAVE', interface='eth0', vip='192.168.1.1' )
-
configure_keepalived
(*args, **kwargs)¶ Configure keepalived
Parameters: - router_id – Keepalived router id e.g. lb1
- priority – Keepalived priority e.g. 150
- state – Keepalived state e.g. MASTER or ‘SLAVE’
- interface – Keepalived binding interface e.g. eth0
- vip – Keepalived virtual ip e.g. CONTROLLER_VIP
Returns: None
-
upload_conf
(*args, **kwargs)¶ Upload configuration file to the target host
Parameters: file – the path of haproxy configration file Returns: None