| Adam Israel | bf79352 | 2018-11-20 13:54:13 -0500 | [diff] [blame] | 1 | from charmhelpers.core.hookenv import ( |
| 2 | action_get, |
| 3 | action_fail, |
| 4 | action_set, |
| 5 | status_set, |
| 6 | ) |
| 7 | from charms.reactive import ( |
| 8 | clear_flag, |
| 9 | set_flag, |
| 10 | when, |
| 11 | when_not, |
| 12 | ) |
| 13 | import charms.sshproxy |
| Adam Israel | b2a07f5 | 2019-04-25 17:17:05 -0400 | [diff] [blame] | 14 | import os |
| Adam Israel | bf79352 | 2018-11-20 13:54:13 -0500 | [diff] [blame] | 15 | |
| 16 | |
| 17 | @when('sshproxy.configured') |
| 18 | @when_not('simple.installed') |
| 19 | def 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') |
| 34 | def touch(): |
| Adam Israel | b2a07f5 | 2019-04-25 17:17:05 -0400 | [diff] [blame] | 35 | if not in_action_context(): |
| 36 | clear_flag('actions.touch') |
| 37 | return |
| 38 | |
| Adam Israel | bf79352 | 2018-11-20 13:54:13 -0500 | [diff] [blame] | 39 | err = '' |
| 40 | try: |
| 41 | filename = action_get('filename') |
| 42 | cmd = ['touch {}'.format(filename)] |
| 43 | result, err = charms.sshproxy._run(cmd) |
| Adam Israel | 6d84dbd | 2019-03-08 18:33:35 -0500 | [diff] [blame] | 44 | except Exception: |
| Adam Israel | bf79352 | 2018-11-20 13:54:13 -0500 | [diff] [blame] | 45 | action_fail('command failed:' + err) |
| 46 | else: |
| 47 | action_set({'output': result}) |
| 48 | finally: |
| 49 | clear_flag('actions.touch') |
| Adam Israel | b2a07f5 | 2019-04-25 17:17:05 -0400 | [diff] [blame] | 50 | |
| 51 | |
| 52 | def in_action_context(): |
| 53 | """Determine whether we're running on an action context.""" |
| 54 | return 'JUJU_ACTION_UUID' in os.environ |