Added ReCreate. Also added try catch to api eval of rpc method.
[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 sliver in data['slivers']:
21         for attribute in sliver['attributes']:
22             if attribute['name'] == 'proper_op':
23                 buf += "%s: %s\n" % (sliver['name'], attribute['value'])
24
25     try: os.makedirs("/etc/proper")
26     except OSError: pass
27     propd_conf = open("/etc/proper/propd.conf", "r+")
28
29     if propd_conf.read() != buf:
30         logger.log('proper: updating /etc/propd.conf')
31         propd_conf.seek(0)
32         propd_conf.write(buf)
33         propd_conf.truncate()
34         logger.log('proper: restarting proper')
35         os.system('/etc/init.d/proper restart')
36
37     propd_conf.close()
38
39 def start(options, config):
40     pass