make executable
[sfa.git] / geni / plc.py
index a30225d..66d8ae2 100644 (file)
@@ -1,3 +1,4 @@
+#!/usr/bin/python
 ##
 # GENI PLC Wrapper
 #
 # is up to date and accurate.
 #
 # 1) Import the existing planetlab database, creating the
-#    appropriate geni records. This is done by running the "import.py" tool.
+#    appropriate geni records. This is done by running the "gimport.py" tool.
 #
 # 2) Create a "trusted_roots" directory and place the certificate of the root
-#    authority in that directory. Given the defaults in import.py, this
+#    authority in that directory. Given the defaults in gimport.py, this
 #    certificate would be named "planetlab.gid". For example,
 #
 #    mkdir trusted_roots; cp authorities/planetlab.gid trusted_roots/
@@ -62,11 +63,19 @@ def main():
     key_file = "server.key"
     cert_file = "server.cert"
 
-    # if no key is specified, then make one up
-    if (not os.path.exists(key_file)) or (not os.path.exists(cert_file)):
+    if (os.path.exists(key_file)) and (not os.path.exists(cert_file)):
+        # If private key exists and cert doesnt, recreate cert
+        key = Keypair(filename=key_file)
+        cert = Certificate(subject="registry")
+        cert.set_issuer(key=key, subject="registry")
+        cert.set_pubkey(key)
+        cert.sign()
+        cert.save_to_file(cert_file)
+
+    elif (not os.path.exists(key_file)) or (not os.path.exists(cert_file)):
+        # if no key is specified, then make one up
         key = Keypair(create=True)
         key.save_to_file(key_file)
-
         cert = Certificate(subject="registry")
         cert.set_issuer(key=key, subject="registry")
         cert.set_pubkey(key)