1
from landscape.ui.constants import NOT_MANAGED, CANONICAL_MANAGED
4
from landscape.ui.model.registration.proxy import RegistrationProxy
5
from landscape.ui.model.configuration.state import StateError
8
class ConfigControllerLockError(Exception):
12
class ConfigController(object):
14
L{ConfigContoller} defines actions to take against a configuration object,
15
providing starting values from the file, allowing them to be changed
16
transiently, reverted or committed.
19
DEFAULT_DEDICATED_ACCOUNT_NAME = "standalone"
21
def __init__(self, configuration):
23
self._configuration = configuration
24
self._initialised = True
26
def __getattr__(self, name):
27
if name in self.__dict__:
28
return self.__dict__[name]
30
return getattr(self._configuration, name)
32
def __setattr__(self, name, value):
33
# this test allows attributes to be set in the __init__ method
34
if not '_initialised' in self.__dict__:
35
return object.__setattr__(self, name, value)
36
if name in ConfigController.__dict__:
37
return object.__setattr__(self, name, value)
40
setattr(self._configuration, name, value)
41
self._configuration.modify()
42
except AttributeError:
43
return object.__setattr__(self, name, value)
45
self._configuration.modify()
49
Load the initial data from the configuration.
51
return self._configuration.load_data()
55
Revert settings to those the configuration object originally found.
58
self._configuration.revert()
60
# We probably don't care.
61
logging.info("landscape-client-settings-ui reverted with no "
64
def persist(self, on_notify, on_error, on_succeed, on_fail):
65
"Persist settings via the configuration object."
67
self._configuration.persist()
69
# We probably don't care.
70
logging.info("landscape-client-settings-ui committed with no "
72
if self._configuration.management_type == NOT_MANAGED:
73
self.disable(on_notify, on_succeed, on_fail)
75
self.register(on_notify, on_error, on_succeed, on_fail)
77
def register(self, notify_method, error_method, succeed_method,
80
Perform registration using the L{RegistrationProxy}.
83
def registration_fail_wrapper():
84
fail_method(action="Registering client")
86
def registration_succeed_wrapper():
87
succeed_method(action="Registering client")
89
registration = RegistrationProxy(
90
on_register_notify=notify_method,
91
on_register_error=error_method,
92
on_register_succeed=registration_succeed_wrapper,
93
on_register_fail=registration_fail_wrapper)
94
if self._configuration.management_type == CANONICAL_MANAGED:
95
notify_method("Attempting to register at %s" %
96
self._configuration.hosted_landscape_host)
98
notify_method("Attempting to register at %s" %
99
self._configuration.local_landscape_host)
100
registration.register(self._configuration.get_config_filename())
103
def disable(self, notify_method, succeed_method, fail_method):
105
Disable landscape client via the L{RegistrationProxy}.
108
def disabling_fail_wrapper():
109
fail_method(action="Disabling client")
111
def disabling_succeed_wrapper():
112
succeed_method(action="Disabling client")
114
registration = RegistrationProxy(
115
on_disable_succeed=disabling_succeed_wrapper,
116
on_disable_fail=disabling_fail_wrapper)
117
notify_method("Attempting to disable landscape client.")
118
registration.disable()