OpenStack Networking (Neutron)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.4KB

  1. # Copyright (c) 2015 Mellanox Technologies, Ltd
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. from oslo_config import cfg
  16. from oslo_log import log
  17. import stevedore
  18. from neutron._i18n import _, _LE, _LI
  19. LOG = log.getLogger(__name__)
  20. L2_AGENT_EXT_MANAGER_NAMESPACE = 'neutron.agent.l2.extensions'
  21. L2_AGENT_EXT_MANAGER_OPTS = [
  22. cfg.ListOpt('extensions',
  23. default=[],
  24. help=_('Extensions list to use')),
  25. ]
  26. def register_opts(conf):
  27. conf.register_opts(L2_AGENT_EXT_MANAGER_OPTS, 'agent')
  28. class AgentExtensionsManager(stevedore.named.NamedExtensionManager):
  29. """Manage agent extensions."""
  30. def __init__(self, conf):
  31. super(AgentExtensionsManager, self).__init__(
  32. L2_AGENT_EXT_MANAGER_NAMESPACE, conf.agent.extensions,
  33. invoke_on_load=True, name_order=True)
  34. LOG.info(_LI("Loaded agent extensions: %s"), self.names())
  35. def initialize(self, connection, driver_type, agent_api=None):
  36. """Initialize enabled L2 agent extensions.
  37. :param connection: RPC connection that can be reused by extensions to
  38. define their RPC endpoints
  39. :param driver_type: a string that defines the agent type to the
  40. extension. Can be used by the extension to choose
  41. the right backend implementation.
  42. :param agent_api: an AgentAPI instance that provides an API to
  43. interact with the agent that the manager
  44. is running in.
  45. """
  46. # Initialize each agent extension in the list.
  47. for extension in self:
  48. LOG.info(_LI("Initializing agent extension '%s'"), extension.name)
  49. extension.obj.consume_api(agent_api)
  50. extension.obj.initialize(connection, driver_type)
  51. def handle_port(self, context, data):
  52. """Notify all agent extensions to handle port."""
  53. for extension in self:
  54. try:
  55. extension.obj.handle_port(context, data)
  56. # TODO(QoS) add agent extensions exception and catch them here
  57. except AttributeError:
  58. LOG.exception(
  59. _LE("Agent Extension '%(name)s' failed "
  60. "while handling port update"),
  61. {'name': extension.name}
  62. )
  63. def delete_port(self, context, data):
  64. """Notify all agent extensions to delete port."""
  65. for extension in self:
  66. try:
  67. extension.obj.delete_port(context, data)
  68. # TODO(QoS) add agent extensions exception and catch them here
  69. # instead of AttributeError
  70. except AttributeError:
  71. LOG.exception(
  72. _LE("Agent Extension '%(name)s' failed "
  73. "while handling port deletion"),
  74. {'name': extension.name}
  75. )