Beispiel #1
0
    def _build_proxy_command(self, command, instance=None, port=None,
                             info=None, rootwrap_command=None):
        # Accepted keywords in the proxy command template:
        # {host}, {port}, {tenant_id}, {network_id}, {router_id}
        keywords = {}

        if not info:
            info = self.get_neutron_info(instance)
        keywords['tenant_id'] = context.current().tenant_id
        keywords['network_id'] = info['network']

        # Query Neutron only if needed
        if '{router_id}' in command:
            client = neutron.NeutronClient(info['network'], info['uri'],
                                           info['token'], info['tenant'])
            keywords['router_id'] = client.get_router()

        keywords['host'] = instance.management_ip
        keywords['port'] = port

        try:
            command = command.format(**keywords)
        except KeyError as e:
            LOG.error(_('Invalid keyword in proxy_command: %s'), str(e))
            # Do not give more details to the end-user
            raise ex.SystemError('Misconfiguration')
        if rootwrap_command:
            command = '{0} {1}'.format(rootwrap_command, command)
        return command
Beispiel #2
0
 def test_get_router(self, patched):
     patched.side_effect = _test_get_neutron_client
     neutron = neutron_client.NeutronClient(
         '33b47310-b7a8-4559-bf95-45ba669a448e', None, None, None)
     self.assertEqual('6c4d4e32-3667-4cd4-84ea-4cc1e98d18be',
                      neutron.get_router())