heat : db API add watch_rule_get_by_name
Add watch_rule_get_by_name, and move the previous watch_rule_get to look up rule by ID, which is consistent with the other api calls. Lookup by id is required for WatchRule rework Ref #217 Change-Id: I4b5d08ffcd31b6b522c65edd0a202e8cf5a367b8 Signed-off-by: Steven Hardy <shardy@redhat.com>
This commit is contained in:
parent
db0a268f41
commit
8be0906b7a
|
@ -143,8 +143,12 @@ def event_create(context, values):
|
|||
return IMPL.event_create(context, values)
|
||||
|
||||
|
||||
def watch_rule_get(context, watch_rule_name):
|
||||
return IMPL.watch_rule_get(context, watch_rule_name)
|
||||
def watch_rule_get(context, watch_rule_id):
|
||||
return IMPL.watch_rule_get(context, watch_rule_id)
|
||||
|
||||
|
||||
def watch_rule_get_by_name(context, watch_rule_name):
|
||||
return IMPL.watch_rule_get_by_name(context, watch_rule_name)
|
||||
|
||||
|
||||
def watch_rule_get_all(context):
|
||||
|
|
|
@ -258,7 +258,13 @@ def event_create(context, values):
|
|||
return event_ref
|
||||
|
||||
|
||||
def watch_rule_get(context, watch_rule_name):
|
||||
def watch_rule_get(context, watch_rule_id):
|
||||
result = model_query(context, models.WatchRule).\
|
||||
filter_by(id=watch_rule_id).first()
|
||||
return result
|
||||
|
||||
|
||||
def watch_rule_get_by_name(context, watch_rule_name):
|
||||
result = model_query(context, models.WatchRule).\
|
||||
filter_by(name=watch_rule_name).first()
|
||||
return result
|
||||
|
|
|
@ -454,7 +454,7 @@ class EngineManager(manager.Manager):
|
|||
This could be used by CloudWatch and WaitConditions
|
||||
and treat HA service events like any other CloudWatch.
|
||||
'''
|
||||
wr = db_api.watch_rule_get(None, watch_name)
|
||||
wr = db_api.watch_rule_get_by_name(None, watch_name)
|
||||
if wr is None:
|
||||
logger.warn('NoSuch watch:%s' % (watch_name))
|
||||
return ['NoSuch Watch Rule', None]
|
||||
|
@ -483,7 +483,7 @@ class EngineManager(manager.Manager):
|
|||
'''
|
||||
if watch_name:
|
||||
try:
|
||||
wr = db_api.watch_rule_get(context, watch_name)
|
||||
wr = db_api.watch_rule_get_by_name(context, watch_name)
|
||||
except Exception as ex:
|
||||
logger.warn('show_watch (%s) db error %s' %
|
||||
(watch_name, str(ex)))
|
||||
|
@ -538,7 +538,7 @@ class EngineManager(manager.Manager):
|
|||
|
||||
if watch_name:
|
||||
try:
|
||||
wr = db_api.watch_rule_get(context, watch_name)
|
||||
wr = db_api.watch_rule_get_by_name(context, watch_name)
|
||||
except Exception as ex:
|
||||
logger.warn('show_watch (%s) db error %s' %
|
||||
(watch_name, str(ex)))
|
||||
|
|
|
@ -621,7 +621,7 @@ class stackManagerTest(unittest.TestCase):
|
|||
def test_show_watch_metric(self):
|
||||
# Get one of the watch rules created in test_show_watch
|
||||
# And add a metric datapoint
|
||||
watch = db_api.watch_rule_get(self.ctx, "HttpFailureAlarm")
|
||||
watch = db_api.watch_rule_get_by_name(self.ctx, "HttpFailureAlarm")
|
||||
self.assertNotEqual(watch, None)
|
||||
values = {'watch_rule_id': watch.id,
|
||||
'data': {
|
||||
|
|
Loading…
Reference in New Issue