NFP - Fixed LBaaSv2 creation issue

Getting DHCP agent host from agent-list.
This is needed to get active network info required by haproxy driver (v2).
Commented get_routers RPC call as there is no l3-agent in certain setups.

Change-Id: I588e2fbb996c2eafd59d6caad28507c1d3fa2ea1
This commit is contained in:
kedarkulkarni 2017-01-25 19:53:34 +05:30 committed by Subrahmanyam Ongole
parent 25b7cc074e
commit fd954f26a1
3 changed files with 43 additions and 5 deletions

View File

@ -14,6 +14,7 @@ from gbpservice.contrib.nfp.config_orchestrator.common import (
topics as a_topics) topics as a_topics)
from gbpservice.nfp.core import log as nfp_logging from gbpservice.nfp.core import log as nfp_logging
from gbpservice.nfp.lib import transport from gbpservice.nfp.lib import transport
from gbpservice.nfp.orchestrator.openstack import openstack_driver
from neutron._i18n import _LE from neutron._i18n import _LE
from neutron.common import constants as n_constants from neutron.common import constants as n_constants
@ -89,9 +90,10 @@ def _filter_data(routers, networks, filters):
'networks': _filtered_networks} 'networks': _filtered_networks}
def get_core_context(context, filters, host): def get_core_context(context, filters, config):
routers = get_routers(context, host) #routers = get_routers(context, config.host)
networks = get_networks(context, host) routers = []
networks = get_networks(context, config)
return _filter_data(routers, networks, filters) return _filter_data(routers, networks, filters)
@ -103,7 +105,24 @@ def get_routers(context, host):
router_ids=None) router_ids=None)
def get_networks(context, host): def get_dhcp_agent_host(config):
try:
neutronclient = openstack_driver.NeutronClient(config)
keystoneclient = openstack_driver.KeystoneClient(config)
token = keystoneclient.get_admin_token()
filters = {'agent_type': 'DHCP agent', 'alive': True}
agents = neutronclient.get_agents(token, filters)
if agents:
return agents[0].get('host', None)
except Exception as exc:
LOG.error(_LE("Failed to get dhcp agent host : %(exc)s"),
{'exc': exc})
def get_networks(context, config):
host = get_dhcp_agent_host(config)
if not host:
return []
target = messaging.Target( target = messaging.Target(
topic=n_topics.PLUGIN, topic=n_topics.PLUGIN,
namespace=n_constants.RPC_NAMESPACE_DHCP_PLUGIN, namespace=n_constants.RPC_NAMESPACE_DHCP_PLUGIN,

View File

@ -71,7 +71,7 @@ class Lbv2Agent(loadbalancer_dbv2.LoadBalancerPluginDbv2):
filters = {'tenant_id': [tenant_id]} filters = {'tenant_id': [tenant_id]}
core_context_dict = common.get_core_context(context, core_context_dict = common.get_core_context(context,
filters, filters,
self._conf.host) self._conf)
del core_context_dict['routers'] del core_context_dict['routers']
return core_context_dict return core_context_dict

View File

@ -966,6 +966,25 @@ class NeutronClient(OpenstackApi):
LOG.error(err) LOG.error(err)
raise Exception(err) raise Exception(err)
def get_agents(self, token, filters=None):
""" Get neutron agents
:param token: A scoped_token
:param filters: Parameters for list filter
:return: neutron agents List
"""
try:
neutron = neutron_client.Client(token=token,
endpoint_url=self.network_service)
return neutron.list_agents(**filters).get('agents', [])
except Exception as ex:
err = ("Failed to read agents information"
" Exception :: %s" % (ex))
LOG.error(err)
raise Exception(err)
class GBPClient(OpenstackApi): class GBPClient(OpenstackApi):
""" GBP Client Api Driver. """ """ GBP Client Api Driver. """