This script allows us to swape a master mysql server and a slave. It uses the pexpect module to connect to each server through ssh either using a password or using ssh key.
Python module pexpect : pip install pexpect
python switch.py hostname1 hostname2