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 if 'slivers' not in data:
27 logger.log_missing_data("vsys_privs.GetSlivers",'slivers')
29 for sliver in data['slivers']:
30 slice = sliver['name']
31 for attribute in sliver['attributes']:
32 tag = attribute['tagname']
33 value = attribute['value']
34 if tag.startswith('vsys_'):
35 if (privs.has_key(slice)):
36 slice_priv = privs[slice]
37 if (slice_priv.has_key(tag)):
38 slice_priv[tag].append(value)
40 slice_priv[tag]=[value]
42 privs[slice] = slice_priv
44 privs[slice] = {tag:[value]}
46 cur_privs = read_privs()
47 write_privs(cur_privs, privs)
51 priv_finder = os.walk(VSYS_PRIV_DIR)
52 priv_find = [i for i in priv_finder]
53 (rootdir,slices,foo) = priv_find[0]
58 if (len(priv_find)>1):
59 for (slicedir,bar,tagnames) in priv_find[1:]:
61 # The depth of the vsys-privileges directory = 1
64 for tagname in tagnames:
65 tagfile = os.path.join(slicedir,tagname)
66 values_n = file(tagfile).readlines()
67 values = map(lambda s:s.rstrip(),values_n)
68 slice = os.path.basename(slicedir)
69 cur_privs[slice][tagname]=values
73 def write_privs(cur_privs,privs):
74 for slice in privs.keys():
75 variables = privs[slice]
76 slice_dir = os.path.join(VSYS_PRIV_DIR,slice)
77 if (not os.path.exists(slice_dir)):
80 # Add values that do not exist
81 for k in variables.keys():
83 if (cur_privs.has_key(slice)
84 and cur_privs[slice].has_key(k)
85 and cur_privs[slice][k] == v):
86 # The binding has not changed
89 v_file = os.path.join(slice_dir, k)
94 logger.log("Added vsys attribute %s for %s"%(k,slice))
96 # Remove files and directories
98 for slice in cur_privs.keys():
99 variables = cur_privs[slice]
100 slice_dir = os.path.join(VSYS_PRIV_DIR,slice)
102 # Add values that do not exist
103 for k in variables.keys():
104 if (privs.has_key(slice)
105 and cur_privs[slice].has_key(k)):
107 print "Sparing %s, %s "%(slice,k)
109 v_file = os.path.join(slice_dir, k)
112 if (not privs.has_key(slice)):
116 if __name__ == "__main__":
117 test_slivers = {'slivers':[
118 {'name':'foo','attributes':[
119 {'tagname':'vsys_m','value':'2'},
120 {'tagname':'vsys_m','value':'3'},
121 {'tagname':'vsys_m','value':'4'}
123 {'name':'bar','attributes':[
124 #{'tagname':'vsys_x','value':'z'}
128 GetSlivers(test_slivers)