Avoid to use same code for aodh resources

Refactor for alarm resources to avoid some
redundant codes.

Change-Id: I5b2922896388a634453139345fef4439b8dad423
This commit is contained in:
huangtianhua 2016-12-27 15:43:09 +08:00
parent 642404d6ff
commit 745c155ed1
3 changed files with 19 additions and 34 deletions

View File

@ -163,6 +163,15 @@ class BaseAlarm(resource.Resource):
alarm_type = 'threshold' alarm_type = 'threshold'
QUERY_FACTOR_FIELDS = (
QF_FIELD, QF_OP, QF_VALUE,
) = (
'field', 'op', 'value',
)
QF_OP_VALS = constraints.AllowedValues(['le', 'ge', 'eq',
'lt', 'gt', 'ne'])
def actions_to_urls(self, props): def actions_to_urls(self, props):
kwargs = {} kwargs = {}
for k, v in iter(props.items()): for k, v in iter(props.items()):

View File

@ -41,23 +41,11 @@ class AodhAlarm(alarm_base.BaseAlarm):
'statistic', 'threshold', 'matching_metadata', 'query', 'statistic', 'threshold', 'matching_metadata', 'query',
) )
QUERY_FACTOR_FIELDS = (
QF_FIELD, QF_OP, QF_VALUE,
) = (
'field', 'op', 'value',
)
QF_OP_VALS = constraints.AllowedValues(['le', 'ge', 'eq',
'lt', 'gt', 'ne'])
properties_schema = { properties_schema = {
COMPARISON_OPERATOR: properties.Schema( COMPARISON_OPERATOR: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('Operator used to compare specified statistic with threshold.'), _('Operator used to compare specified statistic with threshold.'),
constraints=[ constraints=[alarm_base.BaseAlarm.QF_OP_VALS],
constraints.AllowedValues(['ge', 'gt', 'eq', 'ne', 'lt',
'le']),
],
update_allowed=True update_allowed=True
), ),
EVALUATION_PERIODS: properties.Schema( EVALUATION_PERIODS: properties.Schema(
@ -107,7 +95,7 @@ class AodhAlarm(alarm_base.BaseAlarm):
schema=properties.Schema( schema=properties.Schema(
properties.Schema.MAP, properties.Schema.MAP,
schema={ schema={
QF_FIELD: properties.Schema( alarm_base.BaseAlarm.QF_FIELD: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('Name of attribute to compare. ' _('Name of attribute to compare. '
'Names of the form metadata.user_metadata.X ' 'Names of the form metadata.user_metadata.X '
@ -118,12 +106,12 @@ class AodhAlarm(alarm_base.BaseAlarm):
'To see the attributes of your Samples, ' 'To see the attributes of your Samples, '
'use `ceilometer --debug sample-list`.') 'use `ceilometer --debug sample-list`.')
), ),
QF_OP: properties.Schema( alarm_base.BaseAlarm.QF_OP: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('Comparison operator.'), _('Comparison operator.'),
constraints=[QF_OP_VALS] constraints=[alarm_base.BaseAlarm.QF_OP_VALS]
), ),
QF_VALUE: properties.Schema( alarm_base.BaseAlarm.QF_VALUE: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('String value with which to compare.') _('String value with which to compare.')
) )
@ -325,15 +313,6 @@ class EventAlarm(alarm_base.BaseAlarm):
'event_type', 'query' 'event_type', 'query'
) )
QUERY_FACTOR_FIELDS = (
QF_FIELD, QF_OP, QF_VALUE,
) = (
'field', 'op', 'value',
)
QF_OP_VALS = constraints.AllowedValues(['le', 'ge', 'eq',
'lt', 'gt', 'ne'])
properties_schema = { properties_schema = {
EVENT_TYPE: properties.Schema( EVENT_TYPE: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
@ -350,16 +329,16 @@ class EventAlarm(alarm_base.BaseAlarm):
schema=properties.Schema( schema=properties.Schema(
properties.Schema.MAP, properties.Schema.MAP,
schema={ schema={
QF_FIELD: properties.Schema( alarm_base.BaseAlarm.QF_FIELD: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('Name of attribute to compare.') _('Name of attribute to compare.')
), ),
QF_OP: properties.Schema( alarm_base.BaseAlarm.QF_OP: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('Comparison operator.'), _('Comparison operator.'),
constraints=[QF_OP_VALS] constraints=[alarm_base.BaseAlarm.QF_OP_VALS]
), ),
QF_VALUE: properties.Schema( alarm_base.BaseAlarm.QF_VALUE: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('String value with which to compare.') _('String value with which to compare.')
) )

View File

@ -32,10 +32,7 @@ common_gnocchi_properties_schema = {
COMPARISON_OPERATOR: properties.Schema( COMPARISON_OPERATOR: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('Operator used to compare specified statistic with threshold.'), _('Operator used to compare specified statistic with threshold.'),
constraints=[ constraints=[alarm_base.BaseAlarm.QF_OP_VALS],
constraints.AllowedValues(['ge', 'gt', 'eq', 'ne', 'lt',
'le']),
],
update_allowed=True update_allowed=True
), ),
EVALUATION_PERIODS: properties.Schema( EVALUATION_PERIODS: properties.Schema(