From: Scott Baker Date: Wed, 16 Oct 2013 06:39:23 +0000 (-0700) Subject: automatically touch slices with lxcsu if vsys_sysctl attribute changes X-Git-Tag: nodemanager-5.2-9~5 X-Git-Url: http://git.onelab.eu/?p=nodemanager.git;a=commitdiff_plain;h=63e92906c99bb95dd26b7f38dbfe443d53e3dad9 automatically touch slices with lxcsu if vsys_sysctl attribute changes --- diff --git a/plugins/vsys_sysctl.py b/plugins/vsys_sysctl.py new file mode 100644 index 0000000..3539ab1 --- /dev/null +++ b/plugins/vsys_sysctl.py @@ -0,0 +1,60 @@ +""" vsys_sysctl + + Touches a slice with lxcsu if it has vsys_sysctl attributes +""" + +import logger +import os + +def start(): + logger.log("vsys_sysctl: plugin starting up...") + +def GetSlivers(data, config=None, plc=None): + """For each sliver with the vsys attribute, set the script ACL, create the vsys directory in the slice, and restart vsys.""" + + if 'slivers' not in data: + logger.log_missing_data("vsys.GetSlivers",'slivers') + return + + slices = [] + + for sliver in data['slivers']: + slicename = sliver["name"] + for attribute in sliver['attributes']: + if attribute['tagname'].startswith('vsys_sysctl.'): + dir = "/vservers/%s/vsys_sysctl" % slicename + if not os.path.exists(dir): + try: + logger.log("vsys_sysctl: create dir %s" % dir) + os.mkdir(dir) + except: + logger.log("vsys_sysctl: failed to create dir %s" % dir) + + (junk, key) = attribute['tagname'].split(".",1) + value = str(attribute['value']) + + fn = os.path.join(dir, key) + if not test_value(fn, value): + # All we need to do to make vsys_sysctl work is to lxcsu + # into the slice and do anything. + result = os.system("lxcsu -r %s :" % slicename) + if result != 0: + logger.log("vsys_sysctl: failed to lxcsu into %s" % slicename) + continue + + # Store the key name and value inside of /vsys_sysctl in the + # slice. This lets us know that we've done the sysctl. + try: + logger.log("vsys_sysctl: create file %s value %s" % (fn, value)) + file(fn,"w").write(value+"\n") + except: + logger.log("vsys_sysctl: failed to create file %s" % fn) + +def test_value(fn, value): + try: + slice_value = file(fn,"r").readline().strip() + except: + slice_value = None + + return (value == slice_value) +