예제 #1
0
 def __init__(self, app, conf):
     if not MODULE_DEPENDENCY_MET:
         # reraise the exception if the dependency wasn't met
         raise ImportError('dnspython is required for this module')
     self.app = app
     storage_domain = conf.get('storage_domain', 'example.com')
     self.storage_domain = ['.' + s for s in
                            list_from_csv(storage_domain)
                            if not s.startswith('.')]
     self.storage_domain += [s for s in list_from_csv(storage_domain)
                             if s.startswith('.')]
     self.lookup_depth = int(conf.get('lookup_depth', '1'))
     nameservers = list_from_csv(conf.get('nameservers'))
     try:
         for i, server in enumerate(nameservers):
             ip_or_host, maybe_port = nameservers[i] = \
                 parse_socket_string(server, None)
             if not is_valid_ip(ip_or_host):
                 raise ValueError
             if maybe_port is not None:
                 int(maybe_port)
     except ValueError:
         raise ValueError('Invalid cname_lookup/nameservers configuration '
                          'found. All nameservers must be valid IPv4 or '
                          'IPv6, followed by an optional :<integer> port.')
     self.resolver = dns.resolver.Resolver()
     if nameservers:
         self.resolver.nameservers = [ip for (ip, port) in nameservers]
         self.resolver.nameserver_ports = {
             ip: int(port) for (ip, port) in nameservers
             if port is not None}
     self.memcache = None
     self.logger = get_logger(conf, log_route='cname-lookup')
예제 #2
0
def forward_raw_swift_req(swift_baseurl, req, logger, object_chunk_size):
    # logger.info('swift_baseurl: %s' % swift_baseurl)
    scheme, netloc, _, _, _ = urlsplit(swift_baseurl)
    ssl = (scheme == 'https')
    swift_host, swift_port = utils.parse_socket_string(netloc,
                                                       443 if ssl else 80)
    swift_port = int(swift_port)
    if ssl:
        conn = bufferedhttp.HTTPSConnection(swift_host, port=swift_port)
    else:
        conn = bufferedhttp.BufferedHTTPConnection(swift_host, port=swift_port)
    conn.path = req.path_qs
    conn.putrequest(req.method, req.path_qs, skip_host=True)
    proxy_satellite_host = ''
    for header, value in filter_hop_by_hop_headers(req.headers.items()):
        if header.lower() == 'host':
            proxy_satellite_host = value
            continue
        conn.putheader(header, str(value))
    conn.putheader('Host', str(swift_host))
    conn.endheaders()

    content_length = int(req.headers.get('content-length', '0'))
    if content_length != 0:
        chunk = req.body_file.read(object_chunk_size)
        while chunk:
            conn.send(chunk)
            chunk = req.body_file.read(object_chunk_size)

    resp = conn.getresponse()
    headers = dict(filter_hop_by_hop_headers(resp.getheaders()))
    if 'x-storage-url' in headers:
        swift_scheme, swift_netloc, swift_path, _, _ = \
            urlsplit(headers['x-storage-url'])
        headers['x-storage-url'] = \
            swift_scheme+"://"+proxy_satellite_host+swift_path
    body_len = 0 if req.method == 'HEAD' \
        else int(headers.get('content-length', "0"))
    app_iter = ClosingResourceIterable(resource=conn,
                                       data_src=resp,
                                       length=body_len)
    return swob.Response(app_iter=app_iter,
                         status=resp.status,
                         headers=headers,
                         request=req)
예제 #3
0
파일: memcached.py 프로젝트: clayg/swift
 def __init__(self, server, size, connect_timeout):
     Pool.__init__(self, max_size=size)
     self.host, self.port = utils.parse_socket_string(
         server, DEFAULT_MEMCACHED_PORT)
     self._connect_timeout = connect_timeout
예제 #4
0
 def __init__(self, server, size, connect_timeout):
     Pool.__init__(self, max_size=size)
     self.host, self.port = utils.parse_socket_string(
         server, DEFAULT_MEMCACHED_PORT)
     self._connect_timeout = connect_timeout