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