~felipe-alfaro-gmail/charms/xenial/neutron-api/trunk

« back to all changes in this revision

Viewing changes to actions/actions.py

  • Committer: Felipe Alfaro Solana
  • Date: 2017-04-05 19:45:40 UTC
  • Revision ID: felipe.alfaro@gmail.com-20170405194540-85i0nhnp98ipob0y
Neutron API charm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
#
 
3
# Copyright 2016 Canonical Ltd
 
4
#
 
5
# Licensed under the Apache License, Version 2.0 (the "License");
 
6
# you may not use this file except in compliance with the License.
 
7
# You may obtain a copy of the License at
 
8
#
 
9
#  http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
# Unless required by applicable law or agreed to in writing, software
 
12
# distributed under the License is distributed on an "AS IS" BASIS,
 
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
# See the License for the specific language governing permissions and
 
15
# limitations under the License.
 
16
 
 
17
import os
 
18
import sys
 
19
 
 
20
sys.path.append('hooks/')
 
21
 
 
22
from charmhelpers.core.hookenv import action_fail
 
23
from neutron_api_utils import (
 
24
    pause_unit_helper,
 
25
    resume_unit_helper,
 
26
    register_configs,
 
27
)
 
28
 
 
29
 
 
30
def pause(args):
 
31
    """Pause the Ceilometer services.
 
32
    @raises Exception should the service fail to stop.
 
33
    """
 
34
    pause_unit_helper(register_configs())
 
35
 
 
36
 
 
37
def resume(args):
 
38
    """Resume the Ceilometer services.
 
39
    @raises Exception should the service fail to start."""
 
40
    resume_unit_helper(register_configs())
 
41
 
 
42
 
 
43
# A dictionary of all the defined actions to callables (which take
 
44
# parsed arguments).
 
45
ACTIONS = {"pause": pause, "resume": resume}
 
46
 
 
47
 
 
48
def main(args):
 
49
    action_name = os.path.basename(args[0])
 
50
    try:
 
51
        action = ACTIONS[action_name]
 
52
    except KeyError:
 
53
        return "Action %s undefined" % action_name
 
54
    else:
 
55
        try:
 
56
            action(args)
 
57
        except Exception as e:
 
58
            action_fail(str(e))
 
59
 
 
60
 
 
61
if __name__ == "__main__":
 
62
    sys.exit(main(sys.argv))