1 # Copyright 2019 Canonical Ltd.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 from charmhelpers
.core
.hookenv
import (
21 from charms
.reactive
import (
27 import charms
.sshproxy
31 @when('sshproxy.configured')
32 @when_not('simple.installed')
33 def install_simple_proxy_charm():
34 """Post-install actions.
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
40 This ensures that the workload status is set to active only when the SSH
41 proxy is properly configured.
43 set_flag('simple.installed')
44 status_set('active', 'Ready!')
47 @when('actions.touch')
49 if not in_action_context():
50 clear_flag('actions.touch')
55 filename
= action_get('filename')
56 cmd
= ['touch {}'.format(filename
)]
57 result
, err
= charms
.sshproxy
._run
(cmd
)
59 action_fail('command failed:' + err
)
61 action_set({'output': result
})
63 clear_flag('actions.touch')
66 def in_action_context():
67 """Determine whether we're running on an action context."""
68 return 'JUJU_ACTION_UUID' in os
.environ