2 # Copyright 2019 Whitestack, LLC
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 # For those usages not covered by the Apache License, Version 2.0 please
17 # contact: esousa@whitestack.com or glavado@whitestack.com
19 {%- if license is defined -%}
20 # Copyright {{ license.year }} {{ license.company }}
22 # Licensed under the Apache License, Version 2.0 (the "License"); you may
23 # not use this file except in compliance with the License. You may obtain
24 # a copy of the License at
26 # http://www.apache.org/licenses/LICENSE-2.0
28 # Unless required by applicable law or agreed to in writing, software
29 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
30 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
31 # License for the specific language governing permissions and limitations
34 # For those usages not covered by the Apache License, Version 2.0 please
35 # contact: {{ license.email }}
42 from charmhelpers.core.hookenv import (
50 import charms.libansible
52 from charms.reactive import (
53 remove_state as remove_flag,
54 set_state as set_flag,
59 # Sets the status of the charm to show in OSM: configured
60 @when('config.changed')
62 set_flag('{{ charm_name }}.configured')
63 status_set('active', 'ready!')
67 # Edits ansible config files and executes ansible-playbook
68 {% for pb in playbooks -%}
69 @when('{{ charm_name }}.configured')
70 @when('actions.{{ pb.action_name }}')
71 def {{ pb.function_name }}():
75 # edit the following snippet to add your parameters
76 # Note: don't forget to edit actions.yaml to add the parameters
77 # param_variable = action_get('param-name')
78 # dict_vars['param-name'] = param_variable}
80 result = charms.libansible.execute_playbook('{{ pb.file }}', dict_vars)
82 exc_type, exc_value, exc_traceback = sys.exc_info()
83 err = traceback.format_exception(exc_type, exc_value, exc_traceback)
84 action_fail('{{ pb.action_name }} failed: ' + str(err))
86 action_set({'output': result})
88 remove_flag('actions.{{ pb.action_name }}')