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):
24 if 'slivers' not in data:
25 logger.log_missing_data("vsys_privs.GetSlivers",'slivers')
31 # Parse attributes and update dict of scripts
32 if 'slivers' not in data:
33 logger.log_missing_data("vsys_privs.GetSlivers",'slivers')
35 for sliver in data['slivers']:
36 slice = sliver['name']
37 for attribute in sliver['attributes']:
38 tag = attribute['tagname']
39 value = attribute['value']
40 if tag.startswith('vsys_'):
41 if (privs.has_key(slice)):
42 slice_priv = privs[slice]
43 if (slice_priv.has_key(tag)):
44 slice_priv[tag].append(value)
46 slice_priv[tag]=[value]
48 privs[slice] = slice_priv
50 privs[slice] = {tag:[value]}
52 cur_privs = read_privs()
53 write_privs(cur_privs, privs)
57 priv_finder = os.walk(VSYS_PRIV_DIR)
58 priv_find = [i for i in priv_finder]
59 (rootdir,slices,foo) = priv_find[0]
64 if (len(priv_find)>1):
65 for (slicedir,bar,tagnames) in priv_find[1:]:
67 # The depth of the vsys-privileges directory = 1
70 for tagname in tagnames:
71 tagfile = os.path.join(slicedir,tagname)
72 values_n = file(tagfile).readlines()
73 values = map(lambda s:s.rstrip(),values_n)
74 slice = os.path.basename(slicedir)
75 cur_privs[slice][tagname]=values
79 def write_privs(cur_privs,privs):
80 for slice in privs.keys():
81 variables = privs[slice]
82 slice_dir = os.path.join(VSYS_PRIV_DIR,slice)
83 if (not os.path.exists(slice_dir)):
86 # Add values that do not exist
87 for k in variables.keys():
89 if (cur_privs.has_key(slice)
90 and cur_privs[slice].has_key(k)
91 and cur_privs[slice][k] == v):
92 # The binding has not changed
95 v_file = os.path.join(slice_dir, k)
100 logger.log("Added vsys attribute %s for %s"%(k,slice))
102 # Remove files and directories
104 for slice in cur_privs.keys():
105 variables = cur_privs[slice]
106 slice_dir = os.path.join(VSYS_PRIV_DIR,slice)
108 # Add values that do not exist
109 for k in variables.keys():
110 if (privs.has_key(slice)
111 and cur_privs[slice].has_key(k)):
113 print "Sparing %s, %s "%(slice,k)
115 v_file = os.path.join(slice_dir, k)
118 if (not privs.has_key(slice)):
122 if __name__ == "__main__":
123 test_slivers = {'slivers':[
124 {'name':'foo','attributes':[
125 {'tagname':'vsys_m','value':'2'},
126 {'tagname':'vsys_m','value':'3'},
127 {'tagname':'vsys_m','value':'4'}
129 {'name':'bar','attributes':[
130 #{'tagname':'vsys_x','value':'z'}
134 GetSlivers(test_slivers)