1 #!/usr/bin/env /usr/bin/plcsh
3 # Bootstraps the PLC database with a default administrator account and
4 # a default site, defines default slice attribute types, and
5 # creates/updates default system slices.
6 # scan ordered scripts in /etc/planetlab/db-config.d
8 # Mark Huang <mlhuang@cs.princeton.edu>
9 # Copyright (C) 2006 The Trustees of Princeton University
10 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
14 from optparse import OptionParser
16 from plc_config import PLCConfiguration
18 def GetSnippets(directory):
20 if os.path.exists(directory):
22 filenames = os.listdir(directory)
24 raise Exception, "Error when opening %s (%s)" % \
25 (os.path.join(dir, file), e)
27 # ignore files that contain either ~ or .
28 ignore_tokens = ("~",".")
30 for filename in filenames:
32 for token in ignore_tokens:
33 if filename.find(token)>=0:
38 parts = filename.split('-')
40 name = '-'.join(parts)
42 number = int(parts[0])
43 entry = numberedfiles.get(number,[])
45 numberedfiles[number]=entry
52 print "db-config: ignored %s snippet" % filename
55 keys = numberedfiles.keys()
58 for filename in numberedfiles[k]:
59 filenames.append(filename)
63 cfg = PLCConfiguration()
65 variables = cfg.variables()
67 usage="%prog [-- options] [steps]"
68 parser = OptionParser(usage=usage )
69 parser.add_option("-l","--list",dest="list_steps",action="store_true",default=False,
70 help="Lists available steps")
71 parser.add_option("-v","--verbose",dest="verbose",action="store_true",default=False,
74 (options,steps) = parser.parse_args()
76 # Load variables into dictionaries
77 for category_id, (category, variablelist) in variables.iteritems():
78 globals()[category_id] = dict(zip(variablelist.keys(),
79 [variable['value'] for variable in variablelist.values()]))
81 directory="/etc/planetlab/db-config.d"
82 snippets = GetSnippets(directory)
84 for snippet in snippets:
87 # no steps provided on the command-line : run them all
92 if snippet.find (step)>=0 : selected=True
96 if options.list_steps:
97 if not options.verbose:
100 print "Found step %s/%s"%(directory,snippet)
101 os.system("rpm -qf %s/%s"%(directory,snippet))
104 fullpath = os.path.join(directory, snippet)
106 print "Running step %s"%fullpath
109 if __name__ == '__main__':