~openstack-charmers-next/charms/xenial/cinder/trunk

« back to all changes in this revision

Viewing changes to actions/actions.py

  • Committer: Gerrit Code Review
  • Author(s): Jenkins
  • Date: 2016-04-05 08:57:34 UTC
  • mfrom: (156.2.1 trunk)
  • Revision ID: review@openstack.org-20160405085734-e69rpvyd75wnmswj
Merge "Add pause/resume actions and sync charm-helpers"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import os
 
4
import sys
 
5
 
 
6
sys.path.append('hooks/')
 
7
 
 
8
from charmhelpers.core.hookenv import action_fail
 
9
from cinder_utils import (
 
10
    pause_unit_helper,
 
11
    resume_unit_helper,
 
12
    register_configs,
 
13
)
 
14
 
 
15
 
 
16
def pause(args):
 
17
    """Pause the Ceilometer services.
 
18
    @raises Exception should the service fail to stop.
 
19
    """
 
20
    pause_unit_helper(register_configs())
 
21
 
 
22
 
 
23
def resume(args):
 
24
    """Resume the Ceilometer services.
 
25
    @raises Exception should the service fail to start."""
 
26
    resume_unit_helper(register_configs())
 
27
 
 
28
 
 
29
# A dictionary of all the defined actions to callables (which take
 
30
# parsed arguments).
 
31
ACTIONS = {"pause": pause, "resume": resume}
 
32
 
 
33
 
 
34
def main(args):
 
35
    action_name = os.path.basename(args[0])
 
36
    try:
 
37
        action = ACTIONS[action_name]
 
38
    except KeyError:
 
39
        return "Action %s undefined" % action_name
 
40
    else:
 
41
        try:
 
42
            action(args)
 
43
        except Exception as e:
 
44
            action_fail(str(e))
 
45
 
 
46
 
 
47
if __name__ == "__main__":
 
48
    sys.exit(main(sys.argv))