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