How to open an SSH tunnel using python?
Try use sshtunnel package.
This is simple:
pip install sshtunnel
python -m sshtunnel -U vagrant -P vagrant -L :3306 -R 127.0.0.1:3306 -p 2222 localhost
Disclosure: I'm the author and maintainer of this package.
You could try paramiko's forward functionality. For a paramiko overview, see here.