OpenStack Networking (Neutron)
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

75 Zeilen
2.8KB

  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. from oslo_config import cfg
  13. from oslo_log import log as logging
  14. from neutron._i18n import _, _LI
  15. from neutron import manager
  16. QOS_DRIVER_NAMESPACE = 'neutron.qos.notification_drivers'
  17. QOS_PLUGIN_OPTS = [
  18. cfg.ListOpt('notification_drivers',
  19. default=['message_queue'],
  20. help=_('Drivers list to use to send the update notification')),
  21. ]
  22. cfg.CONF.register_opts(QOS_PLUGIN_OPTS, "qos")
  23. LOG = logging.getLogger(__name__)
  24. class QosServiceNotificationDriverManager(object):
  25. def __init__(self):
  26. self.notification_drivers = []
  27. self._load_drivers(cfg.CONF.qos.notification_drivers)
  28. def update_policy(self, context, qos_policy):
  29. for driver in self.notification_drivers:
  30. driver.update_policy(context, qos_policy)
  31. def delete_policy(self, context, qos_policy):
  32. for driver in self.notification_drivers:
  33. driver.delete_policy(context, qos_policy)
  34. def create_policy(self, context, qos_policy):
  35. for driver in self.notification_drivers:
  36. driver.create_policy(context, qos_policy)
  37. def _load_drivers(self, notification_drivers):
  38. """Load all the instances of the configured QoS notification drivers
  39. :param notification_drivers: comma separated string
  40. """
  41. if not notification_drivers:
  42. raise SystemExit(_('A QoS driver must be specified'))
  43. LOG.debug("Loading QoS notification drivers: %s", notification_drivers)
  44. for notification_driver in notification_drivers:
  45. driver_ins = self._load_driver_instance(notification_driver)
  46. self.notification_drivers.append(driver_ins)
  47. def _load_driver_instance(self, notification_driver):
  48. """Returns an instance of the configured QoS notification driver
  49. :returns: An instance of Driver for the QoS notification
  50. """
  51. mgr = manager.NeutronManager
  52. driver = mgr.load_class_for_provider(QOS_DRIVER_NAMESPACE,
  53. notification_driver)
  54. driver_instance = driver()
  55. LOG.info(
  56. _LI("Loading %(name)s (%(description)s) notification driver "
  57. "for QoS plugin"),
  58. {"name": notification_driver,
  59. "description": driver_instance.get_description()})
  60. return driver_instance