refactoring to compute from scheduler

This commit is contained in:
Sandy Walsh
2011-06-28 05:51:40 -07:00
parent 9ff79304ec
commit 4f625513ac
3 changed files with 51 additions and 7 deletions

View File

@@ -37,6 +37,45 @@ class BadPriorityException(Exception):
pass
def publisher_id(service, host=None):
if not host:
host = FLAGS.host
return "%s.%s" % (service, host)
def msgkeys(event_type, instance_id, level, publisher_id):
return dict(event_type=event_type, instance_id=instance_id,
notification_level=level, publisher_id=publisher_id)
def safe_notify(publisher_id, event_type, priority, payload):
try:
notify(publisher_id, event_type, notification_level, payload)
exception Exception, e:
LOG.exception(_("Problem '%(e)' attempting to "
"send to notification system." % locals()))
def instance_safe_notify(publisher_id, event_type, priority, instance_id,
extra_payload=None):
payload = dict(instance_id = instance_id)
if extra_payload:
payload.extend(extra_payload)
safe_notify(publisher_id, event_type, priority, payload)
def exception_to_notification(self, ex):
required = ['instance_id', 'publisher_id', 'notification_level',
'event_type']
for key in required:
if not (hasattr(ex, key) and ex.key):
return # Doesn't have everything we need. Skip it.
instance_id = ex.instance_id
publisher_id = ex.publisher_id
notification_level = ex.notification_level
event_type = ex.event_type
instance_safe_notify(publisher_id, event_type, priority, instance_id)
def notify(publisher_id, event_type, priority, payload):
"""
Sends a notification using the specified driver

View File

@@ -44,7 +44,6 @@ from nova import fakerabbit
from nova import flags
from nova import log as logging
from nova import utils
from nova.notifier import api as notifier
@@ -323,12 +322,8 @@ class ConsumerSet(object):
running = False
break
except exception.NovaException, e:
if not e.notification_level:
ex = e
# We have an exception we can
# tell the Notification system about.
# Pass it on.
ex = e
notifier.exception_to_notification(e)
except Exception as e:
ex = e

View File

@@ -27,6 +27,7 @@ from nova import db
from nova import exception
from nova import flags
from nova import log as logging
from nova import notifier
from nova import rpc
from nova import utils
from nova.compute import power_state
@@ -47,6 +48,15 @@ class WillNotSchedule(exception.Error):
pass
def publisher_id(host=None):
return notifier.publisher_id("scheduler", host)
def notifier(instance_id, event_type, level, host=None):
return dict(instance_id=instance_id, event_type=event_type,
notification_level=level, host=publisher_id(host))
class Scheduler(object):
"""The base class that all Scheduler clases should inherit from."""