allow stepwise start/stop
[myplc.git] / api-config
index 51f8e30..d217042 100755 (executable)
@@ -6,7 +6,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: api-config,v 1.1.1.1 2006/03/27 17:36:46 mlhuang Exp $
+# $Id: api-config,v 1.4 2006/03/28 22:35:42 mlhuang Exp $
 #
 
 import plcapilib
@@ -66,7 +66,7 @@ def main():
              'abbreviated_name': plc['name'],
              # XXX Default site slice_prefix/login_base must be "pl_"
              # 'login_base': plc['slice_prefix'],
-             'login_base': "pl_",
+             'login_base': "pl",
              'is_public': False,
              'url': url,
              'max_slices': 100 }
@@ -78,11 +78,13 @@ def main():
             AdmDeleteSite(site_id)
             raise Exception, "Someone deleted the \"%s\" site from the database!" % \
                   site['name']
-    else:
-        site_id = sites[0]['site_id']
-        # XXX login_base cannot be updated
-        del site['login_base']
-        AdmUpdateSite(site_id, site)
+        sites = [site]
+
+    # Must call AdmUpdateSite() even after AdmAddSite() to update max_slices
+    site_id = sites[0]['site_id']
+    # XXX login_base cannot be updated
+    del site['login_base']
+    AdmUpdateSite(site_id, site)
 
     # The default administrator account must be associated with a site
     # in order to login.
@@ -184,39 +186,42 @@ def main():
                                      attribute_type['min_role_id'], attribute_type['max_per_slice'],
                                      attribute_type['is_exclusive'], attribute_type['value_fields'])
 
-    if not SliceListNames():
-        # Get contents of SSL public certificate used for signing tickets
+    # Get contents of SSL public certificate used for signing tickets
+    try:
+        plc_ticket_pubkey = ""
+        for line in file(plc_api['ssl_key_pub']):
+            # Skip comments
+            if line[0:5] != "-----":
+                # XXX The embedded newlines matter, do not strip()!
+                plc_ticket_pubkey += line
+    except:
+        plc_ticket_pubkey = '%KEY%'
+
+    # Create/update system slices
+    slices = [{'name': "pl_conf",
+               'description': "PlanetLab Slice Creation Service (SCS)",
+               'url': url,
+               'attributes': {'plc_slice_type': {'type': "VServerSlice"},
+                              'plc_agent_version': {'version': "1.0"},
+                              'plc_ticket_pubkey': {'key': plc_ticket_pubkey}}},
+              {'name': "pl_conf_vserverslice",
+               'description': "Default attributes for vserver slices",
+               'url': url,
+               'attributes': {'nm_cpu_share': {'cpu_share': 32},
+                              'plc_slice_type': {'type': "VServerSlice"},
+                              'nm_disk_quota': {'quota': 5000000}}}]
+    for slice in slices:
         try:
-            plc_ticket_pubkey = ""
-            for line in file(plc_api['ssl_key_pub']):
-                # Skip comments
-                if line[0:5] != "-----":
-                    # XXX The embedded newlines matter, do not strip()!
-                    plc_ticket_pubkey += line
+            SliceInfo([slice['name']])
         except:
-            plc_ticket_pubkey = '%KEY%'
-
-        # Create system slices
-        slices = [{'name': "pl_conf",
-                   'description': "PlanetLab Slice Creation Service (SCS)",
-                   'url': url,
-                   'attributes': {'plc_slice_type': {'type': "VServerSlice"},
-                                  'plc_agent_version': {'version': "1.0"},
-                                  'plc_ticket_pubkey': {'key': plc_ticket_pubkey}}},
-                  {'name': "pl_conf_vserverslice",
-                   'description': "Default attributes for vserver slices",
-                   'url': url,
-                   'attributes': {'nm_cpu_share': {'cpu_share': 32},
-                                  'plc_slice_type': {'type': "VServerSlice"},
-                                  'nm_disk_quota': {'quota': 5000000}}}]
-        for slice in slices:
             SliceCreate(slice['name'])
-            SliceUpdate(slice['name'], slice['url'], slice['description'])
             SliceSetInstantiationMethod(slice['name'], 'plc-instantiated')
-            # Renew forever
-            SliceRenew(slice['name'], sys.maxint)
-            for attribute, values in slice['attributes'].iteritems():
-                SliceAttributeAdd(slice['name'], attribute, values)
+        SliceUpdate(slice['name'], slice['url'], slice['description'])
+        # Renew forever
+        SliceRenew(slice['name'], sys.maxint)
+        # Create/update all attributes
+        for attribute, values in slice['attributes'].iteritems():
+            SliceAttributeSet(slice['name'], attribute, values)
 
 
 if __name__ == '__main__':