summaryrefslogtreecommitdiff
path: root/ceilometerclient/common
diff options
context:
space:
mode:
authorUros Jovanovic <uros.jovanovic@gmail.com>2014-03-05 18:49:14 +0000
committerUros Jovanovic <uros.jovanovic@gmail.com>2014-03-26 08:24:56 +0000
commit7146571b702579fa1367598ab278ca2f8ec1e156 (patch)
tree051046a88aca58b13ef56a7747a2d4e689e369e9 /ceilometerclient/common
parent3e8045c9caad407b38758da7f611982809e3a0f5 (diff)
downloadpython-ceilometerclient-7146571b702579fa1367598ab278ca2f8ec1e156.tar.gz
Adds alarm time constraint support to ceilometer CLI
Time constraints can be specified for create and update families of commands with the following format: --time-constraint name=constraint1;start='0 11 * * *';duration=300 This switch can be specified multiple times in the case of multiple time constraints. With update commands, time constraints are updated by name, e.g. --time-constraint name=constraint1;duration=500 updates the constraint 'constraint1' with a new duration 500. Time constraints can be removed with update commands using the switch --remove-time-constraint=constraint1,constraint2 . Example of display outputs: > ceilometer alarm-list +--------------------------------------+-------+-------------------+---------+------------+----------------------------+--------------------------------------------------------------+ | Alarm ID | Name | State | Enabled | Continuous | Alarm condition | Time constraints | +--------------------------------------+-------+-------------------+---------+------------+----------------------------+--------------------------------------------------------------+ | 2ead776d-2fc7-47a2-b0bb-0f88dcefa457 | test2 | insufficient data | True | False | cpu == 50.0 during 1 x 60s | cons1 at 0 11 * * * for 300s, cons2 at 0 23 * * * for 600s | +--------------------------------------+-------+-------------------+---------+------------+----------------------------+--------------------------------------------------------------+ > ceilometer alarm-show -a +---------------------------+-----------------------------------------------------------------------+ | Property | Value | +---------------------------+-----------------------------------------------------------------------+ | alarm_actions | [] | | alarm_id | 2ead776d-2fc7-47a2-b0bb-0f88dcefa457 | | comparison_operator | eq | | description | Alarm when cpu is eq a avg of 50.0 over 60 seconds | | enabled | True | | evaluation_periods | 1 | | exclude_outliers | False | | insufficient_data_actions | [] | | meter_name | cpu | | name | test2 | | ok_actions | [] | | period | 60 | | project_id | 962f75ad22c24cbf99d40d7b82718505 | | query | | | repeat_actions | False | | state | insufficient data | | statistic | avg | | threshold | 50.0 | | time_constraints | [{name: cons1, | | | description: Time constraint at 0 11 * * * lasting for 300 seconds, | | | start: 0 11 * * *, | | | duration: 300}, | | | {name: cons2, | | | description: Time constraint at 0 23 * * * lasting for 600 seconds, | | | start: 0 23 * * *, | | | duration: 600}] | | type | threshold | | user_id | 76f335df8e2f4c7e9e8185e26ea85759 | +---------------------------+-----------------------------------------------------------------------+ > ceilometer alarm-history -a 2ead776d-2fc7-47a2-b0bb-0f88dcefa457 +----------+----------------------------+--------------------------------------------------------------------------------+ | Type | Timestamp | Detail | +----------+----------------------------+--------------------------------------------------------------------------------+ | creation | 2014-03-06T07:41:35.362050 | name: test2 | | | | description: Alarm when cpu is eq a avg of 50.0 over 60 seconds | | | | type: threshold | | | | rule: cpu == 50.0 during 1 x 60s | | | | time_constraints: cons1 at 0 11 * * * for 300s, cons2 at 0 23 * * * for 600s | +----------+----------------------------+--------------------------------------------------------------------------------+ Change-Id: I3953276537b4526e46e5e6d229d6fa154f8ab0fc Closes-Bug: #1288246
Diffstat (limited to 'ceilometerclient/common')
-rw-r--r--ceilometerclient/common/utils.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/ceilometerclient/common/utils.py b/ceilometerclient/common/utils.py
index 2628ca0..db7b042 100644
--- a/ceilometerclient/common/utils.py
+++ b/ceilometerclient/common/utils.py
@@ -154,6 +154,27 @@ def args_array_to_dict(kwargs, key_to_convert):
return kwargs
+def args_array_to_list_of_dicts(kwargs, key_to_convert):
+ """Converts ['a=1;b=2','c=3;d=4'] to [{a:1,b:2},{c:3,d:4}]
+ """
+ values_to_convert = kwargs.get(key_to_convert)
+ if values_to_convert:
+ try:
+ kwargs[key_to_convert] = []
+ for lst in values_to_convert:
+ pairs = lst.split(";")
+ dct = dict()
+ for pair in pairs:
+ kv = pair.split("=", 1)
+ dct[kv[0]] = kv[1].strip(" \"'") # strip spaces and quotes
+ kwargs[key_to_convert].append(dct)
+ except Exception:
+ raise exc.CommandError(
+ '%s must be a list of key1=value1;key2=value2;... not "%s"' % (
+ key_to_convert, values_to_convert))
+ return kwargs
+
+
def key_with_slash_to_nested_dict(kwargs):
nested_kwargs = {}
for k in list(kwargs):