3 Touches a slice with lxcsu if it has vsys_sysctl attributes
10 logger.log("vsys_sysctl: plugin starting up...")
12 def GetSlivers(data, config=None, plc=None):
13 """For each sliver with the vsys attribute, set the script ACL, create the vsys directory in the slice, and restart vsys."""
15 if 'slivers' not in data:
16 logger.log_missing_data("vsys.GetSlivers", 'slivers')
21 for sliver in data['slivers']:
22 slicename = sliver["name"]
23 for attribute in sliver['attributes']:
24 if attribute['tagname'].startswith('vsys_sysctl.'):
25 dir = "/vservers/%s/vsys_sysctl" % slicename
26 if not os.path.exists(dir):
28 logger.log("vsys_sysctl: create dir %s" % dir)
31 logger.log("vsys_sysctl: failed to create dir %s" % dir)
33 (junk, key) = attribute['tagname'].split(".", 1)
34 value = str(attribute['value'])
36 fn = os.path.join(dir, key)
37 if not test_value(fn, value):
38 # All we need to do to make vsys_sysctl work is to lxcsu
39 # into the slice and do anything.
40 result = os.system("lxcsu -r %s :" % slicename)
42 logger.log("vsys_sysctl: failed to lxcsu into %s" % slicename)
45 # Store the key name and value inside of /vsys_sysctl in the
46 # slice. This lets us know that we've done the sysctl.
48 logger.log("vsys_sysctl: create file %s value %s" % (fn, value))
49 with open(fn, "w") as f:
52 logger.log("vsys_sysctl: failed to create file %s" % fn)
54 def test_value(fn, value):
56 slice_value = file(fn, "r").readline().strip()
60 return (value == slice_value)