a5ebd7562193150682c38f2d035df96d715cd8db
[nodemanager.git] / proper.py
1 """Generate Proper configuration file"""
2
3 import os
4 import logger
5
6 def GetSlivers(data):
7     # anyone can execute the get_file_flags operation (since it is applied
8     # within the caller's vserver and the command lsattr gives the same
9     # info anyway) or get the version string.  wait is harmless too since
10     # the caller needs to know the child ID.  and we let any slice unmount
11     # directories in its own filesystem, mostly as a workaround for some
12     # Stork problems.
13     buf = """
14 *: get_file_flags
15 *: version
16 *: wait
17 +: unmount
18 """.lstrip()
19
20     for d in data:
21         for sliver in d['slivers']:
22             for attribute in sliver['attributes']:
23                 if attribute['name'] == 'proper_op':
24                     buf += "%s: %s\n" % (sliver['name'], attribute['value'])
25
26     try: os.makedirs("/etc/proper")
27     except OSError: pass
28     propd_conf = open("/etc/proper/propd.conf", "r+")
29
30     if propd_conf.read() != buf:
31         logger.log('proper: updating /etc/propd.conf')
32         propd_conf.seek(0)
33         propd_conf.write(buf)
34         propd_conf.truncate()
35         logger.log('proper: restarting proper')
36         os.system('/etc/init.d/proper restart')
37
38     propd_conf.close()
39
40 def start(options, config):
41     pass