Added bootstrap for the currently existing PCU types and Protocol types.
[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: db-config 7454 2007-12-11 18:55:00Z faiyaza $
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',
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',
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_min",
454          'description': "Minimum CPU share (ms/s)",
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         # XXX Required for old Node Manager
503         # Special attributes applicable to Slice Creation Service (pl_conf) slice
504         {'name': "plc_slice_type",
505          'description': "Type of slice rspec to be created",
506          'min_role_id': 20},
507         {'name': "plc_agent_version",
508          'description': "Version of PLC agent (slice creation service) software to be deployed",
509          'min_role_id': 10},
510         {'name': "plc_ticket_pubkey",
511          'description': "Public key used to verify PLC-signed tickets",
512          'min_role_id': 10}
513         ]
514
515     # Get list of existing attribute types
516     attribute_types = GetSliceAttributeTypes()
517     attribute_types = [attribute_type['name'] for attribute_type in attribute_types]
518
519     # Create/update default slice attribute types
520     for default_attribute_type in default_attribute_types:
521         if default_attribute_type['name'] not in attribute_types:
522             AddSliceAttributeType(default_attribute_type)
523         else:
524             UpdateSliceAttributeType(default_attribute_type['name'], default_attribute_type)
525
526     # Create/update system slices
527     legacy_slices = [
528         # XXX Required for old Node Manager
529         {'name': "pl_conf",
530          'description': "PlanetLab Slice Creation Service (SCS)",
531          'url': url,
532          'instantiation': "plc-instantiated",
533          # Renew forever
534          'expires': sys.maxint,
535          'attributes': [('plc_slice_type', "VServerSlice"),
536                         ('plc_agent_version', "1.0"),
537                         ('plc_ticket_pubkey', "")]},
538
539         # XXX Required for old Node Manager
540         {'name': "pl_conf_vserverslice",
541          'description': "Default attributes for vserver slices",
542          'url': url,
543          'instantiation': "plc-instantiated",
544          # Renew forever
545          'expires': sys.maxint,
546          'attributes': [('cpu_share', "32"),
547                         ('plc_slice_type', "VServerSlice"),
548                         ('disk_max', "5000000")]},
549         ]
550     default_slices = [
551          # PlanetFlow
552         {'name': plc['slice_prefix'] + "_netflow",
553          'description': "PlanetFlow Traffic Auditing Service",
554          'url': url,
555          'instantiation': "plc-instantiated",
556          # Renew forever
557          'expires': sys.maxint,
558          'attributes': [('system', "1"),
559                         ('vref', "planetflow"),
560                         ('proper_op', "open file=/etc/passwd, flags=r"),
561                         ('proper_op', "create_socket"),
562                         ('proper_op', "bind_socket")]},
563         ]
564          
565     ### xxx - to review once new node manager rolls out
566     # if PLC_SLICE_PREFIX is left to default - this is meant for the public PL only
567     if plc['slice_prefix'] == 'pl':
568         # create both legacy slices together with netflow through default_slices
569         default_slices += legacy_slices
570     else:
571         # we use another slice prefix : disable legacy slices if already created
572         for legacy_slice in legacy_slices:
573             try:
574                 DeleteSlice(legacy_slice['name'])
575             except:
576                 pass
577     
578     for default_slice in default_slices:
579         slices = GetSlices([default_slice['name']])
580         if slices:
581             slice = slices[0]
582             UpdateSlice(slice['slice_id'], default_slice)
583         else:
584             AddSlice(default_slice)
585             slice = GetSlices([default_slice['name']])[0]
586
587         # Create/update all attributes
588         slice_attributes = []
589         if slice['slice_attribute_ids']:
590             # Delete unknown attributes
591             for slice_attribute in GetSliceAttributes(slice['slice_attribute_ids']):
592                 if (slice_attribute['name'], slice_attribute['value']) \
593                    not in default_slice['attributes']:
594                     DeleteSliceAttribute(slice_attribute['slice_attribute_id'])
595                 else:
596                     slice_attributes.append((slice_attribute['name'], slice_attribute['value']))
597
598         for (name, value) in default_slice['attributes']:
599             if (name, value) not in slice_attributes:
600                 AddSliceAttribute(slice['name'], name, value)
601
602     installfailed = """
603 Once the node meets these requirements, please reinitiate the install
604 by visiting:
605
606 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
607
608 Update the BootState to 'Reinstall', then reboot the node.
609
610 If you have already performed this step and are still receiving this
611 message, please reply so that we may investigate the problem.
612 """
613
614     # Load default message templates
615     message_templates = [
616         {'message_id': 'Verify account',
617          'subject': "Verify account registration",
618          'template': """
619 Please verify that you registered for a %(PLC_NAME)s account with the
620 username %(email)s by visiting:
621
622 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/register.php?id=%(person_id)d&key=%(verification_key)s
623
624 If you did not register for a %(PLC_NAME)s account, please ignore this
625 message, or contact %(PLC_NAME)s Support <%(PLC_MAIL_SUPPORT_ADDRESS)s>.
626 """
627          },
628
629         {'message_id': 'New PI account',
630          'subject': "New PI account registration from %(first_name)s %(last_name)s <%(email)s> at %(site_name)s",
631          'template': """
632 %(first_name)s %(last_name)s <%(email)s> has signed up for a new
633 %(PLC_NAME)s account at %(site_name)s and has requested a PI role. PIs
634 are responsible for enabling user accounts, creating slices, and
635 ensuring that all users abide by the %(PLC_NAME)s Acceptable Use
636 Policy.
637
638 Only %(PLC_NAME)s administrators may enable new PI accounts. If you
639 are a PI at %(site_name)s, please respond and indicate whether this
640 registration is acceptable.
641
642 To view the request, visit:
643
644 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/index.php?id=%(person_id)d
645 """
646          },
647
648         {'message_id': 'New account',
649          'subject': "New account registration from %(first_name)s %(last_name)s <%(email)s> at %(site_name)s",
650          'template': """
651 %(first_name)s %(last_name)s <%(email)s> has signed up for a new
652 %(PLC_NAME)s account at %(site_name)s and has requested the following
653 roles: %(roles)s.
654
655 To deny the request or enable the account, visit:
656
657 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/index.php?id=%(person_id)d
658 """
659          },
660
661         {'message_id': 'Password reset requested',
662          'subject': "Password reset requested",
663          'template': """
664 Someone has requested that the password of your %(PLC_NAME)s account
665 %(email)s be reset. If this person was you, you may continue with the
666 reset by visiting:
667
668 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/reset_password.php?id=%(person_id)d&key=%(verification_key)s
669
670 If you did not request that your password be reset, please contact
671 %(PLC_NAME)s Support <%(PLC_MAIL_SUPPORT_ADDRESS)s>. Do not quote or
672 otherwise include any of this text in any correspondence.
673 """
674          },
675
676         {'message_id': 'Password reset',
677          'subject': "Password reset",
678          'template': """
679 The password of your %(PLC_NAME)s account %(email)s has been
680 temporarily reset to:
681
682 %(password)s
683
684 Please change it at as soon as possible by visiting:
685
686 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/persons/index.php?id=%(person_id)d
687
688 If you did not request that your password be reset, please contact
689 %(PLC_NAME)s Support <%(PLC_MAIL_SUPPORT_ADDRESS)s>. Do not quote or
690 otherwise include any of this text in any correspondence.
691 """
692          },
693
694         # Boot Manager messages
695         {'message_id': "installfinished",
696          'subject': "%(hostname)s completed installation",
697          'template': """
698 %(hostname)s just completed installation.
699
700 The node should be usable in a couple of minutes if installation was
701 successful.
702 """
703          },
704
705         {'message_id': "insufficientdisk",
706          'subject': "%(hostname)s does not have sufficient disk space",
707          'template': """
708 %(hostname)s failed to boot because it does not have sufficent disk
709 space, or because its disk controller was not recognized.
710
711 Please replace the current disk or disk controller or install
712 additional disks to meet the current hardware requirements.
713 """ + installfailed
714          },
715
716         {'message_id': "insufficientmemory",
717          'subject': "%(hostname)s does not have sufficient memory",
718          'template': """
719 %(hostname)s failed to boot because it does not have sufficent
720 memory.
721
722 Please install additional memory to meet the current hardware
723 requirements.
724 """ + installfailed
725          },
726
727         {'message_id': "authfail",
728          'subject': "%(hostname)s failed to authenticate",
729          'template':
730 """
731 %(hostname)s failed to authenticate for the following reason:
732
733 %(fault)s
734
735 The most common reason for authentication failure is that the
736 authentication key stored in the node configuration file, does not
737 match the key on record. 
738
739 There are two possible steps to resolve the problem.
740
741 1. If you have used an All-in-one BootCD that includes the plnode.txt file,
742     then please check your machine for any old boot media, either in the
743     floppy drive, or on a USB stick.  It is likely that an old configuration
744     is being used instead of the new configuration stored on the BootCD.
745 Or, 
746 2. If you are using Generic BootCD image, then regenerate the node 
747     configuration file by visiting:
748
749     https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
750
751     Under 'Download', follow the 'Download plnode.txt file for %(hostname)s'
752     option, and save the downloaded file as plnode.txt on either a floppy 
753     disk or a USB flash drive.  Be sure the 'Boot State' is set to 'Boot', 
754     and, then reboot the node.
755
756 If you have already performed this step and are still receiving this
757 message, please reply so that we can help investigate the problem.
758 """
759          },
760
761         {'message_id': "notinstalled",
762          'subject': "%(hostname)s is not installed",
763          'template':
764 """
765 %(hostname)s failed to boot because it has either never been
766 installed, or the installation is corrupt.
767
768 Please check if the hard drive has failed, and replace it if so. After
769 doing so, visit:
770
771 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
772
773 Change the 'Boot State' to 'Reinstall', and then reboot the node.
774
775 If you have already performed this step and are still receiving this
776 message, please reply so that we may investigate the problem.
777 """
778          },
779
780         {'message_id': "hostnamenotresolve",
781          'subject': "%(hostname)s does not resolve",
782          'template':
783 """
784 %(hostname)s failed to boot because its hostname does not resolve, or
785 does resolve but does not match its configured IP address.
786
787 Please check the network settings for the node, especially its
788 hostname, IP address, and DNS servers, by visiting:
789
790 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
791
792 Correct any errors, and change the 'Boot State' to 'Reinstall', and then
793 reboot the node.
794
795 If you have already performed this step and are still receiving this
796 message, please reply so that we may investigate the problem.
797 """
798          },
799
800         # XXX N.B. I don't think these are necessary, since there's no
801         # way that the Boot Manager would even be able to contact the
802         # API to send these messages.
803
804         {'message_id': "noconfig",
805          'subject': "%(hostname)s does not have a configuration file",
806          'template': """
807 %(hostname)s failed to boot because it could not find a PlanetLab
808 configuration file. To create this file, visit:
809
810 https://%(PLC_WWW_HOST)s:%(PLC_WWW_SSL_PORT)d/db/nodes/?id=%(node_id)d
811
812 Click the Configuration File link, and save the downloaded file as
813 plnode.txt on either a floppy disk or a USB flash drive.  Change the 
814 'Boot State' to 'Reinstall', and then reboot the node.
815
816 If you have already performed this step and are still receiving this
817 message, please reply so that we may investigate the problem.
818 """
819          },
820
821         {'message_id': "nodetectednetwork",
822          'subject': "%(hostname)s has unsupported network hardware",
823          'template':
824 """
825
826 %(hostname)s failed to boot because it has network hardware that is
827 unsupported by the current production kernel. If it has booted
828 successfully in the past, please try re-installing it by visiting:
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
840     for template in message_templates:
841         messages = GetMessages([template['message_id']])
842         if not messages:
843             AddMessage(template)
844
845     
846     ### Setup Initial PCU information
847     pcu_types = [{'model': 'AP79xx',
848           'name': 'APC AP79xx',
849           'pcu_protocol_types': [{ 'port': 80,
850                                   'protocol': 'APC79xxHttp',
851                                   'supported': False},
852                                  { 'port': 23,
853                                   'protocol': 'APC79xx',
854                                   'supported': True},
855                                  { 'port': 22,
856                                   'protocol': 'APC79xx',
857                                   'supported': True}],
858           },
859          {'model': 'Masterswitch',
860           'name': 'APC Masterswitch',
861           'pcu_protocol_types': [{ 'port': 80,
862                                   'protocol': 'APCMasterHttp',
863                                   'supported': False},
864                                  { 'port': 23,
865                                   'protocol': 'APCMaster',
866                                   'supported': True},
867                                  { 'port': 22,
868                                   'protocol': 'APCMaster',
869                                   'supported': True}],
870           },
871          {'model': 'DS4-RPC',
872           'name': 'BayTech DS4-RPC',
873           'pcu_protocol_types': [{ 'port': 80,
874                                   'protocol': 'BayTechHttp',
875                                   'supported': False},
876                                  { 'port': 23,
877                                   'protocol': 'BayTech',
878                                   'supported': True},
879                                  { 'port': 22,
880                                   'protocol': 'BayTech',
881                                   'supported': True}],
882           },
883          {'model': 'IP-41x_IP-81x',
884           'name': 'Dataprobe IP-41x & IP-81x',
885           'pcu_protocol_types': [ { 'port': 23,
886                                   'protocol': 'IPALTelnet',
887                                   'supported': True},
888                                   { 'port': 80,
889                                   'protocol': 'IPALHttp',
890                                   'supported': False}],
891           },
892          {'model': 'DRAC3',
893           'name': 'Dell RAC Version 3',
894           'pcu_protocol_types': [],
895           },
896          {'model': 'DRAC4',
897           'name': 'Dell RAC Version 4',
898           'pcu_protocol_types': [{ 'port': 443,
899                                   'protocol': 'DRACRacAdm',
900                                   'supported': True},
901                                  { 'port': 80,
902                                   'protocol': 'DRACRacAdm',
903                                   'supported': False},
904                                  { 'port': 22,
905                                   'protocol': 'DRAC',
906                                   'supported': True}],
907           },
908          {'model': 'ePowerSwitch',
909           'name': 'ePowerSwitch 1/4/8x',
910           'pcu_protocol_types': [{ 'port': 80,
911                                   'protocol': 'ePowerSwitch',
912                                   'supported': True}],
913           },
914          {'model': 'ilo2',
915           'name': 'HP iLO2 (Integrated Lights-Out)',
916           'pcu_protocol_types': [{ 'port': 443,
917                                   'protocol': 'HPiLOHttps',
918                                   'supported': True},
919                                  { 'port': 22,
920                                   'protocol': 'HPiLO',
921                                   'supported': True}],
922           },
923          {'model': 'ilo1',
924           'name': 'HP iLO version 1',
925           'pcu_protocol_types': [],
926           },
927          {'model': 'PM211-MIP',
928           'name': 'Infratec PM221-MIP',
929           'pcu_protocol_types': [],
930           },
931          {'model': 'AMT2.5',
932           'name': 'Intel AMT v2.5 (Active Management Technology)',
933           'pcu_protocol_types': [],
934           },
935          {'model': 'AMT3.0',
936           'name': 'Intel AMT v3.0 (Active Management Technology)',
937           'pcu_protocol_types': [],
938           },
939          {'model': 'WTI_IPS-4',
940           'name': 'Western Telematic (WTI IPS-4)',
941           'pcu_protocol_types': [],
942           },
943          {'model': 'unknown',
944           'name': 'Unknown Vendor or Model',
945           'pcu_protocol_types': [{ 'port': 443,
946                                   'protocol': 'UnknownPCU',
947                                   'supported': False},
948                                  { 'port': 80,
949                                   'protocol': 'UnknownPCU',
950                                   'supported': False},
951                                  { 'port': 23,
952                                   'protocol': 'UnknownPCU',
953                                   'supported': False},
954                                  { 'port': 22,
955                                   'protocol': 'UnknownPCU',
956                                   'supported': False}],
957           }]
958
959     # Get all model names
960     pcu_models = [type['model'] for type in GetPCUTypes()]
961     for type in pcu_types:
962         protocol_types = type['pcu_protocol_types']
963         # Take this value out of the struct.
964         del type['pcu_protocol_types']
965         if type['model'] not in pcu_models:
966             # Add the name/model info into DB
967             id = AddPCUType(type)
968             # for each protocol, also add this.
969             for ptype in protocol_types:
970                 AddPCUProtocolType(id, ptype)
971
972
973 if __name__ == '__main__':
974     main()
975
976 # Local variables:
977 # tab-width: 4
978 # mode: python
979 # End: