passes SLICEFAMILY to yum.conf.php
[myplc.git] / db-config
1 #!/usr/bin/env /usr/bin/plcsh
2 #
3 # Bootstraps the PLC database with a default administrator account and
4 # a default site, defines default slice attribute types, and
5 # creates/updates default system slices.
6 #
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
9 #
10 # $Id$
11 # $HeadURL$
12
13 from plc_config import PLCConfiguration
14 import sys
15
16 def main():
17     cfg = PLCConfiguration()
18     cfg.load()
19     variables = cfg.variables()
20
21     # Load variables into dictionaries
22     for category_id, (category, variablelist) in variables.iteritems():
23         globals()[category_id] = dict(zip(variablelist.keys(),
24                                        [variable['value'] for variable in variablelist.values()]))
25
26     # Create/update the default administrator account (should be
27     # person_id 2).
28     admin = { 'person_id': 2,
29               'first_name': "Default",
30               'last_name': "Administrator",
31               'email': plc['root_user'],
32               'password': plc['root_password'] }
33     persons = GetPersons([admin['person_id']])
34     if not persons:
35         person_id = AddPerson(admin)
36         if person_id != admin['person_id']:
37             # Huh? Someone deleted the account manually from the database.
38             DeletePerson(person_id)
39             raise Exception, "Someone deleted the \"%s %s\" account from the database!" % \
40                   (admin['first_name'], admin['last_name'])
41         UpdatePerson(person_id, { 'enabled': True })
42     else:
43         person_id = persons[0]['person_id']
44         UpdatePerson(person_id, admin)
45
46     # Create/update the default site (should be site_id 1)
47     if plc_www['port'] == '80':
48         url = "http://" + plc_www['host'] + "/"
49     elif plc_www['port'] == '443':
50         url = "https://" + plc_www['host'] + "/"
51     else:
52         url = "http://" + plc_www['host'] + ":" + plc_www['port'] + "/"
53     site = { 'site_id': 1,
54              'name': plc['name'] + " Central",
55              'abbreviated_name': plc['name'],
56              'login_base': plc['slice_prefix'],
57              'is_public': False,
58              'url': url,
59              'max_slices': 100 }
60
61     sites = GetSites([site['site_id']])
62     if not sites:
63         site_id = AddSite(site['name'], site['abbreviated_name'], site['login_base'], site)
64         if site_id != site['site_id']:
65             DeleteSite(site_id)
66             raise Exception, "Someone deleted the \"%s\" site from the database!" % \
67                   site['name']
68         sites = [site]
69
70     # Must call UpdateSite() even after AddSite() to update max_slices
71     site_id = sites[0]['site_id']
72     UpdateSite(site_id, site)
73
74     # The default administrator account must be associated with a site
75     # in order to login.
76     AddPersonToSite(admin['person_id'], site['site_id'])
77     SetPersonPrimarySite(admin['person_id'], site['site_id'])
78
79     # Grant admin and PI roles to the default administrator account
80     AddRoleToPerson(10, admin['person_id'])
81     AddRoleToPerson(20, admin['person_id'])
82
83     # Setup default PlanetLabConf entries
84     default_conf_files = [
85         # NTP configuration
86         {'enabled': True,
87          'source': 'PlanetLabConf/ntp.conf.php',
88          'dest': '/etc/ntp.conf',
89          'file_permissions': '644',
90          'file_owner': 'root',
91          'file_group': 'root',
92          'preinstall_cmd': '',
93          'postinstall_cmd': '/etc/rc.d/init.d/ntpd restart',
94          'error_cmd': '',
95          'ignore_cmd_errors': False,
96          'always_update': False},
97         {'enabled': True,
98          'source': 'PlanetLabConf/ntp/step-tickers.php',
99          'dest': '/etc/ntp/step-tickers',
100          'file_permissions': '644',
101          'file_owner': 'root',
102          'file_group': 'root',
103          'preinstall_cmd': '',
104          'postinstall_cmd': '/etc/rc.d/init.d/ntpd restart',
105          'error_cmd': '',
106          'ignore_cmd_errors': False,
107          'always_update': False},
108
109         # SSH server configuration
110         {'enabled': True,
111          'source': 'PlanetLabConf/sshd_config',
112          'dest': '/etc/ssh/sshd_config',
113          'file_permissions': '600',
114          'file_owner': 'root',
115          'file_group': 'root',
116          'preinstall_cmd': '',
117          'postinstall_cmd': '/etc/init.d/sshd restart',
118          'error_cmd': '',
119          'ignore_cmd_errors': False,
120          'always_update': False},
121
122         # Administrative SSH keys
123         {'enabled': True,
124          'source': 'PlanetLabConf/keys.php?root',
125          'dest': '/root/.ssh/authorized_keys',
126          'file_permissions': '644',
127          'file_owner': 'root',
128          'file_group': 'root',
129          'preinstall_cmd': '',
130          'postinstall_cmd': '/bin/chmod 700 /root/.ssh',
131          'error_cmd': '',
132          'ignore_cmd_errors': False,
133          'always_update': False},
134         {'enabled': True,
135          'source': 'PlanetLabConf/keys.php?site_admin',
136          'dest': '/home/site_admin/.ssh/authorized_keys',
137          'file_permissions': '644',
138          'file_owner': 'site_admin',
139          'file_group': 'site_admin',
140          'preinstall_cmd': 'grep -q site_admin /etc/passwd',
141          'postinstall_cmd': '/bin/chmod 700 /home/site_admin/.ssh',
142          'error_cmd': '',
143          'ignore_cmd_errors': False,
144          'always_update': False},
145         # Log rotation configuration
146         {'enabled': True,
147          'source': 'PlanetLabConf/logrotate.conf',
148          'dest': '/etc/logrotate.conf',
149          'file_permissions': '644',
150          'file_owner': 'root',
151          'file_group': 'root',
152          'preinstall_cmd': '',
153          'postinstall_cmd': '',
154          'error_cmd': '',
155          'ignore_cmd_errors': False,
156          'always_update': False},
157
158         # updatedb/locate nightly cron job
159         {'enabled': True,
160          'source': 'PlanetLabConf/slocate.cron',
161          'dest': '/etc/cron.daily/slocate.cron',
162          'file_permissions': '755',
163          'file_owner': 'root',
164          'file_group': 'root',
165          'preinstall_cmd': '',
166          'postinstall_cmd': '',
167          'error_cmd': '',
168          'ignore_cmd_errors': False,
169          'always_update': False},
170
171         # YUM configuration
172         {'enabled': True,
173          'source': 'PlanetLabConf/yum.conf.php?gpgcheck=1&slicefamily=@SLICEFAMILY@',
174          'dest': '/etc/yum.conf',
175          'file_permissions': '644',
176          'file_owner': 'root',
177          'file_group': 'root',
178          'preinstall_cmd': '',
179          'postinstall_cmd': '',
180          'error_cmd': '',
181          'ignore_cmd_errors': False,
182          'always_update': False},
183         {'enabled': True,
184          'source': 'PlanetLabConf/delete-rpm-list-production',
185          'dest': '/etc/planetlab/delete-rpm-list',
186          'file_permissions': '644',
187          'file_owner': 'root',
188          'file_group': 'root',
189          'preinstall_cmd': '',
190          'postinstall_cmd': '',
191          'error_cmd': '',
192          'ignore_cmd_errors': False,
193          'always_update': False},
194
195         # PLC configuration
196         {'enabled': True,
197          'source': 'PlanetLabConf/get_plc_config.php',
198          'dest': '/etc/planetlab/plc_config',
199          'file_permissions': '644',
200          'file_owner': 'root',
201          'file_group': 'root',
202          'preinstall_cmd': '',
203          'postinstall_cmd': '',
204          'error_cmd': '',
205          'ignore_cmd_errors': False,
206          'always_update': False},
207         {'enabled': True,
208          'source': 'PlanetLabConf/get_plc_config.php?python',
209          'dest': '/etc/planetlab/plc_config.py',
210          'file_permissions': '644',
211          'file_owner': 'root',
212          'file_group': 'root',
213          'preinstall_cmd': '',
214          'postinstall_cmd': '',
215          'error_cmd': '',
216          'ignore_cmd_errors': False,
217          'always_update': False},
218         {'enabled': True,
219          'source': 'PlanetLabConf/get_plc_config.php?perl',
220          'dest': '/etc/planetlab/plc_config.pl',
221          'file_permissions': '644',
222          'file_owner': 'root',
223          'file_group': 'root',
224          'preinstall_cmd': '',
225          'postinstall_cmd': '',
226          'error_cmd': '',
227          'ignore_cmd_errors': False,
228          'always_update': False},
229         {'enabled': True,
230          'source': 'PlanetLabConf/get_plc_config.php?php',
231          'dest': '/etc/planetlab/php/plc_config.php',
232          'file_permissions': '644',
233          'file_owner': 'root',
234          'file_group': 'root',
235          'preinstall_cmd': '',
236          'postinstall_cmd': '',
237          'error_cmd': '',
238          'ignore_cmd_errors': False,
239          'always_update': False},
240
241         # XXX Required for old Node Manager
242         # Proper configuration
243         {'enabled': True,
244          'source': 'PlanetLabConf/propd.conf',
245          'dest': '/etc/proper/propd.conf',
246          'file_permissions': '644',
247          'file_owner': 'root',
248          'file_group': 'root',
249          'preinstall_cmd': '',
250          'postinstall_cmd': '/etc/init.d/proper restart',
251          'error_cmd': '',
252          'ignore_cmd_errors': True,
253          'always_update': False},
254
255         # XXX Required for old Node Manager
256         # Bandwidth cap
257         {'enabled': True,
258          'source': 'PlanetLabConf/bwlimit.php',
259          'dest': '/etc/planetlab/bwcap',
260          'file_permissions': '644',
261          'file_owner': 'root',
262          'file_group': 'root',
263          'preinstall_cmd': '',
264          'postinstall_cmd': '',
265          'error_cmd': '',
266          'ignore_cmd_errors': True,
267          'always_update': False},
268
269         # Proxy ARP setup
270         {'enabled': True,
271          'source': 'PlanetLabConf/proxies.php',
272          'dest': '/etc/planetlab/proxies',
273          'file_permissions': '644',
274          'file_owner': 'root',
275          'file_group': 'root',
276          'preinstall_cmd': '',
277          'postinstall_cmd': '',
278          'error_cmd': '',
279          'ignore_cmd_errors': False,
280          'always_update': False},
281
282         # Firewall configuration
283         {'enabled': True,
284          'source': 'PlanetLabConf/iptables',
285          'dest': '/etc/sysconfig/iptables',
286          'file_permissions': '600',
287          'file_owner': 'root',
288          'file_group': 'root',
289          'preinstall_cmd': '',
290          'postinstall_cmd': '',
291          'error_cmd': '',
292          'ignore_cmd_errors': False,
293          'always_update': False},
294         {'enabled': True,
295          'source': 'PlanetLabConf/blacklist.php',
296          'dest': '/etc/planetlab/blacklist',
297          'file_permissions': '600',
298          'file_owner': 'root',
299          'file_group': 'root',
300          'preinstall_cmd': '',
301          'postinstall_cmd': '/sbin/iptables-restore --noflush < /etc/planetlab/blacklist',
302          'error_cmd': '',
303          'ignore_cmd_errors': True,
304          'always_update': False},
305
306         # /etc/issue
307         {'enabled': True,
308          'source': 'PlanetLabConf/issue.php',
309          'dest': '/etc/issue',
310          'file_permissions': '644',
311          'file_owner': 'root',
312          'file_group': 'root',
313          'preinstall_cmd': '',
314          'postinstall_cmd': '',
315          'error_cmd': '',
316          'ignore_cmd_errors': False,
317          'always_update': False},
318
319         # Kernel parameters
320         {'enabled': True,
321          'source': 'PlanetLabConf/sysctl.php',
322          'dest': '/etc/sysctl.conf',
323          'file_permissions': '644',
324          'file_owner': 'root',
325          'file_group': 'root',
326          'preinstall_cmd': '',
327          'postinstall_cmd': '/sbin/sysctl -e -p /etc/sysctl.conf',
328          'error_cmd': '',
329          'ignore_cmd_errors': False,
330          'always_update': False},
331
332         # Sendmail configuration
333         {'enabled': True,
334          'source': 'PlanetLabConf/sendmail.mc',
335          'dest': '/etc/mail/sendmail.mc',
336          'file_permissions': '644',
337          'file_owner': 'root',
338          'file_group': 'root',
339          'preinstall_cmd': '',
340          'postinstall_cmd': '',
341          'error_cmd': '',
342          'ignore_cmd_errors': False,
343          'always_update': False},
344         {'enabled': True,
345          'source': 'PlanetLabConf/sendmail.cf',
346          'dest': '/etc/mail/sendmail.cf',
347          'file_permissions': '644',
348          'file_owner': 'root',
349          'file_group': 'root',
350          'preinstall_cmd': '',
351          'postinstall_cmd': 'service sendmail restart',
352          'error_cmd': '',
353          'ignore_cmd_errors': False,
354          'always_update': False},
355
356         # GPG signing keys
357         {'enabled': True,
358          'source': 'PlanetLabConf/RPM-GPG-KEY-fedora',
359          'dest': '/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora',
360          'file_permissions': '644',
361          'file_owner': 'root',
362          'file_group': 'root',
363          'preinstall_cmd': '',
364          'postinstall_cmd': 'rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora',
365          'error_cmd': '',
366          'ignore_cmd_errors': False,
367          'always_update': False},
368         {'enabled': True,
369          'source': 'PlanetLabConf/get_gpg_key.php',
370          'dest': '/etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab',
371          'file_permissions': '644',
372          'file_owner': 'root',
373          'file_group': 'root',
374          'preinstall_cmd': '',
375          'postinstall_cmd': 'rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab',
376          'error_cmd': '',
377          'ignore_cmd_errors': False,
378          'always_update': False},
379
380         # Ping of death configuration
381         # the 'restart' postcommand doesn't work, b/c the pod script doesn't support it.
382         {'enabled': True,
383          'source': 'PlanetLabConf/ipod.conf.php',
384          'dest': '/etc/ipod.conf',
385          'file_permissions': '644',
386          'file_owner': 'root',
387          'file_group': 'root',
388          'preinstall_cmd': '',
389          'postinstall_cmd': '/etc/init.d/pod start',
390          'error_cmd': '',
391          'ignore_cmd_errors': False,
392          'always_update': False},
393
394         # sudo configuration
395         {'enabled': True,
396          'source': 'PlanetLabConf/sudoers.php',
397          'dest': '/etc/sudoers',
398          'file_permissions': '440',
399          'file_owner': 'root',
400          'file_group': 'root',
401          'preinstall_cmd': '',
402          'postinstall_cmd': '/usr/sbin/visudo -c',
403          'error_cmd': '',
404          'ignore_cmd_errors': False,
405          'always_update': False}
406         ]
407
408     # Get list of existing (enabled, global) files
409     conf_files = GetConfFiles()
410     conf_files = filter(lambda conf_file: conf_file['enabled'] and \
411                                           not conf_file['node_ids'] and \
412                                           not conf_file['nodegroup_ids'],
413                         conf_files)
414     dests = [conf_file['dest'] for conf_file in conf_files]
415     conf_files = dict(zip(dests, conf_files))
416
417     # Create/update default PlanetLabConf entries
418     for default_conf_file in default_conf_files:
419         if default_conf_file['dest'] not in dests:
420             AddConfFile(default_conf_file)
421         else:
422             conf_file = conf_files[default_conf_file['dest']]
423             UpdateConfFile(conf_file['conf_file_id'], default_conf_file)
424
425     # Setup default slice attribute types
426     default_attribute_types = [
427         # Slice type (only vserver is supported)
428         {'name': "type",
429          'description': "Type of slice (e.g. vserver)",
430          'min_role_id': 20},
431
432         # System slice
433         {'name': "system",
434          'description': "Is a default system slice (1) or not (0 or unset)",
435          'min_role_id': 10},
436
437         # Slice enabled (1) or suspended (0)
438         {'name': "enabled",
439          'description': "Slice enabled (1 or unset) or suspended (0)",
440          'min_role_id': 10},
441
442         # Slice reference image
443         {'name': "vref",
444          'description': "Reference image",
445          'min_role_id': 30},
446
447         # Slice initialization script
448         {'name': "initscript",
449          'description': "Slice initialization script",
450          'min_role_id': 10},
451
452         # CPU share
453         {'name': "cpu_pct",
454          'description': "Reserved CPU percent",
455          'min_role_id': 10},
456         {'name': "cpu_share",
457          'description': "Number of CPU shares",
458          'min_role_id': 10},
459
460         # Bandwidth limits
461         {'name': "net_min_rate",
462          'description': "Minimum bandwidth (kbps)",
463          'min_role_id': 10},
464         {'name': "net_max_rate",
465          'description': "Maximum bandwidth (kbps)",
466          'min_role_id': 10},
467         {'name': "net_i2_min_rate",
468          'description': "Minimum bandwidth over I2 routes (kbps)",
469          'min_role_id': 10},
470         {'name': "net_i2_max_rate",
471          'description': "Maximum bandwidth over I2 routes (kbps)",
472          'min_role_id': 10},
473         {'name': "net_max_kbyte",
474          'description': "Maximum daily network Tx KByte limit.",
475          'min_role_id': 10},
476         {'name': "net_thresh_kbyte",
477          'description': "KByte limit before warning and throttling.",
478          'min_role_id': 10},
479         {'name': "net_i2_max_kbyte",
480          'description': "Maximum daily network Tx KByte limit to I2 hosts.",
481          'min_role_id': 10},
482         {'name': "net_i2_thresh_kbyte",
483          'description': "KByte limit to I2 hosts before warning and throttling.",
484          'min_role_id': 10},
485         {'name': "net_share",
486          'description': "Number of bandwidth shares",
487          'min_role_id': 10},
488         {'name': "net_i2_share",
489          'description': "Number of bandwidth shares over I2 routes",
490          'min_role_id': 10},
491  
492         # Disk quota
493         {'name': "disk_max",
494          'description': "Disk quota (1k disk blocks)",
495          'min_role_id': 10},
496
497         # Proper operations
498         {'name': "proper_op",
499          'description': "Proper operation (e.g. bind_socket)",
500          'min_role_id': 10},
501
502         # VServer capabilities 
503         {'name': "capabilities",
504          'description': "VServer bcapabilities (separate by commas)",
505          'min_role_id': 10},
506
507                 # Vsys
508         {'name': "vsys",
509          'description': "Bind vsys script fd's to a slice's vsys directory.",
510          'min_role_id': 10},
511
512         # CoDemux
513         {'name': "codemux",
514          'description': "Demux HTTP between slices using localhost ports. Value in the form 'host, localhost port'.",
515          'min_role_id': 10},
516
517         ]
518
519     # Get list of existing attribute types
520     attribute_types = GetSliceAttributeTypes()
521     attribute_types = [attribute_type['name'] for attribute_type in attribute_types]
522
523     # Create/update default slice attribute types
524     for default_attribute_type in default_attribute_types:
525         if default_attribute_type['name'] not in attribute_types:
526             AddSliceAttributeType(default_attribute_type)
527         else:
528             UpdateSliceAttributeType(default_attribute_type['name'], default_attribute_type)
529
530     # Default Initscripts
531     default_initscripts = []
532
533     # Find initscripts and add them to the db
534     for (root, dirs, files) in os.walk("/etc/plc_sliceinitscripts"):
535         for f in files:
536             # Read the file
537             file = open(root + "/" + f, "ro")
538             default_initscripts.append({"name": plc['slice_prefix'] + "_" + f,
539                                         "enabled": True,
540                                         "script": file.read().replace("@SITE@", url).replace("@PREFIX@", plc['slice_prefix'])})
541             file.close()
542
543     # Get list of existing initscripts
544     oldinitscripts = GetInitScripts()
545     oldinitscripts = [script['name'] for script in oldinitscripts]
546
547     for initscript in default_initscripts:
548         if initscript['name'] not in oldinitscripts:  AddInitScript(initscript)
549
550     # Setup default slice attribute types
551     default_setting_types = [
552
553         {'category' : "general",
554          'name' : "ifname",
555          'description': "Set interface name, instead of eth0 or the like",
556          'min_role_id' : 40},
557         {'category' : "Multihome",
558          'name' : "alias",
559          'description': "Specifies that the network is used for multihoming",
560          'min_role_id' : 40},
561
562         {'category' : "hidden",
563          'name' : "backdoor",
564          'description': "For testing new settings",
565          'min_role_id' : 10},
566         ] + [
567         { "category" : "WiFi",
568           "name" : x,
569           "description" : "802.11 %s -- see %s"%(y,z),
570           "min_role_id" : 40 } for (x,y,z) in [
571             ("mode","Mode","iwconfig"),
572             ("essid","ESSID","iwconfig"),
573             ("nw","Network Id","iwconfig"),
574             ("freq","Frequency","iwconfig"),
575             ("channel","Channel","iwconfig"),
576             ("sens","sensitivity threshold","iwconfig"),
577             ("rate","Rate","iwconfig"),
578             ("key","key","iwconfig key"),
579             ("key1","key1","iwconfig key [1]"),
580             ("key2","key2","iwconfig key [2]"),
581             ("key3","key3","iwconfig key [3]"),
582             ("key4","key4","iwconfig key [4]"),
583             ("securitymode","Security mode","iwconfig enc"),
584             ("iwconfig","Additional parameters to iwconfig","ifup-wireless"),
585             ("iwpriv","Additional parameters to iwpriv","ifup-wireless"),
586             ]
587         ]
588
589
590     # Get list of existing attribute types
591     setting_types = GetNodeNetworkSettingTypes()
592     setting_types = [setting_type['name'] for setting_type in setting_types]
593
594     # Create/update default slice setting types
595     for default_setting_type in default_setting_types:
596         if default_setting_type['name'] not in setting_types:
597             AddNodeNetworkSettingType(default_setting_type)
598         else:
599             UpdateNodeNetworkSettingType(default_setting_type['name'], default_setting_type)
600
601     # Create/update system slices
602     default_slices = [
603          # PlanetFlow
604         {'name': plc['slice_prefix'] + "_netflow",
605          'description': "PlanetFlow Traffic Auditing Service.  Logs, captured in the root context using fprobe-ulogd, are stored in a directory in the root context which is bind mounted to the planetflow slice.  The Planetflow Central service then periodically rsyncs these logs from the planetflow slice for aggregation.",
606          'url': url,
607          'instantiation': "plc-instantiated",
608          # Renew forever (minus one day, work around date conversion weirdness)
609          'expires': 0x7fffffff - (60 * 60 * 24),
610          'attributes': [('system', "1"),
611                         ('vref', "planetflow"),
612                                                 ('vsys', "pfmount")]},
613           # Sirius
614         {'name': plc['slice_prefix'] + "_sirius",
615          'description': 'The Sirius Calendar Service.\n\nSirius provides system-wide reservations of 25% CPU and 2Mb/s outgoing\nbandwidth.  Sign up for hour-long slots using the Web GUI at the\nPlanetLab website.\n\nThis slice should not generate traffic external to PlanetLab.\n',
616          'url': url + "db/sirius/index.php",
617          'instantiation': "plc-instantiated",
618          # Renew forever (minus one day, work around date conversion weirdness)
619          'expires': 0x7fffffff - (60 * 60 * 24),
620          'attributes': [('system', "1"),
621                         ('net_min_rate', "2000"),
622                         ('cpu_pct', "25"),
623                         ('initscript', plc['slice_prefix'] + "_sirius")]}
624         ]
625     
626     for default_slice in default_slices:
627         slices = GetSlices([default_slice['name']])
628         if slices:
629             slice = slices[0]
630             UpdateSlice(slice['slice_id'], default_slice)
631         else:
632             AddSlice(default_slice)
633             slice = GetSlices([default_slice['name']])[0]
634
635         # Create/update all attributes
636         slice_attributes = []
637         if slice['slice_attribute_ids']:
638             # Delete unknown attributes
639             for slice_attribute in GetSliceAttributes(slice['slice_attribute_ids']):
640                 if (slice_attribute['name'], slice_attribute['value']) \
641                    not in default_slice['attributes']:
642                     DeleteSliceAttribute(slice_attribute['slice_attribute_id'])
643                 else:
644                     slice_attributes.append((slice_attribute['name'], slice_attribute['value']))
645
646         for (name, value) in default_slice['attributes']:
647             if (name, value) not in slice_attributes:
648                 AddSliceAttribute(slice['name'], name, value)
649
650     installfailed = """
651 Once the node meets these requirements, please reinitiate the install
652 by visiting:
653
654 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
655
656 Update the BootState to 'Reinstall', then reboot the node.
657
658 If you have already performed this step and are still receiving this
659 message, please reply so that we may investigate the problem.
660 """
661
662     # Load default message templates
663     message_templates = [
664         {'message_id': 'Verify account',
665          'subject': "Verify account registration",
666          'template': """
667 Please verify that you registered for a %(PLC_NAME)s account with the
668 username %(email)s by visiting:
669
670 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/register.php?id=%(person_id)d&key=%(verification_key)s
671
672 If you did not register for a %(PLC_NAME)s account, please ignore this
673 message, or contact %(PLC_NAME)s Support <%(PLC_MAIL_SUPPORT_ADDRESS)s>.
674 """
675          },
676
677         {'message_id': 'New PI account',
678          'subject': "New PI account registration from %(first_name)s %(last_name)s <%(email)s> at %(site_name)s",
679          'template': """
680 %(first_name)s %(last_name)s <%(email)s> has signed up for a new
681 %(PLC_NAME)s account at %(site_name)s and has requested a PI role. PIs
682 are responsible for enabling user accounts, creating slices, and
683 ensuring that all users abide by the %(PLC_NAME)s Acceptable Use
684 Policy.
685
686 Only %(PLC_NAME)s administrators may enable new PI accounts. If you
687 are a PI at %(site_name)s, please respond and indicate whether this
688 registration is acceptable.
689
690 To view the request, visit:
691
692 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/index.php?id=%(person_id)d
693 """
694          },
695
696         {'message_id': 'New account',
697          'subject': "New account registration from %(first_name)s %(last_name)s <%(email)s> at %(site_name)s",
698          'template': """
699 %(first_name)s %(last_name)s <%(email)s> has signed up for a new
700 %(PLC_NAME)s account at %(site_name)s and has requested the following
701 roles: %(roles)s.
702
703 To deny the request or enable the account, visit:
704
705 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/index.php?id=%(person_id)d
706 """
707          },
708
709         {'message_id': 'Password reset requested',
710          'subject': "Password reset requested",
711          'template': """
712 Someone has requested that the password of your %(PLC_NAME)s account
713 %(email)s be reset. If this person was you, you may continue with the
714 reset by visiting:
715
716 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/reset_password.php?id=%(person_id)d&key=%(verification_key)s
717
718 If you did not request that your password be reset, please contact
719 %(PLC_NAME)s Support <%(PLC_MAIL_SUPPORT_ADDRESS)s>. Do not quote or
720 otherwise include any of this text in any correspondence.
721 """
722          },
723
724         {'message_id': 'Password reset',
725          'subject': "Password reset",
726          'template': """
727 The password of your %(PLC_NAME)s account %(email)s has been
728 temporarily reset to:
729
730 %(password)s
731
732 Please change it at as soon as possible by visiting:
733
734 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/index.php?id=%(person_id)d
735
736 If you did not request that your password be reset, please contact
737 %(PLC_NAME)s Support <%(PLC_MAIL_SUPPORT_ADDRESS)s>. Do not quote or
738 otherwise include any of this text in any correspondence.
739 """
740          },
741
742         # Boot Manager messages
743         {'message_id': "installfinished",
744          'subject': "%(hostname)s completed installation",
745          'template': """
746 %(hostname)s just completed installation.
747
748 The node should be usable in a couple of minutes if installation was
749 successful.
750 """
751          },
752
753         {'message_id': "insufficientdisk",
754          'subject': "%(hostname)s does not have sufficient disk space",
755          'template': """
756 %(hostname)s failed to boot because it does not have sufficent disk
757 space, or because its disk controller was not recognized.
758
759 Please replace the current disk or disk controller or install
760 additional disks to meet the current hardware requirements.
761 """ + installfailed
762          },
763
764         {'message_id': "insufficientmemory",
765          'subject': "%(hostname)s does not have sufficient memory",
766          'template': """
767 %(hostname)s failed to boot because it does not have sufficent
768 memory.
769
770 Please install additional memory to meet the current hardware
771 requirements.
772 """ + installfailed
773          },
774
775         {'message_id': "authfail",
776          'subject': "%(hostname)s failed to authenticate",
777          'template':
778 """
779 %(hostname)s failed to authenticate for the following reason:
780
781 %(fault)s
782
783 The most common reason for authentication failure is that the
784 authentication key stored in the node configuration file, does not
785 match the key on record. 
786
787 There are two possible steps to resolve the problem.
788
789 1. If you have used an All-in-one BootCD that includes the plnode.txt file,
790     then please check your machine for any old boot media, either in the
791     floppy drive, or on a USB stick.  It is likely that an old configuration
792     is being used instead of the new configuration stored on the BootCD.
793 Or, 
794 2. If you are using Generic BootCD image, then regenerate the node 
795     configuration file by visiting:
796
797     https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
798
799     Under 'Download', follow the 'Download plnode.txt file for %(hostname)s'
800     option, and save the downloaded file as plnode.txt on either a floppy 
801     disk or a USB flash drive.  Be sure the 'Boot State' is set to 'Boot', 
802     and, then reboot the node.
803
804 If you have already performed this step and are still receiving this
805 message, please reply so that we can help investigate the problem.
806 """
807          },
808
809         {'message_id': "notinstalled",
810          'subject': "%(hostname)s is not installed",
811          'template':
812 """
813 %(hostname)s failed to boot because it has either never been
814 installed, or the installation is corrupt.
815
816 Please check if the hard drive has failed, and replace it if so. After
817 doing so, visit:
818
819 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
820
821 Change the 'Boot State' to 'Reinstall', and then reboot the node.
822
823 If you have already performed this step and are still receiving this
824 message, please reply so that we may investigate the problem.
825 """
826          },
827
828         {'message_id': "hostnamenotresolve",
829          'subject': "%(hostname)s does not resolve",
830          'template':
831 """
832 %(hostname)s failed to boot because its hostname does not resolve, or
833 does resolve but does not match its configured IP address.
834
835 Please check the network settings for the node, especially its
836 hostname, IP address, and DNS servers, by visiting:
837
838 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
839
840 Correct any errors, and change the 'Boot State' to 'Reinstall', and then
841 reboot the node.
842
843 If you have already performed this step and are still receiving this
844 message, please reply so that we may investigate the problem.
845 """
846          },
847
848         # XXX N.B. I don't think these are necessary, since there's no
849         # way that the Boot Manager would even be able to contact the
850         # API to send these messages.
851
852         {'message_id': "noconfig",
853          'subject': "%(hostname)s does not have a configuration file",
854          'template': """
855 %(hostname)s failed to boot because it could not find a PlanetLab
856 configuration file. To create this file, visit:
857
858 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
859
860 Click the Configuration File link, and save the downloaded file as
861 plnode.txt on either a floppy disk or a USB flash drive.  Change the 
862 'Boot State' to 'Reinstall', and then reboot the node.
863
864 If you have already performed this step and are still receiving this
865 message, please reply so that we may investigate the problem.
866 """
867          },
868
869         {'message_id': "nodetectednetwork",
870          'subject': "%(hostname)s has unsupported network hardware",
871          'template':
872 """
873
874 %(hostname)s failed to boot because it has network hardware that is
875 unsupported by the current production kernel. If it has booted
876 successfully in the past, please try re-installing it by visiting:
877
878 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
879
880 Change the 'Boot State' to 'Reinstall', and then reboot the node.
881
882 If you have already performed this step and are still receiving this
883 message, please reply so that we may investigate the problem.
884 """
885          },
886         ]
887
888     for template in message_templates:
889         messages = GetMessages([template['message_id']])
890         if not messages:
891             AddMessage(template)
892
893     
894     ### Setup Initial PCU information
895     pcu_types = [{'model': 'AP79xx',
896           'name': 'APC AP79xx',
897           'pcu_protocol_types': [{ 'port': 80,
898                                   'protocol': 'APC79xxHttp',
899                                   'supported': False},
900                                  { 'port': 23,
901                                   'protocol': 'APC79xx',
902                                   'supported': True},
903                                  { 'port': 22,
904                                   'protocol': 'APC79xx',
905                                   'supported': True}],
906           },
907          {'model': 'Masterswitch',
908           'name': 'APC Masterswitch',
909           'pcu_protocol_types': [{ 'port': 80,
910                                   'protocol': 'APCMasterHttp',
911                                   'supported': False},
912                                  { 'port': 23,
913                                   'protocol': 'APCMaster',
914                                   'supported': True},
915                                  { 'port': 22,
916                                   'protocol': 'APCMaster',
917                                   'supported': True}],
918           },
919          {'model': 'DS4-RPC',
920           'name': 'BayTech DS4-RPC',
921           'pcu_protocol_types': [{ 'port': 80,
922                                   'protocol': 'BayTechHttp',
923                                   'supported': False},
924                                  { 'port': 23,
925                                   'protocol': 'BayTech',
926                                   'supported': True},
927                                  { 'port': 22,
928                                   'protocol': 'BayTech',
929                                   'supported': True}],
930           },
931          {'model': 'IP-41x_IP-81x',
932           'name': 'Dataprobe IP-41x & IP-81x',
933           'pcu_protocol_types': [ { 'port': 23,
934                                   'protocol': 'IPALTelnet',
935                                   'supported': True},
936                                   { 'port': 80,
937                                   'protocol': 'IPALHttp',
938                                   'supported': False}],
939           },
940          {'model': 'DRAC3',
941           'name': 'Dell RAC Version 3',
942           'pcu_protocol_types': [],
943           },
944          {'model': 'DRAC4',
945           'name': 'Dell RAC Version 4',
946           'pcu_protocol_types': [{ 'port': 443,
947                                   'protocol': 'DRACRacAdm',
948                                   'supported': True},
949                                  { 'port': 80,
950                                   'protocol': 'DRACRacAdm',
951                                   'supported': False},
952                                  { 'port': 22,
953                                   'protocol': 'DRAC',
954                                   'supported': True}],
955           },
956          {'model': 'ePowerSwitch',
957           'name': 'ePowerSwitch 1/4/8x',
958           'pcu_protocol_types': [{ 'port': 80,
959                                   'protocol': 'ePowerSwitch',
960                                   'supported': True}],
961           },
962          {'model': 'ilo2',
963           'name': 'HP iLO2 (Integrated Lights-Out)',
964           'pcu_protocol_types': [{ 'port': 443,
965                                   'protocol': 'HPiLOHttps',
966                                   'supported': True},
967                                  { 'port': 22,
968                                   'protocol': 'HPiLO',
969                                   'supported': True}],
970           },
971          {'model': 'ilo1',
972           'name': 'HP iLO version 1',
973           'pcu_protocol_types': [],
974           },
975          {'model': 'PM211-MIP',
976           'name': 'Infratec PM221-MIP',
977           'pcu_protocol_types': [],
978           },
979          {'model': 'AMT2.5',
980           'name': 'Intel AMT v2.5 (Active Management Technology)',
981           'pcu_protocol_types': [],
982           },
983          {'model': 'AMT3.0',
984           'name': 'Intel AMT v3.0 (Active Management Technology)',
985           'pcu_protocol_types': [],
986           },
987          {'model': 'WTI_IPS-4',
988           'name': 'Western Telematic (WTI IPS-4)',
989           'pcu_protocol_types': [],
990           },
991          {'model': 'unknown',
992           'name': 'Unknown Vendor or Model',
993           'pcu_protocol_types': [{ 'port': 443,
994                                   'protocol': 'UnknownPCU',
995                                   'supported': False},
996                                  { 'port': 80,
997                                   'protocol': 'UnknownPCU',
998                                   'supported': False},
999                                  { 'port': 23,
1000                                   'protocol': 'UnknownPCU',
1001                                   'supported': False},
1002                                  { 'port': 22,
1003                                   'protocol': 'UnknownPCU',
1004                                   'supported': False}],
1005           }]
1006
1007     # Get all model names
1008     pcu_models = [type['model'] for type in GetPCUTypes()]
1009     for type in pcu_types:
1010         protocol_types = type['pcu_protocol_types']
1011         # Take this value out of the struct.
1012         del type['pcu_protocol_types']
1013         if type['model'] not in pcu_models:
1014             # Add the name/model info into DB
1015             id = AddPCUType(type)
1016             # for each protocol, also add this.
1017             for ptype in protocol_types:
1018                 AddPCUProtocolType(id, ptype)
1019
1020
1021 if __name__ == '__main__':
1022     main()
1023
1024 # Local variables:
1025 # tab-width: 4
1026 # mode: python
1027 # End: