def __init__(self, conf): self.conf = conf ks_session = keystone.KeystoneSession() self.api_client = AstaraExtClientWrapper( session=ks_session.session, endpoint_type=cfg.CONF.endpoint_type, ) self.l3_rpc_client = L3PluginApi(PLUGIN_ROUTER_RPC_TOPIC, cfg.CONF.host)
def test_session(self, mock_load_auth, mock_session): fake_auth = mock.Mock() mock_load_auth.return_value = fake_auth fake_session = mock.Mock() mock_session.return_value = fake_session ks_session = keystone.KeystoneSession().session mock_load_auth.assert_called_with(cfg.CONF, 'keystone_authtoken') mock_session.assert_called_with(auth=fake_auth) self.assertEqual(ks_session, fake_session)
def __init__(self, conf): self.conf = conf ks_session = keystone.KeystoneSession() self.client = client.Client(version='2', session=ks_session.session, region_name=conf.auth_region) try: self.instance_provider = get_instance_provider( conf.instance_provider)(self.client) except AttributeError: default = INSTANCE_PROVIDERS['default'] LOG.error(_LE('Could not find provider config, using default %s'), default) self.instance_provider = default(self.client)
def take_action(self, parsed_args): ks_session = keystone.KeystoneSession() n_c = client.Client(session=ks_session.session) router_id = parsed_args.router_id.lower() port = n_c.list_ports(name="ASTARA:MGT:%s" % router_id) try: mgmt_ip_addr = port['ports'][0]['fixed_ips'].pop()['ip_address'] except (KeyError, IndexError): raise ValueError( "No router management address found for router with id %s" % router_id) try: cmd = ["ssh", "astara@%s" % mgmt_ip_addr] + parsed_args.remainder subprocess.check_call(cmd) except subprocess.CalledProcessError as e: sys.exit(e.returncode)
def make_message(self, parsed_args): router_id = parsed_args.router_id.lower() reason = parsed_args.reason if router_id in ['error', '*']: tenant_id = router_id else: # Look up the tenant for a given router so we can send the # command using both and the rug can route it to the correct # worker. We do the lookup here instead of in the rug to avoid # having to teach the rug notification and dispatching code # about how to find the owner of a router, and to shift the # burden of the neutron API call to the client so the server # doesn't block. It also gives us a chance to report an error # when we can't find the router. ks_session = keystone.KeystoneSession() n_c = client.Client(session=ks_session.session) response = n_c.list_routers(retrieve_all=True, id=router_id) try: router_details = response['routers'][0] except (KeyError, IndexError): raise ValueError('No router with id %r found.' % (router_id)) assert router_details['id'] == router_id tenant_id = router_details['tenant_id'] self.log.info( 'sending %s instruction for tenant %r, router %r', self._COMMAND, tenant_id, router_id, ) return { 'command': self._COMMAND, 'router_id': router_id, 'tenant_id': tenant_id, 'reason': reason, }