diff options
Diffstat (limited to 'charms/trusty/ceilometer/actions/actions.py')
-rwxr-xr-x | charms/trusty/ceilometer/actions/actions.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/charms/trusty/ceilometer/actions/actions.py b/charms/trusty/ceilometer/actions/actions.py new file mode 100755 index 0000000..0c077b6 --- /dev/null +++ b/charms/trusty/ceilometer/actions/actions.py @@ -0,0 +1,48 @@ +#!/usr/bin/python + +import os +import sys + +from charmhelpers.core.hookenv import action_fail +from ceilometer_utils import ( + pause_unit_helper, + resume_unit_helper, + register_configs, +) + + +def pause(args): + """Pause the Ceilometer services. + + @raises Exception should the service fail to stop. + """ + pause_unit_helper(register_configs()) + + +def resume(args): + """Resume the Ceilometer services. + + @raises Exception should the service fail to start.""" + resume_unit_helper(register_configs()) + + +# A dictionary of all the defined actions to callables (which take +# parsed arguments). +ACTIONS = {"pause": pause, "resume": resume} + + +def main(args): + action_name = os.path.basename(args[0]) + try: + action = ACTIONS[action_name] + except KeyError: + return "Action %s undefined" % action_name + else: + try: + action(args) + except Exception as e: + action_fail(str(e)) + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) |