Support connection with private IP

* Moved the connection related code to libraries folder so that we
don't need to duplicate the code in every recipes.
* Used private IP to connect if private_network attribute is
presented.