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