changes for 3.0
[monitor.git] / getconf.py
index 802eced..1008c74 100755 (executable)
@@ -1,45 +1,56 @@
 #!/usr/bin/python
 
-import auth
 import plc
+api = plc.getAuthAPI()
 import sys
 import os
+import config
 
-def getconf(hostname):
-       api = plc.PLC(auth.auth, auth.plc)
+def getconf(hostname, force=False, media=None):
        n = api.GetNodes(hostname)
-       filename = "bootcd-alpha/" + hostname + ".txt"
-       if not os.path.exists(filename):
-               f = open("bootcd-alpha/" + hostname + ".txt", 'w')
+       filename = "bootcd/" + hostname + ".txt"
+       if not os.path.exists(filename) or force:
+               f = open("bootcd/" + hostname + ".txt", 'w')
                f.write( api.AdmGenerateNodeConfFile(n[0]['node_id']) )
                f.close()
-               print os.system("cd bootcd-alpha; ./build.sh -f %s.txt -t iso -o /plc/data/var/www/html/bootcds/%s.iso &> /dev/null" % ( hostname, hostname))
-               print os.system("cd bootcd-alpha; ./build.sh -f %s.txt -t usb_partition -o /plc/data/var/www/html/bootcds/%s-partition.usb &> /dev/null" % ( hostname, hostname))
+               print os.system("cd bootcd; ./build.sh -f %s.txt -t iso -o /plc/data/var/www/html/bootcds/%s.iso &> /dev/null" % ( hostname, hostname))
+               print os.system("cd bootcd; ./build.sh -f %s.txt -t usb_partition -o /plc/data/var/www/html/bootcds/%s-partition.usb &> /dev/null" % ( hostname, hostname))
        else:
                # assume that the images have already been generated..
                pass
 
        args = {}
-       args['url_list']  = "   http://pl-virtual-03.cs.princeton.edu/bootcds/%s-partition.usb\n" % hostname
-       args['url_list'] += "   http://pl-virtual-03.cs.princeton.edu/bootcds/%s.iso" % hostname
-       #print "http://pl-virtual-03.cs.princeton.edu/bootcds/%s.usb\n" % hostname
+       if not media:
+               args['url_list']  = "   http://%s/bootcds/%s-partition.usb\n" % (config.MONITOR_HOSTNAME, hostname)
+               args['url_list'] += "   http://%s/bootcds/%s.iso" % (config.MONITOR_HOSTNAME, hostname)
+       else:
+               if media == "usb":
+                       args['url_list']  = "   http://%s/bootcds/%s-partition.usb\n" % (config.MONITOR_HOSTNAME, hostname)
+               elif media == "iso":
+                       args['url_list']  = "   http://%s/bootcds/%s.iso" % (config.MONITOR_HOSTNAME, hostname)
+               else:
+                       args['url_list']  = "   http://%s/bootcds/%s-partition.usb\n" % (config.MONITOR_HOSTNAME, hostname)
+                       args['url_list'] += "   http://%s/bootcds/%s.iso" % (config.MONITOR_HOSTNAME, hostname)
+                       
 
        return args
 
 if __name__ == '__main__':
-       from config import config as cfg
-       from optparse import OptionParser
-       parser = OptionParser()
-       parser.set_defaults(media='both')
+       import parser as parsermodule
+
+       parser = parsermodule.getParser()
+       parser.set_defaults(media='both', force=False)
        parser.add_option("", "--media", dest="media", metavar="usb, iso, both", 
                                                help="""Which media to generate the message for.""")
+       parser.add_option("", "--force", dest="force", action="store_true", 
+                                               help="""Force the recreation of the usb images.""")
+       parser = parsermodule.getParser(['defaults'], parser)
 
-       config = cfg(parser)
-       config.parse_args()
+       config = parsermodule.parse_args(parser)
 
        ret = {'url_list' : ''} 
        for i in config.args:
-               conf = getconf(i)
+               conf = getconf(i, config.force, config.media)
                ret['url_list'] += conf['url_list']
                ret['hostname'] = i
 
@@ -68,7 +79,7 @@ Thank you,
 
 """ % ret
 
-       elif config.media == "cd":
+       elif config.media == "iso":
                print """
 Hello,