rename directory
[sfa.git] / plc / addinitscript.py
1 ##
2 # A simple tool for adding an initscript via the PLCAPI. I couldn't find the
3 # obvious way to do this through the PL interface, so I wrote this utility to
4 # do it.
5 #
6 # It takes two command line parameters: an initscript name and the contents of
7 # the initscript.
8 #
9 # For example,
10 #     addinitscript.py foo "echo test"
11 ##
12
13 import getopt
14 import sys
15 import tempfile
16
17 from config import *
18
19 def connect_shell():
20     global pl_auth, shell
21
22     # get PL account settings from config module
23     pl_auth = get_pl_auth()
24
25     # connect to planetlab
26     if "Url" in pl_auth:
27         import remoteshell
28         shell = remoteshell.RemoteShell()
29     else:
30         import PLC.Shell
31         shell = PLC.Shell.Shell(globals = globals())
32
33 def main():
34     connect_shell()
35
36     if len(sys.argv)<3:
37        print "syntax: addinitscript.py name value"
38        sys.exit(-1)
39
40     name = sys.argv[1]
41     value = sys.argv[2]
42
43     fields={}
44     fields['enabled'] = True
45     fields['name'] = name
46     fields['script'] = value
47     shell.AddInitScript(pl_auth, fields)
48
49 if __name__ == "__main__":
50     main()