+def touchAcls()
+ '''Creates empty acl files for scripts.
+ To be ran in case of new scripts that appear in the backend.
+ Returns list of available scripts.'''
+ acls = []
+ scripts = []
+ for (root, dirs, files) in os.walk(VSYSBKEND):
+ for file in files:
+ if file.endswith(".acl"):
+ acls.append(file.rstrip(".acl")
+ else:
+ scripts.append(file)
+
+ for new in (Set(scripts) - Set(acls)):
+ logger.log("vsys: Found new script %s. Writing empty acl.")
+ f = open("%s/%s.acl" %(VSYSBKEND, new), "w")
+ f.write("\n")
+ f.close()
+
+ return scripts
+
+
+def writeAcls(currentscripts, oldscripts):
+ '''Creates .acl files for script in the script repo.'''
+ # Check each oldscript entry to see if we need to modify
+ _restartvsys = False
+ for (acl, oldslivers) in oldscripts.iteritems():
+ if (len(oldslivers) != len(currentscripts[acl])) or \
+ (len(Set(oldslivers) - Set(currentscript[acl])) != 0:
+ _restartvsys = True
+ logger.log("vsys: Updating %s.acl w/ slices %s" % (acl, currentscripts[acl])
+ f = open("%s/%s.acl" % (VSYSBKEND, acl), "w")
+ for slice in currentscripts[acl]: f.write("%s\n" % slice)
+ f.close()
+ # Trigger a restart
+ return _restartvsys
+
+
+def parseAcls():
+ '''Parse the frontend script acls. Return {script: [slices]} in conf.'''
+ # make a dict of what slices are in what acls.
+ for (root, dirs, files) in os.walk(VSYSBKEND):
+ for file in files:
+ if file.endswith(".acl"):
+ f = open(root+"/"+file,"r+")
+ scriptname = file.rstrip(".acl")
+ scriptacls[scriptname] = []
+ for slice in f.readlines():
+ scriptacls[scriptname].append(slice.rstrip())
+ f.close()
+ # return what scripts are configured for which slices.
+ return scriptacls
+
+
+def writeConf(slivers, oldslivers):
+ # Check if this is needed
+ if (len(slivers) != len(oldslivers)) or \
+ (len(Set(oldslivers) - Set(slivers)) ! = 0):
+ logger.log("vsys: Updating %s" % VSYSCONF)
+ f = open(VSYSCONF,"w")
+ for sliver in slivers:
+ f.write("/vservers/%(name)s/vsys %(name)s\n" % {"name": sliver})
+ f.truncate()
+ f.close()
+
+def parseConf();
+ '''Parse the vsys conf and return list of slices in conf.'''
+ scriptacls = {}
+ slicesinconf = []
+ f = open(VSYSCONF)