X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fmethods%2Fget_key.py;h=1195d53ac5cec31df3ef1ce13a651ff96249f455;hb=29df906cd2d154a3b90fcb1b7025f3fc1bb577fe;hp=27bb135398475cd6b192348214770219e35357e5;hpb=c725b84ed537ebc6fa6c001dc68b1ef564411a1a;p=sfa.git diff --git a/sfa/methods/get_key.py b/sfa/methods/get_key.py index 27bb1353..1195d53a 100644 --- a/sfa/methods/get_key.py +++ b/sfa/methods/get_key.py @@ -1,15 +1,13 @@ -### $Id: $ -### $URL: $ import os import tempfile import commands -from sfa.util.faults import * -from sfa.util.misc import * +from sfa.util.faults import NonExistingRecord, RecordNotFound +from sfa.util.xrn import hrn_to_urn 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.parameter import Parameter +from sfa.util.table import SfaTable from sfa.trust.certificate import Keypair +from sfa.trust.gid import create_uuid class get_key(Method): """ @@ -24,19 +22,19 @@ class get_key(Method): returns = Parameter(int, "1 if successful, faults otherwise") def call(self): - # verify that the callers's ip address exist in the db and is an inteface + # verify that the callers's ip address exist in the db and is an interface # for a node in the db (ip, port) = self.api.remote_addr - interfaces = self.api.plshell.GetInterfaces(self.api.plauth, {'ip': ip}, ['node_id']) + interfaces = self.api.driver.GetInterfaces({'ip': ip}, ['node_id']) if not interfaces: raise NonExistingRecord("no such ip %(ip)s" % locals()) - nodes = self.api.plshell.GetNodes(self.api.plauth, [interfaces[0]['node_id']], ['node_id', 'hostname']) + nodes = self.api.driver.GetNodes([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() + table = SfaTable() records = table.findObjects({'type': 'node', 'pointer': node['node_id']}) if not records: raise RecordNotFound("pointer:" + str(node['node_id'])) @@ -45,7 +43,8 @@ class get_key(Method): # generate a new keypair and gid uuid = create_uuid() pkey = Keypair(create=True) - gid_object = self.api.auth.hierarchy.create_gid(record['hrn'], uuid, pkey) + urn = hrn_to_urn(record['hrn'], record['type']) + gid_object = self.api.auth.hierarchy.create_gid(urn, uuid, pkey) gid = gid_object.save_to_string(save_parents=True) record['gid'] = gid record.set_gid(gid) @@ -55,21 +54,22 @@ class get_key(Method): # attempt the scp the key # and gid onto the node - # this will only work for planetlab based compoenents + # 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_str = gid.save_to_file(save_parents=True) + gid_object.save_to_file(gid_filename, save_parents=True) host = node['hostname'] key_dest="/etc/sfa/node.key" gid_dest="/etc/sfa/node.gid" scp = "/usr/bin/scp" - identity = "/etc/planetlab/root_ssh_key.rsa" - scp_options=" -i %(identity)s %(filename)s " % locals() + #identity = "/etc/planetlab/root_ssh_key.rsa" + 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 root@%(host)s:%(key_dest)s" %\ + 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 root@%(host)s:%(gid_dest)s" %\ + 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]