- handle case when there are no nodes
[myplc.git] / api-config
1 #!/usr/bin/python
2 #
3 # Bootstraps the PLC database with a default administrator account and
4 # a default site.
5 #
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2006 The Trustees of Princeton University
8 #
9 # $Id: api-config,v 1.9 2006/05/23 18:09:21 mlhuang Exp $
10 #
11
12 import plcapilib
13 (plcapi, moreopts, argv) = plcapilib.plcapi(globals())
14 from plc_config import PLCConfiguration
15 import sys
16
17
18 def main():
19     cfg = PLCConfiguration()
20     cfg.load()
21     variables = cfg.variables()
22
23     # Load variables into dictionaries
24     (category, variablelist) = variables['plc']
25     plc = dict(zip(variablelist.keys(),
26                    [variable['value'] for variable in variablelist.values()]))
27
28     (category, variablelist) = variables['plc_www']
29     plc_www = dict(zip(variablelist.keys(),
30                        [variable['value'] for variable in variablelist.values()]))
31
32     (category, variablelist) = variables['plc_api']
33     plc_api = dict(zip(variablelist.keys(),
34                        [variable['value'] for variable in variablelist.values()]))
35
36     # Create/update the default administrator account (should be
37     # person_id 2).
38     admin = { 'person_id': 2,
39               'first_name': "Default",
40               'last_name': "Administrator",
41               'email': plc['root_user'],
42               'password': plc['root_password'] }
43     persons = AdmGetPersons([admin['person_id']])
44     if not persons:
45         person_id = AdmAddPerson(admin['first_name'], admin['last_name'], admin)
46         if person_id != admin['person_id']:
47             # Huh? Someone deleted the account manually from the database.
48             AdmDeletePerson(person_id)
49             raise Exception, "Someone deleted the \"%s %s\" account from the database!" % \
50                   (admin['first_name'], admin['last_name'])
51         AdmSetPersonEnabled(person_id, True)
52     else:
53         person_id = persons[0]['person_id']
54         AdmUpdatePerson(person_id, admin)
55
56     # Create/update the default site (should be site_id 1)
57     if plc_www['port'] == '80':
58         url = "http://" + plc_www['host'] + "/"
59     elif plc_www['port'] == '443':
60         url = "https://" + plc_www['host'] + "/"
61     else:
62         url = "http://" + plc_www['host'] + ":" + plc_www['port'] + "/"
63     site = { 'site_id': 1,
64              'name': plc['name'] + " Central",
65              'abbreviated_name': plc['name'],
66              # XXX Default site slice_prefix/login_base must be "pl_"
67              # 'login_base': plc['slice_prefix'],
68              'login_base': "pl",
69              'is_public': False,
70              'url': url,
71              'max_slices': 100 }
72
73     sites = AdmGetSites([site['site_id']])
74     if not sites:
75         site_id = AdmAddSite(site['name'], site['abbreviated_name'], site['login_base'], site)
76         if site_id != site['site_id']:
77             AdmDeleteSite(site_id)
78             raise Exception, "Someone deleted the \"%s\" site from the database!" % \
79                   site['name']
80         sites = [site]
81
82     # Must call AdmUpdateSite() even after AdmAddSite() to update max_slices
83     site_id = sites[0]['site_id']
84     # XXX login_base cannot be updated
85     del site['login_base']
86     AdmUpdateSite(site_id, site)
87
88     # The default administrator account must be associated with a site
89     # in order to login.
90     AdmAddPersonToSite(admin['person_id'], site['site_id'])
91     AdmSetPersonPrimarySite(admin['person_id'], site['site_id'])
92
93     # Grant admin and PI roles to the default administrator account
94     AdmGrantRoleToPerson(admin['person_id'], 10)
95     AdmGrantRoleToPerson(admin['person_id'], 20)
96
97     # Get the primary IP address for each node
98     hosts = {}
99     nodes = AdmGetNodes([], ['node_id', 'hostname'])
100     plcapi.begin()
101     for node in nodes:
102         AdmGetAllNodeNetworks(node['node_id'])
103     nodenetworks_list = plcapi.commit()
104     if nodenetworks_list is not None:
105         for i, nodenetworks in enumerate(nodenetworks_list):
106             for nodenetwork in nodenetworks:
107                 if nodenetwork['hostname']:
108                     hostname = nodenetwork['hostname']
109                 else:
110                     hostname = nodes[i]['hostname']
111         
112                 if hosts.has_key(nodenetwork['ip']):
113                     if hostname not in hosts[nodenetwork['ip']]:
114                         hosts[nodenetwork['ip']].append(hostname)
115                 else:
116                     hosts[nodenetwork['ip']] = [hostname]
117     
118     # Write /etc/plc_hosts
119     plc_hosts = open("/etc/plc_hosts", "w")
120     for ip, hostnames in hosts.iteritems():
121         plc_hosts.write(ip + "\t" + " ".join(hostnames) + "\n")
122     plc_hosts.close()
123
124     # Setup default PlanetLabConf entries
125     default_conf_files = [
126         # NTP configuration
127         {'enabled': 1,
128          'source': 'PlanetLabConf/ntpconf.php',
129          'dest': '/etc/ntp.conf',
130          'file_permissions': '644',
131          'file_owner': 'root',
132          'file_group': 'root',
133          'preinstall_cmd': '',
134          'postinstall_cmd': '/etc/rc.d/init.d/ntpd restart',
135          'error_cmd': '',
136          'ignore_cmd_errors': 0,
137          'always_update': 0},
138         {'enabled': 1,
139          'source': 'PlanetLabConf/ntptickers.php',
140          'dest': '/etc/ntp/step-tickers',
141          'file_permissions': '644',
142          'file_owner': 'root',
143          'file_group': 'root',
144          'preinstall_cmd': '',
145          'postinstall_cmd': '/etc/rc.d/init.d/ntpd restart',
146          'error_cmd': '',
147          'ignore_cmd_errors': 0,
148          'always_update': 0},
149
150         # SSH server configuration
151         {'enabled': 1,
152          'source': 'PlanetLabConf/sshd_config',
153          'dest': '/etc/ssh/sshd_config',
154          'file_permissions': '600',
155          'file_owner': 'root',
156          'file_group': 'root',
157          'preinstall_cmd': '',
158          'postinstall_cmd': '/etc/init.d/sshd restart',
159          'error_cmd': '',
160          'ignore_cmd_errors': 0,
161          'always_update': 0},
162
163         # Administrative SSH keys
164         {'enabled': 1,
165          'source': 'PlanetLabConf/keys.php?root',
166          'dest': '/root/.ssh/authorized_keys',
167          'file_permissions': '644',
168          'file_owner': 'root',
169          'file_group': 'root',
170          'preinstall_cmd': '',
171          'postinstall_cmd': '',
172          'error_cmd': '',
173          'ignore_cmd_errors': 0,
174          'always_update': 0},
175         {'enabled': 1,
176          'source': 'PlanetLabConf/keys.php?site_admin',
177          'dest': '/home/site_admin/.ssh/authorized_keys',
178          'file_permissions': '644',
179          'file_owner': 'site_admin',
180          'file_group': 'site_admin',
181          'preinstall_cmd': 'grep -q site_admin /etc/passwd',
182          'postinstall_cmd': '',
183          'error_cmd': '',
184          'ignore_cmd_errors': 0,
185          'always_update': 0},
186         {'enabled': 1,
187          'source': 'PlanetLabConf/keys.php?role=admin',
188          'dest': '/home/pl_admin/.ssh/authorized_keys',
189          'file_permissions': '644',
190          'file_owner': 'pl_admin',
191          'file_group': 'pl_admin',
192          'preinstall_cmd': 'grep -q pl_admin /etc/passwd',
193          'postinstall_cmd': '',
194          'error_cmd': '',
195          'ignore_cmd_errors': 0,
196          'always_update': 0},
197
198         # Log rotation configuration
199         {'enabled': 1,
200          'source': 'PlanetLabConf/logrotate.conf',
201          'dest': '/etc/logrotate.conf',
202          'file_permissions': '644',
203          'file_owner': 'root',
204          'file_group': 'root',
205          'preinstall_cmd': '',
206          'postinstall_cmd': '',
207          'error_cmd': '',
208          'ignore_cmd_errors': 0,
209          'always_update': 0},
210
211         # updatedb/locate nightly cron job
212         {'enabled': 1,
213          'source': 'PlanetLabConf/slocate.cron',
214          'dest': '/etc/cron.daily/slocate.cron',
215          'file_permissions': '755',
216          'file_owner': 'root',
217          'file_group': 'root',
218          'preinstall_cmd': '',
219          'postinstall_cmd': '',
220          'error_cmd': '',
221          'ignore_cmd_errors': 0,
222          'always_update': 0},
223
224         # YUM configuration
225         {'enabled': 1,
226          'source': 'PlanetLabConf/yum.conf.php?gpgcheck=1',
227          'dest': '/etc/yum.conf',
228          'file_permissions': '644',
229          'file_owner': 'root',
230          'file_group': 'root',
231          'preinstall_cmd': '',
232          'postinstall_cmd': '',
233          'error_cmd': '',
234          'ignore_cmd_errors': 0,
235          'always_update': 0},
236         {'enabled': 1,
237          'source': 'PlanetLabConf/delete-rpm-list-production',
238          'dest': '/etc/planetlab/delete-rpm-list',
239          'file_permissions': '644',
240          'file_owner': 'root',
241          'file_group': 'root',
242          'preinstall_cmd': '',
243          'postinstall_cmd': '',
244          'error_cmd': '',
245          'ignore_cmd_errors': 0,
246          'always_update': 0},
247
248         # PLC configuration
249         {'enabled': 1,
250          'source': 'PlanetLabConf/get_plc_config.php',
251          'dest': '/etc/planetlab/plc_config',
252          'file_permissions': '644',
253          'file_owner': 'root',
254          'file_group': 'root',
255          'preinstall_cmd': '',
256          'postinstall_cmd': '',
257          'error_cmd': '',
258          'ignore_cmd_errors': 0,
259          'always_update': 0},
260         {'enabled': 1,
261          'source': 'PlanetLabConf/get_plc_config.php?python',
262          'dest': '/etc/planetlab/plc_config.py',
263          'file_permissions': '644',
264          'file_owner': 'root',
265          'file_group': 'root',
266          'preinstall_cmd': '',
267          'postinstall_cmd': '',
268          'error_cmd': '',
269          'ignore_cmd_errors': 0,
270          'always_update': 0},
271         {'enabled': 1,
272          'source': 'PlanetLabConf/get_plc_config.php?perl',
273          'dest': '/etc/planetlab/plc_config.pl',
274          'file_permissions': '644',
275          'file_owner': 'root',
276          'file_group': 'root',
277          'preinstall_cmd': '',
278          'postinstall_cmd': '',
279          'error_cmd': '',
280          'ignore_cmd_errors': 0,
281          'always_update': 0},
282         {'enabled': 1,
283          'source': 'PlanetLabConf/get_plc_config.php?php',
284          'dest': '/etc/planetlab/php/plc_config.php',
285          'file_permissions': '644',
286          'file_owner': 'root',
287          'file_group': 'root',
288          'preinstall_cmd': '',
289          'postinstall_cmd': '',
290          'error_cmd': '',
291          'ignore_cmd_errors': 0,
292          'always_update': 0},
293
294         # Node Manager configuration
295         {'enabled': 1,
296          'source': 'PlanetLabConf/pl_nm-v3.conf',
297          'dest': '/etc/planetlab/pl_nm.conf',
298          'file_permissions': '644',
299          'file_owner': 'root',
300          'file_group': 'root',
301          'preinstall_cmd': '',
302          'postinstall_cmd': '/etc/init.d/pl_nm restart',
303          'error_cmd': '',
304          'ignore_cmd_errors': 0,
305          'always_update': 0},
306         {'enabled': 1,
307          'source': 'PlanetLabConf/RootResources/plc_slice_pool.php',
308          'dest': '/home/pl_nm/RootResources/plc_slice_pool',
309          'file_permissions': '644',
310          'file_owner': 'pl_nm',
311          'file_group': 'pl_nm',
312          'preinstall_cmd': '',
313          'postinstall_cmd': '',
314          'error_cmd': '',
315          'ignore_cmd_errors': 0,
316          'always_update': 0},
317         {'enabled': 1,
318          'source': 'PlanetLabConf/RootResources/pl_conf.py',
319          'dest': '/home/pl_nm/RootResources/pl_conf',
320          'file_permissions': '644',
321          'file_owner': 'pl_nm',
322          'file_group': 'pl_nm',
323          'preinstall_cmd': '',
324          'postinstall_cmd': '/etc/init.d/pl_nm restart',
325          'error_cmd': '',
326          'ignore_cmd_errors': 0,
327          'always_update': 0},
328         {'enabled': 1,
329          'source': 'PlanetLabConf/RootResources/pl_netflow.py',
330          'dest': '/home/pl_nm/RootResources/pl_netflow',
331          'file_permissions': '644',
332          'file_owner': 'pl_nm',
333          'file_group': 'pl_nm',
334          'preinstall_cmd': '',
335          'postinstall_cmd': '',
336          'error_cmd': '',
337          'ignore_cmd_errors': 0,
338          'always_update': 0},
339
340         # Proper configuration
341         {'enabled': 1,
342          'source': 'PlanetLabConf/propd-NM-1.0.conf',
343          'dest': '/etc/proper/propd.conf',
344          'file_permissions': '644',
345          'file_owner': 'root',
346          'file_group': 'root',
347          'preinstall_cmd': '',
348          'postinstall_cmd': '/etc/init.d/proper restart',
349          'error_cmd': '',
350          'ignore_cmd_errors': 1,
351          'always_update': 0},
352
353         # Bandwidth cap
354         {'enabled': 1,
355          'source': 'PlanetLabConf/bwlimit.php',
356          'dest': '/etc/planetlab/bwcap',
357          'file_permissions': '644',
358          'file_owner': 'root',
359          'file_group': 'root',
360          'preinstall_cmd': '',
361          'postinstall_cmd': '/etc/init.d/pl_nm restart',
362          'error_cmd': '',
363          'ignore_cmd_errors': 1,
364          'always_update': 0},
365
366         # Proxy ARP setup
367         {'enabled': 1,
368          'source': 'PlanetLabConf/proxies.php',
369          'dest': '/etc/planetlab/proxies',
370          'file_permissions': '644',
371          'file_owner': 'root',
372          'file_group': 'root',
373          'preinstall_cmd': '',
374          'postinstall_cmd': '',
375          'error_cmd': '',
376          'ignore_cmd_errors': 0,
377          'always_update': 0},
378
379         # Firewall configuration
380         {'enabled': 1,
381          'source': 'PlanetLabConf/iptables',
382          'dest': '/etc/sysconfig/iptables',
383          'file_permissions': '600',
384          'file_owner': 'root',
385          'file_group': 'root',
386          'preinstall_cmd': '',
387          'postinstall_cmd': '',
388          'error_cmd': '',
389          'ignore_cmd_errors': 0,
390          'always_update': 0},
391         {'enabled': 1,
392          'source': 'PlanetLabConf/blacklist.php',
393          'dest': '/etc/planetlab/blacklist',
394          'file_permissions': '600',
395          'file_owner': 'root',
396          'file_group': 'root',
397          'preinstall_cmd': '',
398          'postinstall_cmd': '/sbin/iptables-restore --noflush < /etc/planetlab/blacklist',
399          'error_cmd': '',
400          'ignore_cmd_errors': 1,
401          'always_update': 1},
402
403         # /etc/issue
404         {'enabled': 1,
405          'source': 'PlanetLabConf/issue.php',
406          'dest': '/etc/issue',
407          'file_permissions': '644',
408          'file_owner': 'root',
409          'file_group': 'root',
410          'preinstall_cmd': '',
411          'postinstall_cmd': '',
412          'error_cmd': '',
413          'ignore_cmd_errors': 0,
414          'always_update': 0},
415
416         # Kernel parameters
417         {'enabled': 1,
418          'source': 'PlanetLabConf/sysctl.php',
419          'dest': '/etc/sysctl.conf',
420          'file_permissions': '644',
421          'file_owner': 'root',
422          'file_group': 'root',
423          'preinstall_cmd': '',
424          'postinstall_cmd': '/sbin/sysctl -e -p /etc/sysctl.conf',
425          'error_cmd': '',
426          'ignore_cmd_errors': 0,
427          'always_update': 1},
428
429         # Sendmail configuration
430         {'enabled': 1,
431          'source': 'PlanetLabConf/alpha-sendmail.mc',
432          'dest': '/etc/mail/sendmail.mc',
433          'file_permissions': '644',
434          'file_owner': 'root',
435          'file_group': 'root',
436          'preinstall_cmd': '',
437          'postinstall_cmd': '',
438          'error_cmd': '',
439          'ignore_cmd_errors': 0,
440          'always_update': 0},
441         {'enabled': 1,
442          'source': 'PlanetLabConf/alpha-sendmail.cf',
443          'dest': '/etc/mail/sendmail.cf',
444          'file_permissions': '644',
445          'file_owner': 'root',
446          'file_group': 'root',
447          'preinstall_cmd': '',
448          'postinstall_cmd': 'service sendmail restart',
449          'error_cmd': '',
450          'ignore_cmd_errors': 0,
451          'always_update': 0},
452
453         # GPG signing keys
454         {'enabled': 1,
455          'source': 'PlanetLabConf/RPM-GPG-KEY-fedora',
456          'dest': '/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora',
457          'file_permissions': '644',
458          'file_owner': 'root',
459          'file_group': 'root',
460          'preinstall_cmd': '',
461          'postinstall_cmd': 'rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora',
462          'error_cmd': '',
463          'ignore_cmd_errors': 0,
464          'always_update': 0},
465         {'enabled': 1,
466          'source': 'PlanetLabConf/get_gpg_key.php',
467          'dest': '/etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab',
468          'file_permissions': '644',
469          'file_owner': 'root',
470          'file_group': 'root',
471          'preinstall_cmd': '',
472          'postinstall_cmd': 'rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab',
473          'error_cmd': '',
474          'ignore_cmd_errors': 0,
475          'always_update': 0},
476
477         # Ping of death configuration
478         {'enabled': 1,
479          'source': 'PlanetLabConf/ipod.conf.php',
480          'dest': '/etc/ipod.conf',
481          'file_permissions': '644',
482          'file_owner': 'root',
483          'file_group': 'root',
484          'preinstall_cmd': '',
485          'postinstall_cmd': '',
486          'error_cmd': '',
487          'ignore_cmd_errors': 0,
488          'always_update': 0},
489
490         # sudo configuration
491         {'enabled': 1,
492          'source': 'PlanetLabConf/v3-sudoers.php',
493          'dest': '/etc/sudoers',
494          'file_permissions': '440',
495          'file_owner': 'root',
496          'file_group': 'root',
497          'preinstall_cmd': '',
498          'postinstall_cmd': '/usr/sbin/visudo -c',
499          'error_cmd': '',
500          'ignore_cmd_errors': 0,
501          'always_update': 0}]
502
503     # Get list of existing (enabled, global) files
504     conf_files = AdmGetConfFile()
505     conf_files = filter(lambda conf_file: conf_file['enabled'] and \
506                                           not conf_file['node_id'] and \
507                                           not conf_file['nodegroup_id'],
508                         conf_files)
509     dests = [conf_file['dest'] for conf_file in conf_files]
510     conf_files = dict(zip(dests, conf_files))
511
512     # Create/update default PlanetLabConf entries
513     for default_conf_file in default_conf_files:
514         if default_conf_file['dest'] not in dests:
515             AdmCreateConfFile(default_conf_file['enabled'],
516                               default_conf_file['source'],
517                               default_conf_file['dest'],
518                               default_conf_file['file_permissions'],
519                               default_conf_file['file_owner'],
520                               default_conf_file['file_group'],
521                               default_conf_file['preinstall_cmd'],
522                               default_conf_file['postinstall_cmd'],
523                               default_conf_file['error_cmd'],
524                               default_conf_file['ignore_cmd_errors'],
525                               default_conf_file['always_update'])
526         else:
527             conf_file = conf_files[default_conf_file['dest']]
528             AdmUpdateConfFile(conf_file['conf_file_id'], default_conf_file)
529
530     # Setup default slice attribute types
531     default_attribute_types = [
532         # Slice type (only vserver is supported)
533         {'name': "plc_slice_type",
534          'description': "Type of slice rspec to be created",
535          'is_exclusive': True, 'min_role_id': 20, 'max_per_slice': 1,
536          'value_fields': [{'description': "rspec class",
537                            'name': "type",
538                            'type': "string"}]},
539
540         # Slice initialization script
541         {'name': "initscript",
542          'description': "slice initialization script",
543          'is_exclusive': False, 'min_role_id': 10, 'max_per_slice': 1,
544          'value_fields': [{'description': "",
545                            'name': "initscript_id",
546                            'type': "integer"}]},
547
548         # CPU share (general_prop_share is deprecated)
549         {'name': "general_prop_share",
550          'description': "general share",
551          'is_exclusive': False, 'min_role_id': 10, 'max_per_slice': 1,
552          'value_fields': [{'description': "",
553                            'name': "general_prop_share",
554                            'type': "integer"}]},
555         {'name': "nm_cpu_share",
556          'description': "Number of CPU shares to be allocated to slice",
557          'is_exclusive': True, 'min_role_id': 10, 'max_per_slice': 1,
558          'value_fields': [{'description': "number of shares",
559                            'name': "cpu_share",
560                            'type': "integer"}]},
561
562         # Bandwidth limits
563         {'name': "nm_net_min_rate",
564          'description': "Minimum network Tx bandwidth",
565          'is_exclusive': True, 'min_role_id': 10, 'max_per_slice': 1,
566          'value_fields': [{'description': "rate (kbps)",
567                            'name': "rate",
568                            'type': "integer"}]},
569         {'name': "nm_net_max_rate",
570          'description': "Maximum network Tx bandwidth",
571          'is_exclusive': True, 'min_role_id': 10, 'max_per_slice': 1,
572          'value_fields': [{'description': "rate (kbps)",
573                            'name': "rate",
574                            'type': "integer"}]},
575         {'name': "nm_net_avg_rate",
576          'description': "Average daily network Tx bandwidth",
577          'is_exclusive': True, 'min_role_id': 10, 'max_per_slice': 1,
578          'value_fields': [{'description': "rate (kbps)",
579                            'name': "rate",
580                            'type': "integer"}]},
581         {'name': "nm_net_exempt_min_rate",
582          'description': "Minimum network Tx bandwidth to Internet2 destinations",
583          'is_exclusive': True, 'min_role_id': 10, 'max_per_slice': 1,
584          'value_fields': [{'description': "rate (kbps)",
585                            'name': "rate",
586                            'type': "integer"}]},
587         {'name': "nm_net_exempt_max_rate",
588          'description': "Maximum network Tx bandwidth to Internet2 destinations",
589          'is_exclusive': True, 'min_role_id': 10, 'max_per_slice': 1,
590          'value_fields': [{'description': "rate (kbps)",
591                            'name': "rate",
592                            'type': "integer"}]},
593         {'name': "nm_net_exempt avg_rate",
594          'description': "Average daily network Tx bandwidth to Internet2 destinations",
595          'is_exclusive': True, 'min_role_id': 10, 'max_per_slice': 1,
596          'value_fields': [{'description': "rate (kbps)",
597                            'name': "rate",
598                            'type': "integer"}]},
599
600         # Disk quota
601         {'name': "nm_disk_quota",
602          'description': "Disk quota",
603          'is_exclusive': True, 'min_role_id': 10, 'max_per_slice': 1,
604          'value_fields': [{'description': "Number of 1k disk blocks",
605                            'name': "quota",
606                            'type': "integer"}]},
607
608         # Special attributes applicable to Slice Creation Service (pl_conf) slice
609         {'name': "plc_agent_version",
610          'description': "Version of PLC agent (slice creation service) software to be deployed",
611          'is_exclusive': True, 'min_role_id': 10, 'max_per_slice': 1,
612          'value_fields': [{'description': "current version of PLC agent (SCS)",
613                            'name': "version",
614                            'type': "string"}]},
615         {'name': "plc_ticket_pubkey",
616          'description': "Public key used to verify PLC-signed tickets",
617          'is_exclusive': True, 'min_role_id': 10, 'max_per_slice': 1,
618          'value_fields': [{'description': "PEM-encoded public key",
619                            'name': "key",
620                            'type': "string"}]}]
621
622     # Get list of existing attribute types
623     attribute_types = SliceAttributeTypeList()
624
625     # Create/update default slice attribute types
626     for default_attribute_type in default_attribute_types:
627         if default_attribute_type['name'] not in attribute_types:
628             SliceAttributeTypeCreate(default_attribute_type['name'],
629                                      default_attribute_type['description'],
630                                      default_attribute_type['min_role_id'],
631                                      default_attribute_type['max_per_slice'],
632                                      default_attribute_type['is_exclusive'],
633                                      default_attribute_type['value_fields'])
634         else:
635             # XXX No way to update slice attribute types
636             pass
637
638     # Get contents of SSL public certificate used for signing tickets
639     try:
640         plc_ticket_pubkey = ""
641         for line in file(plc_api['ssl_key_pub']):
642             # Skip comments
643             if line[0:5] != "-----":
644                 # XXX The embedded newlines matter, do not strip()!
645                 plc_ticket_pubkey += line
646     except:
647         plc_ticket_pubkey = '%KEY%'
648
649     # Create/update system slices
650     slices = [{'name': "pl_conf",
651                'description': "PlanetLab Slice Creation Service (SCS)",
652                'url': url,
653                'attributes': {'plc_slice_type': {'type': "VServerSlice"},
654                               'plc_agent_version': {'version': "1.0"},
655                               'plc_ticket_pubkey': {'key': plc_ticket_pubkey}}},
656               {'name': "pl_conf_vserverslice",
657                'description': "Default attributes for vserver slices",
658                'url': url,
659                'attributes': {'nm_cpu_share': {'cpu_share': 32},
660                               'plc_slice_type': {'type': "VServerSlice"},
661                               'nm_disk_quota': {'quota': 5000000}}}]
662     for slice in slices:
663         try:
664             SliceInfo([slice['name']])
665         except:
666             SliceCreate(slice['name'])
667             SliceSetInstantiationMethod(slice['name'], 'plc-instantiated')
668         SliceUpdate(slice['name'], slice['url'], slice['description'])
669         # Renew forever
670         SliceRenew(slice['name'], sys.maxint)
671         # Create/update all attributes
672         for attribute, values in slice['attributes'].iteritems():
673             SliceAttributeSet(slice['name'], attribute, values)
674
675
676 if __name__ == '__main__':
677     main()