def _get_proxy(neutron_info): client = neutron.NeutronClientRemoteWrapper(neutron_info['network'], neutron_info['uri'], neutron_info['token'], neutron_info['tenant']) qrouter = client.get_router() proxy = paramiko.ProxyCommand('ip netns exec qrouter-{0} nc {1} 22'.format( qrouter, neutron_info['host'])) return proxy
def _get_http_client(host, port, neutron_info, *args, **kwargs): global _sessions _http_session = _sessions.get((host, port), None) LOG.debug('cached HTTP session for {0}:{1} is {2}'.format( host, port, _http_session)) if not _http_session: if neutron_info: neutron_client = neutron.NeutronClientRemoteWrapper( neutron_info['network'], neutron_info['uri'], neutron_info['token'], neutron_info['tenant']) # can return a new session here because it actually uses # the same adapter (and same connection pools) for a given # host and port tuple _http_session = neutron_client.get_http_session(host, port=port, *args, **kwargs) LOG.debug('created neutron based HTTP session for {0}:{1}'.format( host, port)) else: # need to cache the session for the non-neutron or neutron # floating ip cases so that a new session with a new HTTPAdapter # and associated pools is not recreated for each HTTP invocation _http_session = requests.Session() LOG.debug('created standard HTTP session for {0}:{1}'.format( host, port)) adapter = requests.adapters.HTTPAdapter(*args, **kwargs) for prefix in ['http://', 'https://']: _http_session.mount(prefix + '%s:%s' % (host, port), adapter) LOG.debug('caching session {0} for {1}:{2}'.format( _http_session, host, port)) _sessions[(host, port)] = _http_session return _http_session
def test_get_router(self, patched): patched.side_effect = _test_get_neutron_client neutron = neutron_client.NeutronClientRemoteWrapper( '33b47310-b7a8-4559-bf95-45ba669a448e', None, None, None) self.assertEqual('6c4d4e32-3667-4cd4-84ea-4cc1e98d18be', neutron.get_router())