2 vsys sub-configurator. Maintains configuration parameters associated with vsys scripts.
3 All slice attributes with the prefix vsys_ are written into configuration files on the
4 node for the reference of vsys scripts.
11 VSYS_PRIV_DIR = "/etc/planetlab/vsys-attributes"
13 def start(options, conf):
14 logger.log("vsys_privs plugin v0.1")
15 if (not os.path.exists(VSYS_PRIV_DIR)):
16 os.makedirs(VSYS_PRIV_DIR)
17 logger.log("Created vsys attributes dir")
19 def GetSlivers(data, config=None, plc=None):
22 # Parse attributes and update dict of scripts
23 for sliver in data['slivers']:
24 slice = sliver['name']
25 for attribute in sliver['attributes']:
26 tag = attribute['tagname']
27 value = attribute['value']
28 if tag.startswith('vsys_'):
29 if (privs.has_key(slice)):
30 slice_priv = privs[slice]
31 if (slice_priv.has_key(tag)):
32 slice_priv[tag].append(value)
34 slice_priv[tag]=[value]
36 privs[slice] = slice_priv
38 privs[slice] = {tag:[value]}
40 cur_privs = read_privs()
41 write_privs(cur_privs, privs)
45 priv_finder = os.walk(VSYS_PRIV_DIR)
46 priv_find = [i for i in priv_finder]
47 (rootdir,slices,foo) = priv_find[0]
52 if (len(priv_find)>1):
53 for (slicedir,bar,tagnames) in priv_find[1:]:
55 # The depth of the vsys-privileges directory = 1
58 for tagname in tagnames:
59 tagfile = os.path.join(slicedir,tagname)
60 values_n = file(tagfile).readlines()
61 values = map(lambda s:s.rstrip(),values_n)
62 slice = os.path.basename(slicedir)
63 cur_privs[slice][tagname]=values
67 def write_privs(cur_privs,privs):
68 for slice in privs.keys():
69 variables = privs[slice]
70 slice_dir = os.path.join(VSYS_PRIV_DIR,slice)
71 if (not os.path.exists(slice_dir)):
74 # Add values that do not exist
75 for k in variables.keys():
77 if (cur_privs.has_key(slice)
78 and cur_privs[slice].has_key(k)
79 and cur_privs[slice][k] == v):
80 # The binding has not changed
83 v_file = os.path.join(slice_dir, k)
88 logger.log("Added vsys attribute %s for %s"%(k,slice))
90 # Remove files and directories
92 for slice in cur_privs.keys():
93 variables = cur_privs[slice]
94 slice_dir = os.path.join(VSYS_PRIV_DIR,slice)
96 # Add values that do not exist
97 for k in variables.keys():
98 if (privs.has_key(slice)
99 and cur_privs[slice].has_key(k)):
101 print "Sparing %s, %s "%(slice,k)
103 v_file = os.path.join(slice_dir, k)
106 if (not privs.has_key(slice)):
110 if __name__ == "__main__":
111 test_slivers = {'slivers':[
112 {'name':'foo','attributes':[
113 {'tagname':'vsys_m','value':'2'},
114 {'tagname':'vsys_m','value':'3'},
115 {'tagname':'vsys_m','value':'4'}
117 {'name':'bar','attributes':[
118 #{'tagname':'vsys_x','value':'z'}
122 GetSlivers(test_slivers)