integrate exmachina configuration management layer

- add exmachina code and test code
- modify plinth.py to listen for shared secret on stdin at start
  (if appropriate flag is set) and try to connect to exmachina daemon
- use exmachina to read and set /etc/hostname as a demo
- update plinth init.d script to start exmachina and share keys
- update docs with new deps and run instructions
This commit is contained in:
bnewbold committed 2012-07-12 22:25:50 -04:00
1 parent 337560b0d1
commit f1e764f2e5
11 files changed
+544 -24

No files matched your search

+16 -12
View File
@@ -41,20 +41,18 @@ def valid_hostname(name):
def set_hostname(hostname):
"Sets machine hostname to hostname"
cfg.log.info("Writing '%s' to /etc/hostname" % hostname)
unslurp("/etc/hostname", hostname+"\n")
cfg.log.info("Writing '%s' to /etc/hostname with exmachina" % hostname)
try:
retcode = subprocess.call("/etc/init.d/hostname.sh start", shell=True)
if retcode < 0:
cfg.log.error("Hostname restart terminated by signal: return code is %s" % retcode)
else:
cfg.log.debug("Hostname restart returned %s" % retcode)
cfg.exmachina.augeas.set("/files/etc/hostname/*", hostname)
cfg.exmachina.augeas.save()
# don't persist/cache change unless it was saved successfuly
sys_store = filedict_con(cfg.store_file, 'sys')
sys_store['hostname'] = hostname
cfg.exmachina.initd.restart("hostname.sh") # is hostname.sh debian-only?
except OSError, e:
raise cherrypy.HTTPError(500, "Hostname restart failed: %s" % e)
sys_store = filedict_con(cfg.store_file, 'sys')
sys_store['hostname'] = hostname
class general(FormPlugin, PagePlugin):
url = ["/sys/config"]
order = 30
@@ -72,8 +70,11 @@ class general(FormPlugin, PagePlugin):
def main(self, message='', **kwargs):
sys_store = filedict_con(cfg.store_file, 'sys')
hostname = cfg.exmachina.augeas.get("/files/etc/hostname/*")
# this layer of persisting configuration in sys_store could/should be
# removed -BLN
defaults = {'time_zone': "slurp('/etc/timezone').rstrip()",
'hostname': "gethostname()",
'hostname': "hostname",
}
for k,c in defaults.items():
if not k in kwargs:
@@ -81,6 +82,8 @@ class general(FormPlugin, PagePlugin):
kwargs[k] = sys_store[k]
except KeyError:
exec("if not '%(k)s' in kwargs: sys_store['%(k)s'] = kwargs['%(k)s'] = %(c)s" % {'k':k, 'c':c})
# over-ride the sys_store cached value
kwargs['hostname'] = hostname
## Get the list of supported timezones and the index in that list of the current one
module_file = __file__
@@ -120,7 +123,8 @@ class general(FormPlugin, PagePlugin):
old_val = sys_store['hostname']
try:
set_hostname(hostname)
except:
except Exception, e:
cfg.log.error(e)
cfg.log.info("Trying to restore old hostname value.")
set_hostname(old_val)
raise