3 # Script for basic access to the PlanetLab Central (PLC) configuration
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2006 The Trustees of Princeton University
9 # $Id: plc-config,v 1.1.1.1 2006/03/27 17:36:46 mlhuang Exp $
17 from plc_config import PLCConfiguration
22 Script to access the PLC configuration file store.
24 Usage: %s [OPTION]... [FILES]
27 --shell Output shell configuration file
28 --python Output Python configuration file
29 --php Output PHP configuration file
33 --variables List names of all variables
34 --packages List names of all packages
35 --comps List comps.xml from configuration
37 Basic variable value manipulation:
39 --category= Category identifier
40 --variable= Variable identifier
41 --value= Variable value
43 Basic package list manipulation:
45 --group= Package group identifier
46 --package= Package name
51 -h, --help This message
52 -s, --save Save changes to first configuration file
53 """.lstrip() % sys.argv[0]
58 plc = PLCConfiguration()
69 longopts = ["shell", "bash", "python",
76 "category=", "variable=", "value=",
77 "group=", "package=", "type=",
82 (opts, argv) = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts)
83 except Exception, err:
84 sys.stderr.write("Error: " + str(err) + os.linesep)
87 for (opt, optval) in opts:
88 if opt == "--shell" or \
91 output = plc.output_shell
93 output = plc.output_php
95 output = plc.output_xml
96 elif opt == "--variables":
97 output = plc.output_variables
98 elif opt == "--packages":
99 output = plc.output_packages
100 elif opt == "--groups":
101 output = plc.output_groups
102 elif opt == "--comps":
103 output = plc.output_comps
104 elif opt == "--category":
105 category['id'] = optval
106 elif opt == "--variable":
107 variable['id'] = optval
108 elif opt == "--value":
109 variable['value'] = optval
110 elif opt == "--group":
112 elif opt == "--package":
113 package['name'] = optval
114 elif opt == "--type":
115 package['type'] = optval
116 elif opt == '-s' or opt == "--save":
118 elif opt == '-h' or opt == "--help":
123 argv = ["/etc/planetlab/plc_config.xml"]
131 except Exception, err:
132 sys.stderr.write("Error: %s: %s" % (file, str(err)) + os.linesep)
135 # --category, --variable, --value
136 if category.has_key('id') and variable.has_key('id'):
137 if variable.has_key('value'):
138 plc.set(category, variable)
140 (category, variable) = plc.get(category['id'], variable['id'])
141 if variable.has_key('value'):
142 print variable['value']
144 # --shell, --php, --xml
145 if output is not None:
146 sys.stdout.write(output())
153 if __name__ == '__main__':