| Adam Israel | 102cd7f | 2018-05-08 12:55:29 -0400 | [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 ( |
| Adam Israel | 7a5344c | 2018-06-21 15:57:00 -0400 | [diff] [blame] | 8 | clear_flag, |
| 9 | set_flag, |
| Adam Israel | 102cd7f | 2018-05-08 12:55:29 -0400 | [diff] [blame] | 10 | when, |
| 11 | when_not, |
| 12 | ) |
| 13 | import charms.sshproxy |
| 14 | |
| 15 | |
| 16 | @when('sshproxy.configured') |
| 17 | @when_not('simple.installed') |
| 18 | def install_simple_proxy_charm(): |
| 19 | """Post-install actions. |
| 20 | |
| 21 | This function will run when two conditions are met: |
| 22 | 1. The 'sshproxy.configured' state is set |
| 23 | 2. The 'simple.installed' state is not set |
| 24 | |
| 25 | This ensures that the workload status is set to active only when the SSH |
| 26 | proxy is properly configured. |
| 27 | """ |
| 28 | set_flag('simple.installed') |
| 29 | status_set('active', 'Ready!') |
| 30 | |
| 31 | |
| 32 | @when('actions.touch') |
| 33 | def touch(): |
| 34 | err = '' |
| 35 | try: |
| 36 | filename = action_get('filename') |
| 37 | cmd = ['touch {}'.format(filename)] |
| 38 | result, err = charms.sshproxy._run(cmd) |
| 39 | except: |
| 40 | action_fail('command failed:' + err) |
| 41 | else: |
| garciadeblas | 74ebaf5 | 2018-10-01 15:28:51 +0200 | [diff] [blame] | 42 | action_set({'output': result}) |
| Adam Israel | 102cd7f | 2018-05-08 12:55:29 -0400 | [diff] [blame] | 43 | finally: |
| Adam Israel | 7a5344c | 2018-06-21 15:57:00 -0400 | [diff] [blame] | 44 | clear_flag('actions.touch') |