Add a postcommand value for /etc/ipod.conf, to make the value take effect.
[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 #
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         {'enabled': True,
146          'source': 'PlanetLabConf/keys.php?role=admin',
147          'dest': '/home/pl_admin/.ssh/authorized_keys',
148          'file_permissions': '644',
149          'file_owner': 'pl_admin',
150          'file_group': 'pl_admin',
151          'preinstall_cmd': 'grep -q pl_admin /etc/passwd',
152          'postinstall_cmd': '/bin/chmod 700 /home/pl_admin/.ssh',
153          'error_cmd': '',
154          'ignore_cmd_errors': False,
155          'always_update': False},
156
157         # Log rotation configuration
158         {'enabled': True,
159          'source': 'PlanetLabConf/logrotate.conf',
160          'dest': '/etc/logrotate.conf',
161          'file_permissions': '644',
162          'file_owner': 'root',
163          'file_group': 'root',
164          'preinstall_cmd': '',
165          'postinstall_cmd': '',
166          'error_cmd': '',
167          'ignore_cmd_errors': False,
168          'always_update': False},
169
170         # updatedb/locate nightly cron job
171         {'enabled': True,
172          'source': 'PlanetLabConf/slocate.cron',
173          'dest': '/etc/cron.daily/slocate.cron',
174          'file_permissions': '755',
175          'file_owner': 'root',
176          'file_group': 'root',
177          'preinstall_cmd': '',
178          'postinstall_cmd': '',
179          'error_cmd': '',
180          'ignore_cmd_errors': False,
181          'always_update': False},
182
183         # YUM configuration
184         {'enabled': True,
185          'source': 'PlanetLabConf/yum.conf.php?gpgcheck=1',
186          'dest': '/etc/yum.conf',
187          'file_permissions': '644',
188          'file_owner': 'root',
189          'file_group': 'root',
190          'preinstall_cmd': '',
191          'postinstall_cmd': '',
192          'error_cmd': '',
193          'ignore_cmd_errors': False,
194          'always_update': False},
195         {'enabled': True,
196          'source': 'PlanetLabConf/delete-rpm-list-production',
197          'dest': '/etc/planetlab/delete-rpm-list',
198          'file_permissions': '644',
199          'file_owner': 'root',
200          'file_group': 'root',
201          'preinstall_cmd': '',
202          'postinstall_cmd': '',
203          'error_cmd': '',
204          'ignore_cmd_errors': False,
205          'always_update': False},
206
207         # PLC configuration
208         {'enabled': True,
209          'source': 'PlanetLabConf/get_plc_config.php',
210          'dest': '/etc/planetlab/plc_config',
211          'file_permissions': '644',
212          'file_owner': 'root',
213          'file_group': 'root',
214          'preinstall_cmd': '',
215          'postinstall_cmd': '',
216          'error_cmd': '',
217          'ignore_cmd_errors': False,
218          'always_update': False},
219         {'enabled': True,
220          'source': 'PlanetLabConf/get_plc_config.php?python',
221          'dest': '/etc/planetlab/plc_config.py',
222          'file_permissions': '644',
223          'file_owner': 'root',
224          'file_group': 'root',
225          'preinstall_cmd': '',
226          'postinstall_cmd': '',
227          'error_cmd': '',
228          'ignore_cmd_errors': False,
229          'always_update': False},
230         {'enabled': True,
231          'source': 'PlanetLabConf/get_plc_config.php?perl',
232          'dest': '/etc/planetlab/plc_config.pl',
233          'file_permissions': '644',
234          'file_owner': 'root',
235          'file_group': 'root',
236          'preinstall_cmd': '',
237          'postinstall_cmd': '',
238          'error_cmd': '',
239          'ignore_cmd_errors': False,
240          'always_update': False},
241         {'enabled': True,
242          'source': 'PlanetLabConf/get_plc_config.php?php',
243          'dest': '/etc/planetlab/php/plc_config.php',
244          'file_permissions': '644',
245          'file_owner': 'root',
246          'file_group': 'root',
247          'preinstall_cmd': '',
248          'postinstall_cmd': '',
249          'error_cmd': '',
250          'ignore_cmd_errors': False,
251          'always_update': False},
252
253         # XXX Required for old Node Manager
254         # Node Manager configuration
255         {'enabled': True,
256          'source': 'PlanetLabConf/pl_nm.conf',
257          'dest': '/etc/planetlab/pl_nm.conf',
258          'file_permissions': '644',
259          'file_owner': 'root',
260          'file_group': 'root',
261          'preinstall_cmd': '',
262          'postinstall_cmd': '/etc/init.d/pl_nm restart',
263          'error_cmd': '',
264          'ignore_cmd_errors': False,
265          'always_update': False},
266         {'enabled': True,
267          'source': 'PlanetLabConf/RootResources/plc_slice_pool.php',
268          'dest': '/home/pl_nm/RootResources/plc_slice_pool',
269          'file_permissions': '644',
270          'file_owner': 'pl_nm',
271          'file_group': 'pl_nm',
272          'preinstall_cmd': '',
273          'postinstall_cmd': '',
274          'error_cmd': '',
275          'ignore_cmd_errors': False,
276          'always_update': False},
277         {'enabled': True,
278          'source': 'PlanetLabConf/RootResources/pl_conf.py',
279          'dest': '/home/pl_nm/RootResources/pl_conf',
280          'file_permissions': '644',
281          'file_owner': 'pl_nm',
282          'file_group': 'pl_nm',
283          'preinstall_cmd': '',
284          'postinstall_cmd': '/etc/init.d/pl_nm restart',
285          'error_cmd': '',
286          'ignore_cmd_errors': False,
287          'always_update': False},
288         {'enabled': True,
289          'source': 'PlanetLabConf/RootResources/pl_netflow.py',
290          'dest': '/home/pl_nm/RootResources/pl_netflow',
291          'file_permissions': '644',
292          'file_owner': 'pl_nm',
293          'file_group': 'pl_nm',
294          'preinstall_cmd': '',
295          'postinstall_cmd': '',
296          'error_cmd': '',
297          'ignore_cmd_errors': False,
298          'always_update': False},
299
300         # XXX Required for old Node Manager
301         # Proper configuration
302         {'enabled': True,
303          'source': 'PlanetLabConf/propd.conf',
304          'dest': '/etc/proper/propd.conf',
305          'file_permissions': '644',
306          'file_owner': 'root',
307          'file_group': 'root',
308          'preinstall_cmd': '',
309          'postinstall_cmd': '/etc/init.d/proper restart',
310          'error_cmd': '',
311          'ignore_cmd_errors': True,
312          'always_update': False},
313
314         # XXX Required for old Node Manager
315         # Bandwidth cap
316         {'enabled': True,
317          'source': 'PlanetLabConf/bwlimit.php',
318          'dest': '/etc/planetlab/bwcap',
319          'file_permissions': '644',
320          'file_owner': 'root',
321          'file_group': 'root',
322          'preinstall_cmd': '',
323          'postinstall_cmd': '/etc/init.d/pl_nm restart',
324          'error_cmd': '',
325          'ignore_cmd_errors': True,
326          'always_update': False},
327
328         # Proxy ARP setup
329         {'enabled': True,
330          'source': 'PlanetLabConf/proxies.php',
331          'dest': '/etc/planetlab/proxies',
332          'file_permissions': '644',
333          'file_owner': 'root',
334          'file_group': 'root',
335          'preinstall_cmd': '',
336          'postinstall_cmd': '',
337          'error_cmd': '',
338          'ignore_cmd_errors': False,
339          'always_update': False},
340
341         # Firewall configuration
342         {'enabled': True,
343          'source': 'PlanetLabConf/iptables',
344          'dest': '/etc/sysconfig/iptables',
345          'file_permissions': '600',
346          'file_owner': 'root',
347          'file_group': 'root',
348          'preinstall_cmd': '',
349          'postinstall_cmd': '',
350          'error_cmd': '',
351          'ignore_cmd_errors': False,
352          'always_update': False},
353         {'enabled': True,
354          'source': 'PlanetLabConf/blacklist.php',
355          'dest': '/etc/planetlab/blacklist',
356          'file_permissions': '600',
357          'file_owner': 'root',
358          'file_group': 'root',
359          'preinstall_cmd': '',
360          'postinstall_cmd': '/sbin/iptables-restore --noflush < /etc/planetlab/blacklist',
361          'error_cmd': '',
362          'ignore_cmd_errors': True,
363          'always_update': False},
364
365         # /etc/issue
366         {'enabled': True,
367          'source': 'PlanetLabConf/issue.php',
368          'dest': '/etc/issue',
369          'file_permissions': '644',
370          'file_owner': 'root',
371          'file_group': 'root',
372          'preinstall_cmd': '',
373          'postinstall_cmd': '',
374          'error_cmd': '',
375          'ignore_cmd_errors': False,
376          'always_update': False},
377
378         # Kernel parameters
379         {'enabled': True,
380          'source': 'PlanetLabConf/sysctl.php',
381          'dest': '/etc/sysctl.conf',
382          'file_permissions': '644',
383          'file_owner': 'root',
384          'file_group': 'root',
385          'preinstall_cmd': '',
386          'postinstall_cmd': '/sbin/sysctl -e -p /etc/sysctl.conf',
387          'error_cmd': '',
388          'ignore_cmd_errors': False,
389          'always_update': False},
390
391         # Sendmail configuration
392         {'enabled': True,
393          'source': 'PlanetLabConf/sendmail.mc',
394          'dest': '/etc/mail/sendmail.mc',
395          'file_permissions': '644',
396          'file_owner': 'root',
397          'file_group': 'root',
398          'preinstall_cmd': '',
399          'postinstall_cmd': '',
400          'error_cmd': '',
401          'ignore_cmd_errors': False,
402          'always_update': False},
403         {'enabled': True,
404          'source': 'PlanetLabConf/sendmail.cf',
405          'dest': '/etc/mail/sendmail.cf',
406          'file_permissions': '644',
407          'file_owner': 'root',
408          'file_group': 'root',
409          'preinstall_cmd': '',
410          'postinstall_cmd': 'service sendmail restart',
411          'error_cmd': '',
412          'ignore_cmd_errors': False,
413          'always_update': False},
414
415         # GPG signing keys
416         {'enabled': True,
417          'source': 'PlanetLabConf/RPM-GPG-KEY-fedora',
418          'dest': '/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora',
419          'file_permissions': '644',
420          'file_owner': 'root',
421          'file_group': 'root',
422          'preinstall_cmd': '',
423          'postinstall_cmd': 'rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora',
424          'error_cmd': '',
425          'ignore_cmd_errors': False,
426          'always_update': False},
427         {'enabled': True,
428          'source': 'PlanetLabConf/get_gpg_key.php',
429          'dest': '/etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab',
430          'file_permissions': '644',
431          'file_owner': 'root',
432          'file_group': 'root',
433          'preinstall_cmd': '',
434          'postinstall_cmd': 'rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab',
435          'error_cmd': '',
436          'ignore_cmd_errors': False,
437          'always_update': False},
438
439         # Ping of death configuration
440         # the 'restart' postcommand doesn't work, b/c the pod script doesn't support it.
441         {'enabled': True,
442          'source': 'PlanetLabConf/ipod.conf.php',
443          'dest': '/etc/ipod.conf',
444          'file_permissions': '644',
445          'file_owner': 'root',
446          'file_group': 'root',
447          'preinstall_cmd': '',
448          'postinstall_cmd': '/etc/init.d/pod start',
449          'error_cmd': '',
450          'ignore_cmd_errors': False,
451          'always_update': False},
452
453         # sudo configuration
454         {'enabled': True,
455          'source': 'PlanetLabConf/sudoers',
456          'dest': '/etc/sudoers',
457          'file_permissions': '440',
458          'file_owner': 'root',
459          'file_group': 'root',
460          'preinstall_cmd': '',
461          'postinstall_cmd': '/usr/sbin/visudo -c',
462          'error_cmd': '',
463          'ignore_cmd_errors': False,
464          'always_update': False}
465         ]
466
467     # Get list of existing (enabled, global) files
468     conf_files = GetConfFiles()
469     conf_files = filter(lambda conf_file: conf_file['enabled'] and \
470                                           not conf_file['node_ids'] and \
471                                           not conf_file['nodegroup_ids'],
472                         conf_files)
473     dests = [conf_file['dest'] for conf_file in conf_files]
474     conf_files = dict(zip(dests, conf_files))
475
476     # Create/update default PlanetLabConf entries
477     for default_conf_file in default_conf_files:
478         if default_conf_file['dest'] not in dests:
479             AddConfFile(default_conf_file)
480         else:
481             conf_file = conf_files[default_conf_file['dest']]
482             UpdateConfFile(conf_file['conf_file_id'], default_conf_file)
483
484     # Setup default slice attribute types
485     default_attribute_types = [
486         # Slice type (only vserver is supported)
487         {'name': "type",
488          'description': "Type of slice (e.g. vserver)",
489          'min_role_id': 20},
490
491         # System slice
492         {'name': "system",
493          'description': "Is a default system slice (1) or not (0 or unset)",
494          'min_role_id': 10},
495
496         # Slice enabled (1) or suspended (0)
497         {'name': "enabled",
498          'description': "Slice enabled (1 or unset) or suspended (0)",
499          'min_role_id': 10},
500
501         # Slice reference image
502         {'name': "vref",
503          'description': "Reference image",
504          'min_role_id': 30},
505
506         # Slice initialization script
507         {'name': "initscript",
508          'description': "Slice initialization script",
509          'min_role_id': 10},
510
511         # CPU share
512         {'name': "cpu_min",
513          'description': "Minimum CPU share (ms/s)",
514          'min_role_id': 10},
515         {'name': "cpu_share",
516          'description': "Number of CPU shares",
517          'min_role_id': 10},
518
519         # Bandwidth limits
520         {'name': "net_min_rate",
521          'description': "Minimum bandwidth (kbps)",
522          'min_role_id': 10},
523         {'name': "net_max_rate",
524          'description': "Maximum bandwidth (kbps)",
525          'min_role_id': 10},
526         {'name': "net_i2_min_rate",
527          'description': "Minimum bandwidth over I2 routes (kbps)",
528          'min_role_id': 10},
529         {'name': "net_i2_max_rate",
530          'description': "Maximum bandwidth over I2 routes (kbps)",
531          'min_role_id': 10},
532         {'name': "net_max_kbyte",
533          'description': "Maximum daily network Tx KByte limit.",
534          'min_role_id': 10},
535         {'name': "net_thresh_kbyte",
536          'description': "KByte limit before warning and throttling.",
537          'min_role_id': 10},
538         {'name': "net_i2_max_kbyte",
539          'description': "Maximum daily network Tx KByte limit to I2 hosts.",
540          'min_role_id': 10},
541         {'name': "net_i2_thresh_kbyte",
542          'description': "KByte limit to I2 hosts before warning and throttling.",
543          'min_role_id': 10},
544         {'name': "net_share",
545          'description': "Number of bandwidth shares",
546          'min_role_id': 10},
547         {'name': "net_i2_share",
548          'description': "Number of bandwidth shares over I2 routes",
549          'min_role_id': 10},
550  
551         # Disk quota
552         {'name': "disk_max",
553          'description': "Disk quota (1k disk blocks)",
554          'min_role_id': 10},
555
556         # Proper operations
557         {'name': "proper_op",
558          'description': "Proper operation (e.g. bind_socket)",
559          'min_role_id': 10},
560
561         # XXX Required for old Node Manager
562         # Special attributes applicable to Slice Creation Service (pl_conf) slice
563         {'name': "plc_slice_type",
564          'description': "Type of slice rspec to be created",
565          'min_role_id': 20},
566         {'name': "plc_agent_version",
567          'description': "Version of PLC agent (slice creation service) software to be deployed",
568          'min_role_id': 10},
569         {'name': "plc_ticket_pubkey",
570          'description': "Public key used to verify PLC-signed tickets",
571          'min_role_id': 10}
572         ]
573
574     # Get list of existing attribute types
575     attribute_types = GetSliceAttributeTypes()
576     attribute_types = [attribute_type['name'] for attribute_type in attribute_types]
577
578     # Create/update default slice attribute types
579     for default_attribute_type in default_attribute_types:
580         if default_attribute_type['name'] not in attribute_types:
581             AddSliceAttributeType(default_attribute_type)
582         else:
583             UpdateSliceAttributeType(default_attribute_type['name'], default_attribute_type)
584
585     # Create/update system slices
586     legacy_slices = [
587         # XXX Required for old Node Manager
588         {'name': "pl_conf",
589          'description': "PlanetLab Slice Creation Service (SCS)",
590          'url': url,
591          'instantiation': "plc-instantiated",
592          # Renew forever
593          'expires': sys.maxint,
594          'attributes': [('plc_slice_type', "VServerSlice"),
595                         ('plc_agent_version', "1.0"),
596                         ('plc_ticket_pubkey', "")]},
597
598         # XXX Required for old Node Manager
599         {'name': "pl_conf_vserverslice",
600          'description': "Default attributes for vserver slices",
601          'url': url,
602          'instantiation': "plc-instantiated",
603          # Renew forever
604          'expires': sys.maxint,
605          'attributes': [('cpu_share', "32"),
606                         ('plc_slice_type', "VServerSlice"),
607                         ('disk_max', "5000000")]},
608         ]
609     default_slices = [
610          # PlanetFlow
611         {'name': plc['slice_prefix'] + "_netflow",
612          'description': "PlanetFlow Traffic Auditing Service",
613          'url': url,
614          'instantiation': "plc-instantiated",
615          # Renew forever
616          'expires': sys.maxint,
617          'attributes': [('system', "1"),
618                         ('vref', "planetflow"),
619                         ('proper_op', "open file=/etc/passwd, flags=r"),
620                         ('proper_op', "create_socket"),
621                         ('proper_op', "bind_socket")]},
622         ]
623          
624     ### xxx - to review once new node manager rolls out
625     # if PLC_SLICE_PREFIX is left to default - this is meant for the public PL only
626     if plc['slice_prefix'] == 'pl':
627         # create both legacy slices together with netflow through default_slices
628         default_slices += legacy_slices
629     else:
630         # we use another slice prefix : disable legacy slices if already created
631         for legacy_slice in legacy_slices:
632             try:
633                 DeleteSlice(legacy_slice['name'])
634             except:
635                 pass
636     
637     for default_slice in default_slices:
638         slices = GetSlices([default_slice['name']])
639         if slices:
640             slice = slices[0]
641             UpdateSlice(slice['slice_id'], default_slice)
642         else:
643             AddSlice(default_slice)
644             slice = GetSlices([default_slice['name']])[0]
645
646         # Create/update all attributes
647         slice_attributes = []
648         if slice['slice_attribute_ids']:
649             # Delete unknown attributes
650             for slice_attribute in GetSliceAttributes(slice['slice_attribute_ids']):
651                 if (slice_attribute['name'], slice_attribute['value']) \
652                    not in default_slice['attributes']:
653                     DeleteSliceAttribute(slice_attribute['slice_attribute_id'])
654                 else:
655                     slice_attributes.append((slice_attribute['name'], slice_attribute['value']))
656
657         for (name, value) in default_slice['attributes']:
658             if (name, value) not in slice_attributes:
659                 AddSliceAttribute(slice['name'], name, value)
660
661     installfailed = """
662 Once the node meets these requirements, please reinitiate the install
663 by visiting:
664
665 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
666
667 Update the BootState to 'Reinstall', then reboot the node.
668
669 If you have already performed this step and are still receiving this
670 message, please reply so that we may investigate the problem.
671 """
672
673     # Load default message templates
674     message_templates = [
675         {'message_id': 'Verify account',
676          'subject': "Verify account registration",
677          'template': """
678 Please verify that you registered for a %(PLC_NAME)s account with the
679 username %(email)s by visiting:
680
681 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/register.php?id=%(person_id)d&key=%(verification_key)s
682
683 If you did not register for a %(PLC_NAME)s account, please ignore this
684 message, or contact %(PLC_NAME)s Support <%(PLC_MAIL_SUPPORT_ADDRESS)s>.
685 """
686          },
687
688         {'message_id': 'New PI account',
689          'subject': "New PI account registration from %(first_name)s %(last_name)s <%(email)s> at %(site_name)s",
690          'template': """
691 %(first_name)s %(last_name)s <%(email)s> has signed up for a new
692 %(PLC_NAME)s account at %(site_name)s and has requested a PI role. PIs
693 are responsible for enabling user accounts, creating slices, and
694 ensuring that all users abide by the %(PLC_NAME)s Acceptable Use
695 Policy.
696
697 Only %(PLC_NAME)s administrators may enable new PI accounts. If you
698 are a PI at %(site_name)s, please respond and indicate whether this
699 registration is acceptable.
700
701 To view the request, visit:
702
703 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/index.php?id=%(person_id)d
704 """
705          },
706
707         {'message_id': 'New account',
708          'subject': "New account registration from %(first_name)s %(last_name)s <%(email)s> at %(site_name)s",
709          'template': """
710 %(first_name)s %(last_name)s <%(email)s> has signed up for a new
711 %(PLC_NAME)s account at %(site_name)s and has requested the following
712 roles: %(roles)s.
713
714 To deny the request or enable the account, visit:
715
716 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/index.php?id=%(person_id)d
717 """
718          },
719
720         {'message_id': 'Password reset requested',
721          'subject': "Password reset requested",
722          'template': """
723 Someone has requested that the password of your %(PLC_NAME)s account
724 %(email)s be reset. If this person was you, you may continue with the
725 reset by visiting:
726
727 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/reset_password.php?id=%(person_id)d&key=%(verification_key)s
728
729 If you did not request that your password be reset, please contact
730 %(PLC_NAME)s Support <%(PLC_MAIL_SUPPORT_ADDRESS)s>. Do not quote or
731 otherwise include any of this text in any correspondence.
732 """
733          },
734
735         {'message_id': 'Password reset',
736          'subject': "Password reset",
737          'template': """
738 The password of your %(PLC_NAME)s account %(email)s has been
739 temporarily reset to:
740
741 %(password)s
742
743 Please change it at as soon as possible by visiting:
744
745 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/index.php?id=%(person_id)d
746
747 If you did not request that your password be reset, please contact
748 %(PLC_NAME)s Support <%(PLC_MAIL_SUPPORT_ADDRESS)s>. Do not quote or
749 otherwise include any of this text in any correspondence.
750 """
751          },
752
753         # Boot Manager messages
754         {'message_id': "installfinished",
755          'subject': "%(hostname)s completed installation",
756          'template': """
757 %(hostname)s just completed installation.
758
759 The node should be usable in a couple of minutes if installation was
760 successful.
761 """
762          },
763
764         {'message_id': "insufficientdisk",
765          'subject': "%(hostname)s does not have sufficient disk space",
766          'template': """
767 %(hostname)s failed to boot because it does not have sufficent disk
768 space, or because its disk controller was not recognized.
769
770 Please replace the current disk or disk controller or install
771 additional disks to meet the current hardware requirements.
772 """ + installfailed
773          },
774
775         {'message_id': "insufficientmemory",
776          'subject': "%(hostname)s does not have sufficient memory",
777          'template': """
778 %(hostname)s failed to boot because it does not have sufficent
779 memory.
780
781 Please install additional memory to meet the current hardware
782 requirements.
783 """ + installfailed
784          },
785
786         {'message_id': "authfail",
787          'subject': "%(hostname)s failed to authenticate",
788          'template':
789 """
790 %(hostname)s failed to authenticate for the following reason:
791
792 %(fault)s
793
794 The most common reason for authentication failure is that the
795 authentication key stored in the node configuration file, does not
796 match the key on record. 
797
798 There are two possible steps to resolve the problem.
799
800 1. If you have used an All-in-one BootCD that includes the plnode.txt file,
801     then please check your machine for any old boot media, either in the
802     floppy drive, or on a USB stick.  It is likely that an old configuration
803     is being used instead of the new configuration stored on the BootCD.
804 Or, 
805 2. If you are using Generic BootCD image, then regenerate the node 
806     configuration file by visiting:
807
808     https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
809
810     Under 'Download', follow the 'Download plnode.txt file for %(hostname)s'
811         option, and save the downloaded file as plnode.txt on either a floppy 
812         disk or a USB flash drive.  Be sure the 'Boot State' is set to 'Boot', 
813         and, then reboot the node.
814
815 If you have already performed this step and are still receiving this
816 message, please reply so that we can help investigate the problem.
817 """
818          },
819
820         {'message_id': "notinstalled",
821          'subject': "%(hostname)s is not installed",
822          'template':
823 """
824 %(hostname)s failed to boot because it has either never been
825 installed, or the installation is corrupt.
826
827 Please check if the hard drive has failed, and replace it if so. After
828 doing so, visit:
829
830 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
831
832 Change the 'Boot State' to 'Reinstall', and then reboot the node.
833
834 If you have already performed this step and are still receiving this
835 message, please reply so that we may investigate the problem.
836 """
837          },
838
839         {'message_id': "hostnamenotresolve",
840          'subject': "%(hostname)s does not resolve",
841          'template':
842 """
843 %(hostname)s failed to boot because its hostname does not resolve, or
844 does resolve but does not match its configured IP address.
845
846 Please check the network settings for the node, especially its
847 hostname, IP address, and DNS servers, by visiting:
848
849 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
850
851 Correct any errors, and change the 'Boot State' to 'Reinstall', and then
852 reboot the node.
853
854 If you have already performed this step and are still receiving this
855 message, please reply so that we may investigate the problem.
856 """
857          },
858
859         # XXX N.B. I don't think these are necessary, since there's no
860         # way that the Boot Manager would even be able to contact the
861         # API to send these messages.
862
863         {'message_id': "noconfig",
864          'subject': "%(hostname)s does not have a configuration file",
865          'template': """
866 %(hostname)s failed to boot because it could not find a PlanetLab
867 configuration file. To create this file, visit:
868
869 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
870
871 Click the Configuration File link, and save the downloaded file as
872 plnode.txt on either a floppy disk or a USB flash drive.  Change the 
873 'Boot State' to 'Reinstall', and then reboot the node.
874
875 If you have already performed this step and are still receiving this
876 message, please reply so that we may investigate the problem.
877 """
878          },
879
880         {'message_id': "nodetectednetwork",
881          'subject': "%(hostname)s has unsupported network hardware",
882          'template':
883 """
884
885 %(hostname)s failed to boot because it has network hardware that is
886 unsupported by the current production kernel. If it has booted
887 successfully in the past, please try re-installing it by visiting:
888
889 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
890
891 Change the 'Boot State' to 'Reinstall', and then reboot the node.
892
893 If you have already performed this step and are still receiving this
894 message, please reply so that we may investigate the problem.
895 """
896          },
897         ]
898
899     for template in message_templates:
900         messages = GetMessages([template['message_id']])
901         if not messages:
902             AddMessage(template)        
903
904 if __name__ == '__main__':
905     main()
906
907 # Local variables:
908 # tab-width: 4
909 # mode: python
910 # End: