1 --- plugins/vsys_privs.py (.../NodeManager-1.8-18) (revision 0)
2 +++ plugins/vsys_privs.py (.../NodeManager-1.8-19) (revision 15536)
5 +vsys sub-configurator. Maintains configuration parameters associated with vsys scripts.
6 +All slice attributes with the prefix vsys_ are written into configuration files on the
7 +node for the reference of vsys scripts.
14 +VSYS_PRIV_DIR = "/etc/planetlab/vsys-attributes"
16 +def start(options, conf):
17 + logger.log("vsys_privs plugin v0.1")
18 + if (not os.path.exists(VSYS_PRIV_DIR)):
19 + os.makedirs(VSYS_PRIV_DIR)
20 + logger.log("Created vsys attributes dir")
22 +def GetSlivers(data, config=None, plc=None):
25 + # Parse attributes and update dict of scripts
26 + for sliver in data['slivers']:
27 + slice = sliver['name']
28 + for attribute in sliver['attributes']:
29 + tag = attribute['tagname']
30 + value = attribute['value']
31 + if tag.startswith('vsys_'):
32 + if (privs.has_key(slice)):
33 + slice_priv = privs[slice]
34 + if (slice_priv.has_key(tag)):
35 + slice_priv[tag].append(value)
37 + slice_priv[tag]=[value]
39 + privs[slice] = slice_priv
41 + privs[slice] = {tag:[value]}
43 + cur_privs = read_privs()
44 + write_privs(cur_privs, privs)
48 + priv_finder = os.walk(VSYS_PRIV_DIR)
49 + priv_find = [i for i in priv_finder]
50 + (rootdir,slices,foo) = priv_find[0]
52 + for slice in slices:
55 + if (len(priv_find)>1):
56 + for (slicedir,bar,tagnames) in priv_find[1:]:
58 + # The depth of the vsys-privileges directory = 1
61 + for tagname in tagnames:
62 + tagfile = os.path.join(slicedir,tagname)
63 + values_n = file(tagfile).readlines()
64 + values = map(lambda s:s.rstrip(),values_n)
65 + slice = os.path.basename(slicedir)
66 + cur_privs[slice][tagname]=values
70 +def write_privs(cur_privs,privs):
71 + for slice in privs.keys():
72 + variables = privs[slice]
73 + slice_dir = os.path.join(VSYS_PRIV_DIR,slice)
74 + if (not os.path.exists(slice_dir)):
77 + # Add values that do not exist
78 + for k in variables.keys():
80 + if (cur_privs.has_key(slice)
81 + and cur_privs[slice].has_key(k)
82 + and cur_privs[slice][k] == v):
83 + # The binding has not changed
86 + v_file = os.path.join(slice_dir, k)
87 + f = open(v_file,'w')
91 + logger.log("Added vsys attribute %s for %s"%(k,slice))
93 + # Remove files and directories
95 + for slice in cur_privs.keys():
96 + variables = cur_privs[slice]
97 + slice_dir = os.path.join(VSYS_PRIV_DIR,slice)
99 + # Add values that do not exist
100 + for k in variables.keys():
101 + if (privs.has_key(slice)
102 + and cur_privs[slice].has_key(k)):
103 + # ok, spare this tag
104 + print "Sparing %s, %s "%(slice,k)
106 + v_file = os.path.join(slice_dir, k)
109 + if (not privs.has_key(slice)):
110 + os.rmdir(slice_dir)
113 +if __name__ == "__main__":
114 + test_slivers = {'slivers':[
115 + {'name':'foo','attributes':[
116 + {'tagname':'vsys_m','value':'2'},
117 + {'tagname':'vsys_m','value':'3'},
118 + {'tagname':'vsys_m','value':'4'}
120 + {'name':'bar','attributes':[
121 + #{'tagname':'vsys_x','value':'z'}
125 + GetSlivers(test_slivers)