Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. # Copyright 2012 Managed I.T.
  2. #
  3. # Author: Kiall Mac Innes <kiall@managedit.ie>
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License. You may obtain
  7. # a copy of the License at
  8. #
  9. #      http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. # License for the specific language governing permissions and limitations
  15. # under the License.
  16. import threading
  17. from oslo.config import cfg
  18. from oslo_log import log as logging
  19.  
  20. from designate.notification_handler.base import BaseAddressHandler
  21.  
  22.  
  23. LOG = logging.getLogger(__name__)
  24.  
  25. cfg.CONF.register_group(cfg.OptGroup(
  26.     name='handler:nova_fixed',
  27.     title="Configuration for Nova Notification Handler"
  28. ))
  29.  
  30. cfg.CONF.register_opts([
  31.     cfg.ListOpt('notification-topics', default=['notifications']),
  32.     cfg.StrOpt('control-exchange', default='nova'),
  33.     cfg.StrOpt('domain-id', default=None),
  34.     cfg.StrOpt('format', default=None)
  35. ], group='handler:nova_fixed')
  36.  
  37.  
  38. class NovaFixedHandler(BaseAddressHandler):
  39.     """Handler for Nova's notifications"""
  40.     __plugin_name__ = 'nova_fixed'
  41.     lock = threading.Lock()
  42.  
  43.     def get_exchange_topics(self):
  44.         exchange = cfg.CONF[self.name].control_exchange
  45.  
  46.         topics = [topic for topic in cfg.CONF[self.name].notification_topics]
  47.  
  48.         return (exchange, topics)
  49.  
  50.     def get_event_types(self):
  51.         return [
  52.             'compute.instance.create.end',
  53.             'compute.instance.delete.start',
  54.         ]
  55.  
  56.     def process_notification(self, context, event_type, payload):
  57.         LOG.debug('NovaFixedHandler received notification - %s' % event_type)
  58.  
  59.         with self.lock:
  60.             if event_type == 'compute.instance.create.end':
  61.                 self._create(payload['fixed_ips'], payload,
  62.                              resource_id=payload['instance_id'],
  63.                              resource_type='instance')
  64.  
  65.             elif event_type == 'compute.instance.delete.start':
  66.                 self._delete(resource_id=payload['instance_id'],
  67.                              resource_type='instance')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement