Add init loop in prometheus sidecar container
[osm/devops.git] / descriptor-packages / tools / charm-generator / generator / actions / templates / action.j2
1 #!/usr/bin/env python3
2 {#-
3 # Copyright 2019 Whitestack, LLC
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # 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, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
15 # under the License.
16 #
17 # For those usages not covered by the Apache License, Version 2.0 please
18 # contact: esousa@whitestack.com or glavado@whitestack.com
19 -#}
20 {%- if license is defined %}
21 # Copyright {{ license.year }} {{ license.company }}
22 #
23 # Licensed under the Apache License, Version 2.0 (the "License"); you may
24 # not use this file except in compliance with the License. You may obtain
25 # a copy of the License at
26 #
27 #         http://www.apache.org/licenses/LICENSE-2.0
28 #
29 # Unless required by applicable law or agreed to in writing, software
30 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
31 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
32 # License for the specific language governing permissions and limitations
33 # under the License.
34 #
35 # For those usages not covered by the Apache License, Version 2.0 please
36 # contact: {{ license.email }}
37 {%- endif %}
38
39 import sys
40 sys.path.append('lib')
41
42 from charms.reactive import main
43 from charms.reactive import set_state
44 from charmhelpers.core.hookenv import action_fail, action_name
45
46 """
47 `set_state` only works here because it's flushed to disk inside the `main()`
48 loop. remove_state will need to be called inside the action method.
49 """
50 set_state('actions.{}'.format(action_name()))
51
52 try:
53     main()
54 except Exception as e:
55     action_fail(repr(e))
56