Beispiel #1
0
def connect(self, address):
    if is_container():
        if isinstance(address, tuple) and is_localhost(address[0]):
            # handle AF_INET and AF_INET6
            address = list(address)
            address[0] = get_container_ip()
            address = tuple(address)
        elif isinstance(address, basestring) and is_localhost(address):
            # handle AF_UNIX
            address = get_container_ip()
    getattr(_socketobject, '_connect')(self, address)
Beispiel #2
0
def _set_to_container_ip(parse_endpoint):
    parts = list(parse_endpoint)
    hostname = container.get_container_ip()

    if not hostname:
        hostname = parse_endpoint.hostname

    if parse_endpoint.port:
        hostname = "%s:%s" % (hostname, parse_endpoint.port)

    parts[1] = hostname

    return urlparse.urlunparse(parts)
Beispiel #3
0
def mongo_init(self,
               host=None,
               port=None,
               max_pool_size=100,
               document_class=dict,
               tz_aware=False,
               _connect=True,
               **kwargs):
    if container.is_container():
        if host in ('localhost', '127.0.0.1', '::1'):
            host = container.get_container_ip()
    return MongoClient.__old_init__(self, host, port, max_pool_size,
                                    document_class, tz_aware, _connect,
                                    **kwargs)
Beispiel #4
0
def postgres_connect(dsn=None,
                     connection_factory=None,
                     cursor_factory=None,
                     **kwargs):
    container_ip = container.get_container_ip()
    if dsn is not None and container.is_container(
    ) and container_ip is not None:
        match = re.search(POSSIBLE_HOSTS_REGEX, dsn)
        if match is not None:
            to_replace = match.group(0)
            new_host = "host=%s" % container_ip
            dsn = dsn.replace(to_replace, new_host)
    return psycopg2._old_connect(dsn, connection_factory, cursor_factory,
                                 **kwargs)
Beispiel #5
0
 def test_container_ip(self):
     self.env.set('CONTAINER_IP', CONTAINER_IP)
     self.assertEqual(CONTAINER_IP, container.get_container_ip())