in libcloud/common/base.py [0:0]
def connect(self, host=None, port=None, base_url=None, **kwargs):
"""
Establish a connection with the API server.
:type host: ``str``
:param host: Optional host to override our default
:type port: ``int``
:param port: Optional port to override our default
:returns: A connection
"""
# prefer the attribute base_url if its set or sent
connection = None
secure = self.secure
if getattr(self, "base_url", None) and base_url is None:
(host, port, secure, request_path) = self._tuple_from_url(getattr(self, "base_url"))
elif base_url is not None:
(host, port, secure, request_path) = self._tuple_from_url(base_url)
else:
host = host or self.host
port = port or self.port
# Make sure port is an int
port = int(port)
if not hasattr(kwargs, "host"):
kwargs.update({"host": host})
if not hasattr(kwargs, "port"):
kwargs.update({"port": port})
if not hasattr(kwargs, "secure"):
kwargs.update({"secure": self.secure})
if not hasattr(kwargs, "key_file") and hasattr(self, "key_file"):
kwargs.update({"key_file": getattr(self, "key_file")})
if not hasattr(kwargs, "cert_file") and hasattr(self, "cert_file"):
kwargs.update({"cert_file": getattr(self, "cert_file")})
if self.timeout:
kwargs.update({"timeout": self.timeout})
if self.proxy_url:
kwargs.update({"proxy_url": self.proxy_url})
connection = self.conn_class(**kwargs)
# You can uncomment this line, if you setup a reverse proxy server
# which proxies to your endpoint, and lets you easily capture
# connections in cleartext when you setup the proxy to do SSL
# for you
# connection = self.conn_class("127.0.0.1", 8080)
self.connection = connection