commit of tools I use, but are not documented or guaranteed to work for anyone
[monitor.git] / getconf.py
1 #!/usr/bin/python
2
3 import auth
4 import plc
5 import sys
6 import os
7
8 def getconf(hostname):
9         api = plc.PLC(auth.auth, auth.plc)
10         n = api.GetNodes(hostname)
11         filename = "bootcd-alpha/" + hostname + ".txt"
12         if not os.path.exists(filename):
13                 f = open("bootcd-alpha/" + hostname + ".txt", 'w')
14                 f.write( api.AdmGenerateNodeConfFile(n[0]['node_id']) )
15                 f.close()
16                 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))
17                 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))
18         else:
19                 # assume that the images have already been generated..
20                 pass
21
22         args = {}
23         args['url_list']  = "   http://pl-virtual-03.cs.princeton.edu/bootcds/%s-partition.usb\n" % hostname
24         args['url_list'] += "   http://pl-virtual-03.cs.princeton.edu/bootcds/%s.iso" % hostname
25         #print "http://pl-virtual-03.cs.princeton.edu/bootcds/%s.usb\n" % hostname
26
27         return args
28
29 if __name__ == '__main__':
30         from config import config as cfg
31         from optparse import OptionParser
32         parser = OptionParser()
33         parser.set_defaults(media='both')
34         parser.add_option("", "--media", dest="media", metavar="usb, iso, both", 
35                                                 help="""Which media to generate the message for.""")
36
37         config = cfg(parser)
38         config.parse_args()
39
40         ret = {'url_list' : ''} 
41         for i in config.args:
42                 conf = getconf(i)
43                 ret['url_list'] += conf['url_list']
44                 ret['hostname'] = i
45
46         if config.media == "both":
47                 print """
48 Hello,
49
50 Here are links to both the ISO CD image, and partitioned, USB image for the
51 DC7800 and others.  These are based on the new 4.2 BootImage, and are the most
52 up-to-date software for PlanetLab nodes.
53
54 %(url_list)s
55
56 All that is necessary is to raw-write these images to a usb stick or CD-ROM, and
57 then boot from them.  If using USB, please use a command like:
58
59    dd if=%(hostname)s.usb of=/dev/sdX
60
61 Where sdX is your USB device.  It is not necessary to run any other formatting
62 commands for these images, because they already include a MBR, partition
63 table, and fs.
64
65 Please let me know if you have any trouble.
66
67 Thank you,
68
69 """ % ret
70
71         elif config.media == "cd":
72                 print """
73 Hello,
74
75 Here are links to the ISO CD image(s) for your machines.  These are based on
76 the new 4.2 BootImage, and are the most up-to-date software for PlanetLab
77 nodes.
78
79 %(url_list)s
80
81 All that is necessary is to burn these images to a CD-ROM, and
82 then boot from them.  
83
84 Please let me know if you have any trouble.
85
86 Thank you,
87
88 """ % ret
89
90         elif config.media == "usb":
91                 print """
92 Hello,
93
94 Here are links to the partitioned, USB images for the DC7800 and others.  
95 These are based on the new 4.2 BootImage, and are the most
96 up-to-date software for PlanetLab nodes.
97
98 %(url_list)s
99
100 All that is necessary is to raw-write these images to a usb stick, and
101 then boot from them.  Please use a command like:
102
103    dd if=%(hostname)s.usb of=/dev/sdX
104
105 Where sdX is your direct, USB device.  Do not use a partition on the usb
106 image, or the boot will fail.  It is not necessary to run any other formatting
107 commands for these images, because they already include a MBR, partition
108 table, and fs.
109
110 Please let me know if you have any trouble.
111
112 Thank you,
113
114 """ % ret