long awaited vsys callback. Still in progress.
[nodemanager.git] / vsys.py
1 # $Id$
2 # $URL$
3
4 """vsys configurator.  Maintains ACLs and script pipes inside vservers based on slice attributes."""
5
6 import logger
7 import os
8
9
10 def start(options, config):
11     pass
12
13 def GetSlivers(data):
14     """For each sliver with the vsys attribute, set the script ACL, create the vsys directory in the slice, and restart vsys."""
15     confedSlivers = parseConf("/etc/vsys.conf")
16     newSlivers = []
17     for sliver in data['slivers']:
18         for attribute in sliver['attributes']:
19             if attribute['name'] == 'vsys':
20                 # As the name implies, when we find an attribute, we
21                 createVsysDir(sliver)
22                 if sliver['name'] not in confedSlivers: newSlivers.append(sliver['name'])
23
24     writeConf(confedSlivers + newSlivers, "/etc/vsys.conf")
25
26 def secureScripts():
27
28 def createVsysDir(sliver):
29     '''Create /vsys directory in slice.  Update vsys conf file.'''
30     try: os.makedirs("/vservers/%s/vsys" % sliver['name'])
31     except OSError: pass
32
33
34 def parseConf(file):
35     '''Parse the vserver conf.  Return [slices] in conf.'''
36     slices = []
37     f = open(file)
38     for line in f.readlines():
39         (slice, path) = line.split()
40         slices.append(slice)
41     f.close()
42     return slices
43
44
45 def writeConf(slivers, file):
46     f = open(file,"w")
47     for sliver in slivers:
48         f.write("/vservers/%(name)s/vsys %(name)s\n" % {"name": sliver})
49     f.truncate()
50     f.close()