blob: af6644bdd6ae44847f319abfc348faaab173d0c0 [file] [log] [blame]
Adam Israelbf793522018-11-20 13:54:13 -05001from charmhelpers.core.hookenv import (
2 action_get,
3 action_fail,
4 action_set,
5 status_set,
6)
7from charms.reactive import (
8 clear_flag,
9 set_flag,
10 when,
11 when_not,
12)
13import charms.sshproxy
Adam Israelb2a07f52019-04-25 17:17:05 -040014import os
Adam Israelbf793522018-11-20 13:54:13 -050015
16
17@when('sshproxy.configured')
18@when_not('simple.installed')
19def install_simple_proxy_charm():
20 """Post-install actions.
21
22 This function will run when two conditions are met:
23 1. The 'sshproxy.configured' state is set
24 2. The 'simple.installed' state is not set
25
26 This ensures that the workload status is set to active only when the SSH
27 proxy is properly configured.
28 """
29 set_flag('simple.installed')
30 status_set('active', 'Ready!')
31
32
33@when('actions.touch')
34def touch():
Adam Israelb2a07f52019-04-25 17:17:05 -040035 if not in_action_context():
36 clear_flag('actions.touch')
37 return
38
Adam Israelbf793522018-11-20 13:54:13 -050039 err = ''
40 try:
41 filename = action_get('filename')
42 cmd = ['touch {}'.format(filename)]
43 result, err = charms.sshproxy._run(cmd)
Adam Israel6d84dbd2019-03-08 18:33:35 -050044 except Exception:
Adam Israelbf793522018-11-20 13:54:13 -050045 action_fail('command failed:' + err)
46 else:
47 action_set({'output': result})
48 finally:
49 clear_flag('actions.touch')
Adam Israelb2a07f52019-04-25 17:17:05 -040050
51
52def in_action_context():
53 """Determine whether we're running on an action context."""
54 return 'JUJU_ACTION_UUID' in os.environ