blob: 6e1300ecbc9ef0dc8aad05a8ebbf3457b3fedc48 [file] [log] [blame]
Dominik Fleischmannca6eb952019-11-27 16:38:18 +01001# Copyright 2019 Canonical Ltd.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Adam Israelbf793522018-11-20 13:54:13 -050015from charmhelpers.core.hookenv import (
16 action_get,
17 action_fail,
18 action_set,
19 status_set,
20)
21from charms.reactive import (
22 clear_flag,
23 set_flag,
24 when,
25 when_not,
26)
27import charms.sshproxy
Adam Israelb2a07f52019-04-25 17:17:05 -040028import os
Adam Israelbf793522018-11-20 13:54:13 -050029
30
31@when('sshproxy.configured')
32@when_not('simple.installed')
33def install_simple_proxy_charm():
34 """Post-install actions.
35
36 This function will run when two conditions are met:
37 1. The 'sshproxy.configured' state is set
38 2. The 'simple.installed' state is not set
39
40 This ensures that the workload status is set to active only when the SSH
41 proxy is properly configured.
42 """
43 set_flag('simple.installed')
44 status_set('active', 'Ready!')
45
46
47@when('actions.touch')
48def touch():
Adam Israelb2a07f52019-04-25 17:17:05 -040049 if not in_action_context():
50 clear_flag('actions.touch')
51 return
52
Adam Israelbf793522018-11-20 13:54:13 -050053 err = ''
54 try:
55 filename = action_get('filename')
56 cmd = ['touch {}'.format(filename)]
57 result, err = charms.sshproxy._run(cmd)
Adam Israel6d84dbd2019-03-08 18:33:35 -050058 except Exception:
Adam Israelbf793522018-11-20 13:54:13 -050059 action_fail('command failed:' + err)
60 else:
61 action_set({'output': result})
62 finally:
63 clear_flag('actions.touch')
Adam Israelb2a07f52019-04-25 17:17:05 -040064
65
66def in_action_context():
67 """Determine whether we're running on an action context."""
68 return 'JUJU_ACTION_UUID' in os.environ