31e035c9965d58f782a6ca53c1b0d488f3b8accd
[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, force=False, media=None):
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) or force:
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         if not media:
24                 args['url_list']  = "   http://monitor.planet-lab.org/bootcds/%s-partition.usb\n" % hostname
25                 args['url_list'] += "   http://monitor.planet-lab.org/bootcds/%s.iso" % hostname
26         else:
27                 if media == "usb":
28                         args['url_list']  = "   http://monitor.planet-lab.org/bootcds/%s-partition.usb\n" % hostname
29                 elif media == "iso":
30                         args['url_list']  = "   http://monitor.planet-lab.org/bootcds/%s.iso" % hostname
31                 else:
32                         args['url_list']  = "   http://monitor.planet-lab.org/bootcds/%s-partition.usb\n" % hostname
33                         args['url_list'] += "   http://monitor.planet-lab.org/bootcds/%s.iso" % hostname
34                         
35         #print "http://monitor.planet-lab.org/bootcds/%s.usb\n" % hostname
36
37         return args
38
39 if __name__ == '__main__':
40         from config import config as cfg
41         from optparse import OptionParser
42         parser = OptionParser()
43         parser.set_defaults(media='both', force=False)
44         parser.add_option("", "--media", dest="media", metavar="usb, iso, both", 
45                                                 help="""Which media to generate the message for.""")
46         parser.add_option("", "--force", dest="force", action="store_true", 
47                                                 help="""Force the recreation of the usb images.""")
48
49         config = cfg(parser)
50         config.parse_args()
51
52         ret = {'url_list' : ''} 
53         for i in config.args:
54                 conf = getconf(i, config.force, config.media)
55                 ret['url_list'] += conf['url_list']
56                 ret['hostname'] = i
57
58         if config.media == "both":
59                 print """
60 Hello,
61
62 Here are links to both the ISO CD image, and partitioned, USB image for the
63 DC7800 and others.  These are based on the new 4.2 BootImage, and are the most
64 up-to-date software for PlanetLab nodes.
65
66 %(url_list)s
67
68 All that is necessary is to raw-write these images to a usb stick or CD-ROM, and
69 then boot from them.  If using USB, please use a command like:
70
71    dd if=%(hostname)s.usb of=/dev/sdX
72
73 Where sdX is your USB device.  It is not necessary to run any other formatting
74 commands for these images, because they already include a MBR, partition
75 table, and fs.
76
77 Please let me know if you have any trouble.
78
79 Thank you,
80
81 """ % ret
82
83         elif config.media == "iso":
84                 print """
85 Hello,
86
87 Here are links to the ISO CD image(s) for your machines.  These are based on
88 the new 4.2 BootImage, and are the most up-to-date software for PlanetLab
89 nodes.
90
91 %(url_list)s
92
93 All that is necessary is to burn these images to a CD-ROM, and
94 then boot from them.  
95
96 Please let me know if you have any trouble.
97
98 Thank you,
99
100 """ % ret
101
102         elif config.media == "usb":
103                 print """
104 Hello,
105
106 Here are links to the partitioned, USB images for the DC7800 and others.  
107 These are based on the new 4.2 BootImage, and are the most
108 up-to-date software for PlanetLab nodes.
109
110 %(url_list)s
111
112 All that is necessary is to raw-write these images to a usb stick, and
113 then boot from them.  Please use a command like:
114
115    dd if=%(hostname)s.usb of=/dev/sdX
116
117 Where sdX is your direct, USB device.  Do not use a partition on the usb
118 image, or the boot will fail.  It is not necessary to run any other formatting
119 commands for these images, because they already include a MBR, partition
120 table, and fs.
121
122 Please let me know if you have any trouble.
123
124 Thank you,
125
126 """ % ret