X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fmethods%2Fget_key.py;h=c641985b6b71f31e62e02859434b95e44c9852b7;hb=3d7237fa0b5f2b4a60cb97c7fb3b6aecfd94558a;hp=501bbc669f439b69fe4489782bc4de7170829752;hpb=2ced4b12a8730c70fd254f5cdb151b4e410b126a;p=sfa.git diff --git a/sfa/methods/get_key.py b/sfa/methods/get_key.py index 501bbc66..c641985b 100644 --- a/sfa/methods/get_key.py +++ b/sfa/methods/get_key.py @@ -2,13 +2,16 @@ ### $URL: $ 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.table import SfaTable +from sfa.trust.certificate import Keypair -class request_key(Method): +class get_key(Method): """ Generate a new keypair and gid for requesting caller (component). @return 1 If successful @@ -24,19 +27,19 @@ class request_key(Method): # verify that the callers's ip address exist in the db and is an inteface # for a node in the db (ip, port) = self.api.remote_addr - interfaces = self.api.plshell(self.api.plauth, {'ip': ip}, ['node_id']) + interfaces = self.api.plshell.GetInterfaces(self.api.plauth, {'ip': ip}, ['node_id']) if not interfaces: raise NonExistingRecord("no such ip %(ip)s" % locals()) - nodes = self.api.plshell(self.api.plauth, [interfaces[0]['node_id']], ['node_id', 'hostname']) + nodes = self.api.plshell.GetNodes(self.api.plauth, [interfaces[0]['node_id']], ['node_id', 'hostname']) if not nodes: raise NonExistingRecord("no such node using ip %(ip)s" % locals()) node = nodes[0] # look up the sfa record - table = GeniTable() - records = table.find({'type': 'node', 'pointer': node['node_id']}) + table = SfaTable() + records = table.findObjects({'type': 'node', 'pointer': node['node_id']}) if not records: - raise raise RecordNotFound("pointer:" + str(node['node_id'])) + raise RecordNotFound("pointer:" + str(node['node_id'])) record = records[0] # generate a new keypair and gid @@ -51,13 +54,32 @@ class request_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.pub" - os.system("scp -i %(identity)s %(filename)s root@%(host)s:%(dest)s" % locals() - os.remove(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