~hazmat/pyjuju/security-policy-rules-redux

« back to all changes in this revision

Viewing changes to juju/state/environment.py

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
from txzookeeper.utils import retry_change
7
7
 
8
 
from ensemble.environment.config import EnvironmentsConfig
9
 
from ensemble.state.errors import EnvironmentStateNotFound
10
 
from ensemble.state.base import StateBase
11
 
 
12
 
 
13
 
GLOBAL_SETTINGS = "/global_settings"
 
8
from juju.environment.config import EnvironmentsConfig
 
9
from juju.state.errors import EnvironmentStateNotFound
 
10
from juju.state.base import StateBase
 
11
 
 
12
 
 
13
SETTINGS_PATH = "/settings"
14
14
 
15
15
 
16
16
class EnvironmentStateManager(StateBase):
57
57
 
58
58
    This can't be stored directly in the environment, as that has access
59
59
    restrictions. The runtime state can be accessed from all connected
60
 
    ensemble clients.
 
60
    juju clients.
61
61
    """
62
62
 
 
63
    def set_provider_type(self, provider_type):
 
64
        return self._set_value("provider-type", provider_type)
 
65
 
 
66
    def get_provider_type(self):
 
67
        return self._get_value("provider-type")
 
68
 
63
69
    def is_debug_log_enabled(self):
64
70
        """Find out if the debug log is enabled. Returns a boolean.
65
71
        """
66
 
        return self._get_value("debug_log", False)
 
72
        return self._get_value("debug-log", False)
67
73
 
68
74
    def set_debug_log(self, enabled):
69
75
        """Enable/Disable the debug log.
70
76
 
71
77
        :param enabled: Boolean denoting whether the log should be enabled.
72
78
        """
73
 
        return self._set_value("debug_log", bool(enabled))
 
79
        return self._set_value("debug-log", bool(enabled))
74
80
 
75
81
    @inlineCallbacks
76
82
    def _get_value(self, key, default=None):
77
83
        try:
78
 
            content, stat = yield self._client.get(GLOBAL_SETTINGS)
 
84
            content, stat = yield self._client.get(SETTINGS_PATH)
79
85
        except zookeeper.NoNodeException:
80
86
            returnValue(default)
81
87
        data = yaml.load(content)
91
97
            data[key] = value
92
98
            return yaml.safe_dump(data)
93
99
 
94
 
        return retry_change(self._client, GLOBAL_SETTINGS, set_value)
 
100
        return retry_change(self._client, SETTINGS_PATH, set_value)
95
101
 
96
102
    def watch_settings_changes(self, callback, error_callback=None):
97
103
        """Register a callback to invoked when the runtime changes.
139
145
        # This logic will break if the node is removed, and so will
140
146
        # the function below, but the internal logic never removes
141
147
        # it, so we do not handle this case.
142
 
        exists_d, watch_d = self._client.exists_and_watch(GLOBAL_SETTINGS)
 
148
        exists_d, watch_d = self._client.exists_and_watch(SETTINGS_PATH)
143
149
        exists = yield exists_d
144
150
 
145
151
        if exists:
161
167
        if not self._watching or not self._client.connected:
162
168
            returnValue(False)
163
169
 
164
 
        exists_d, watch_d = self._client.exists_and_watch(GLOBAL_SETTINGS)
 
170
        exists_d, watch_d = self._client.exists_and_watch(SETTINGS_PATH)
165
171
 
166
172
        try:
167
173
            yield self._callback(change_event)