removed another bunch of references to geni
[sfa.git] / sfa / methods / get_key.py
index dd9076c..c641985 100644 (file)
@@ -4,11 +4,11 @@ import os
 import tempfile
 import commands
 from sfa.util.faults import *
-from sfa.util.misc import *
+from sfa.util.namespace import *
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
-from sfa.util.genitable import *
+from sfa.util.table import SfaTable
 from sfa.trust.certificate import Keypair
 
 class get_key(Method):
@@ -36,7 +36,7 @@ class get_key(Method):
         node = nodes[0]
        
         # look up the sfa record
-        table = GeniTable()
+        table = SfaTable()
         records = table.findObjects({'type': 'node', 'pointer': node['node_id']})
         if not records:
             raise RecordNotFound("pointer:" + str(node['node_id']))  
@@ -54,16 +54,32 @@ class get_key(Method):
         table.update(record)
   
         # attempt the scp the key
-        # this will only work for planetlab based compoenents
-        (fd, filename) = tempfile.mkstemp() 
-        pkey.save_to_file(filename)
+        # and gid onto the node
+        # this will only work for planetlab based components
+        (kfd, key_filename) = tempfile.mkstemp() 
+        (gfd, gid_filename) = tempfile.mkstemp() 
+        pkey.save_to_file(key_filename)
+        gid_object.save_to_file(gid_filename, save_parents=True)
         host = node['hostname']
-        dest="/etc/sfa/nodekey.key" 
-        identity = "/etc/planetlab/root_ssh_key.rsa"
-        scp_command = "/usr/bin/scp -i %(identity)s %(filename)s root@%(host)s:%(dest)s" % locals()
-        (status, output) = commands.getstatusoutput(scp_command)
-        if status:
-            raise Exception, output
-        os.unlink(filename)
+        key_dest="/etc/sfa/node.key"
+        gid_dest="/etc/sfa/node.gid" 
+        scp = "/usr/bin/scp" 
+        identity = "/etc/sfa/root_ssh_key"
+        scp_options=" -i %(identity)s " % locals()
+        scp_options+="-o StrictHostKeyChecking=no " % locals()
+        scp_key_command="%(scp)s %(scp_options)s %(key_filename)s root@%(host)s:%(key_dest)s" %\
+                         locals()
+        scp_gid_command="%(scp)s %(scp_options)s %(gid_filename)s root@%(host)s:%(gid_dest)s" %\
+                         locals()    
+
+        all_commands = [scp_key_command, scp_gid_command]
+        
+        for command in all_commands:
+            (status, output) = commands.getstatusoutput(command)
+            if status:
+                raise Exception, output
+
+        for filename in [key_filename, gid_filename]:
+            os.unlink(filename)
 
         return 1