Merge ""L3AgentExtensionsManager" check loaded extensions"
This commit is contained in:
commit
1a16c35f30
@ -13,8 +13,11 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from neutron_lib.agent import l3_extension
|
||||||
|
from neutron_lib import exceptions
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
|
from neutron._i18n import _
|
||||||
from neutron.agent import agent_extensions_manager as agent_ext_manager
|
from neutron.agent import agent_extensions_manager as agent_ext_manager
|
||||||
from neutron.conf.agent import agent_extensions_manager as agent_ext_mgr_config
|
from neutron.conf.agent import agent_extensions_manager as agent_ext_mgr_config
|
||||||
|
|
||||||
@ -24,6 +27,13 @@ LOG = log.getLogger(__name__)
|
|||||||
L3_AGENT_EXT_MANAGER_NAMESPACE = 'neutron.agent.l3.extensions'
|
L3_AGENT_EXT_MANAGER_NAMESPACE = 'neutron.agent.l3.extensions'
|
||||||
|
|
||||||
|
|
||||||
|
# TODO(ralonsoh): rehome to neutron_lib.
|
||||||
|
class L3ExtensionException(exceptions.NeutronException):
|
||||||
|
message = _('The following L3 agent extensions do not inherit from '
|
||||||
|
'``neutron_lib.agent.l3_extension.L3AgentExtension``: '
|
||||||
|
'%(extensions)s.')
|
||||||
|
|
||||||
|
|
||||||
def register_opts(conf):
|
def register_opts(conf):
|
||||||
agent_ext_mgr_config.register_agent_ext_manager_opts(conf)
|
agent_ext_mgr_config.register_agent_ext_manager_opts(conf)
|
||||||
|
|
||||||
@ -34,57 +44,37 @@ class L3AgentExtensionsManager(agent_ext_manager.AgentExtensionsManager):
|
|||||||
def __init__(self, conf):
|
def __init__(self, conf):
|
||||||
super(L3AgentExtensionsManager,
|
super(L3AgentExtensionsManager,
|
||||||
self).__init__(conf, L3_AGENT_EXT_MANAGER_NAMESPACE)
|
self).__init__(conf, L3_AGENT_EXT_MANAGER_NAMESPACE)
|
||||||
|
extensions = []
|
||||||
|
for extension in self:
|
||||||
|
if not isinstance(extension.obj, (l3_extension.L3AgentExtension,)):
|
||||||
|
extensions.append(extension.attr)
|
||||||
|
if extensions:
|
||||||
|
raise L3ExtensionException(extensions=extensions)
|
||||||
|
|
||||||
def add_router(self, context, data):
|
def add_router(self, context, data):
|
||||||
"""Notify all agent extensions to add router."""
|
"""Notify all agent extensions to add router."""
|
||||||
for extension in self:
|
for extension in self:
|
||||||
if hasattr(extension.obj, 'add_router'):
|
|
||||||
extension.obj.add_router(context, data)
|
extension.obj.add_router(context, data)
|
||||||
else:
|
|
||||||
LOG.error(
|
|
||||||
"Agent Extension '%(name)s' does not "
|
|
||||||
"implement method add_router",
|
|
||||||
{'name': extension.name}
|
|
||||||
)
|
|
||||||
LOG.debug("L3 agent extension(s) finished router %s "
|
LOG.debug("L3 agent extension(s) finished router %s "
|
||||||
"add action.", data['id'])
|
"add action.", data['id'])
|
||||||
|
|
||||||
def update_router(self, context, data):
|
def update_router(self, context, data):
|
||||||
"""Notify all agent extensions to update router."""
|
"""Notify all agent extensions to update router."""
|
||||||
for extension in self:
|
for extension in self:
|
||||||
if hasattr(extension.obj, 'update_router'):
|
|
||||||
extension.obj.update_router(context, data)
|
extension.obj.update_router(context, data)
|
||||||
else:
|
|
||||||
LOG.error(
|
|
||||||
"Agent Extension '%(name)s' does not "
|
|
||||||
"implement method update_router",
|
|
||||||
{'name': extension.name}
|
|
||||||
)
|
|
||||||
LOG.debug("L3 agent extension(s) finished router %s "
|
LOG.debug("L3 agent extension(s) finished router %s "
|
||||||
"update action.", data['id'])
|
"update action.", data['id'])
|
||||||
|
|
||||||
def delete_router(self, context, data):
|
def delete_router(self, context, data):
|
||||||
"""Notify all agent extensions to delete router."""
|
"""Notify all agent extensions to delete router."""
|
||||||
for extension in self:
|
for extension in self:
|
||||||
if hasattr(extension.obj, 'delete_router'):
|
|
||||||
extension.obj.delete_router(context, data)
|
extension.obj.delete_router(context, data)
|
||||||
else:
|
|
||||||
LOG.error(
|
|
||||||
"Agent Extension '%(name)s' does not "
|
|
||||||
"implement method delete_router",
|
|
||||||
{'name': extension.name}
|
|
||||||
)
|
|
||||||
LOG.debug("L3 agent extension(s) finished router %s "
|
LOG.debug("L3 agent extension(s) finished router %s "
|
||||||
"delete action.", data['id'])
|
"delete action.", data['id'])
|
||||||
|
|
||||||
def ha_state_change(self, context, data):
|
def ha_state_change(self, context, data):
|
||||||
"""Notify all agent extensions for HA router state change."""
|
"""Notify all agent extensions for HA router state change."""
|
||||||
for extension in self:
|
for extension in self:
|
||||||
if hasattr(extension.obj, 'ha_state_change'):
|
|
||||||
extension.obj.ha_state_change(context, data)
|
extension.obj.ha_state_change(context, data)
|
||||||
else:
|
LOG.debug('L3 agent extension(s) finished HA state change to "%s" '
|
||||||
LOG.warning(
|
'for router %s', data['state'], data['router_id'])
|
||||||
"Agent Extension '%(name)s' does not "
|
|
||||||
"implement method ha_state_change",
|
|
||||||
{'name': extension.name}
|
|
||||||
)
|
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
other:
|
||||||
|
- |
|
||||||
|
Any L3 agent extension must inherit from
|
||||||
|
``neutron_lib.agent.l3_extension.L3AgentExtension``. The
|
||||||
|
``L3AgentExtensionsManager`` makes this check during the initial loading.
|
||||||
|
A ``L3ExtensionException`` will be raised if the condition is not met.
|
Loading…
Reference in New Issue
Block a user