'Called after a new WebSocket connection has been established.'

def new_websocket_client(self):

    from eventlet import hubs
    hubs.use_hub()
    parse = urlparse.urlparse(self.path)
    if (parse.scheme not in ('http', 'https')):
        if (sys.version_info < (2, 7, 4)):
            raise exception.NovaException((_("We    do    not    support    scheme    '%s'    under    Python    <    2.7.4,    please    use    http    or    https") % parse.scheme))
    query = parse.query
    token = urlparse.parse_qs(query).get('token', ['']).pop()
    if (not token):
        hcookie = self.headers.get('cookie')
        if hcookie:
            cookie = Cookie.SimpleCookie()
            for hcookie_part in hcookie.split(';'):
                hcookie_part = hcookie_part.lstrip()
                try:
                    cookie.load(hcookie_part)
                except Cookie.CookieError:
                    LOG.warning('Found    malformed    cookie')
                else:
                    if ('token' in cookie):
                        token = cookie['token'].value
    ctxt = context.get_admin_context()
    rpcapi = consoleauth_rpcapi.ConsoleAuthAPI()
    connect_info = rpcapi.check_token(ctxt, token=token)
    if (not connect_info):
        raise exception.InvalidToken(token=token)
    expected_origin_hostname = self.headers.get('Host')
    if (':' in expected_origin_hostname):
        e = expected_origin_hostname
        if (('[' in e) and (']' in e)):
            expected_origin_hostname = e.split(']')[0][1:]
        else:
            expected_origin_hostname = e.split(':')[0]
    expected_origin_hostnames = CONF.console.allowed_origins
    expected_origin_hostnames.append(expected_origin_hostname)
    origin_url = self.headers.get('Origin')
    if (origin_url is not None):
        origin = urlparse.urlparse(origin_url)
        origin_hostname = origin.hostname
        origin_scheme = origin.scheme
        if ((origin_hostname == '') or (origin_scheme == '')):
            detail = _('Origin    header    not    valid.')
            raise exception.ValidationError(detail=detail)
        if (origin_hostname not in expected_origin_hostnames):
            detail = _('Origin    header    does    not    match    this    host.')
            raise exception.ValidationError(detail=detail)
        if (not self.verify_origin_proto(connect_info, origin_scheme)):
            detail = _('Origin    header    protocol    does    not    match    this    host.')
            raise exception.ValidationError(detail=detail)
    self.msg(_('connect    info:    %s'), str(connect_info))
    host = connect_info['host']
    port = int(connect_info['port'])
    self.msg((_('connecting    to:    %(host)s:%(port)s') % {'host': host, 'port': port}))
    tsock = self.socket(host, port, connect=True)
    if connect_info.get('internal_access_path'):
        tsock.send(('CONNECT    %s    HTTP/1.1\r\n\r\n' % connect_info['internal_access_path']))
        end_token = '\r\n\r\n'
        while True:
            data = tsock.recv(4096, socket.MSG_PEEK)
            token_loc = data.find(end_token)
            if (token_loc != (-1)):
                if (data.split('\r\n')[0].find('200') == (-1)):
                    raise exception.InvalidConnectionInfo()
                tsock.recv((token_loc + len(end_token)))
                break
    try:
        self.do_proxy(tsock)
    except Exception:
        if tsock:
            tsock.shutdown(socket.SHUT_RDWR)
            tsock.close()
            self.vmsg((_('%(host)s:%(port)s:    Websocket    client    or    target    closed') % {'host': host, 'port': port}))
        raise
