6 from sfa.util.faults import *
7 from sfa.util.misc import *
8 from sfa.util.method import Method
9 from sfa.util.parameter import Parameter, Mixed
10 from sfa.trust.auth import Auth
12 class get_key(Method):
14 Generate a new keypair and gid for requesting caller (component).
15 @return 1 If successful
18 interfaces = ['registry']
22 returns = Parameter(int, "1 if successful, faults otherwise")
25 # verify that the callers's ip address exist in the db and is an inteface
26 # for a node in the db
27 (ip, port) = self.api.remote_addr
28 interfaces = self.api.plshell(self.api.plauth, {'ip': ip}, ['node_id'])
30 raise NonExistingRecord("no such ip %(ip)s" % locals())
31 nodes = self.api.plshell(self.api.plauth, [interfaces[0]['node_id']], ['node_id', 'hostname'])
33 raise NonExistingRecord("no such node using ip %(ip)s" % locals())
36 # look up the sfa record
38 records = table.find({'type': 'node', 'pointer': node['node_id']})
40 raise RecordNotFound("pointer:" + str(node['node_id']))
43 # generate a new keypair and gid
45 pkey = Keypair(create=True)
46 gid_object = self.api.auth.hierarchy.create_gid(record['hrn'], uuid, pkey)
47 gid = gid_object.save_to_string(save_parents=True)
54 # attempt the scp the key
55 # this will only work for planetlab based compoenents
56 (fd, filename) = tempfile.mkstemp()
57 pkey.save_to_file(filename)
58 host = node['hostname']
59 dest="/etc/sfa/nodekey.key"
60 identity = "/etc/planetlab/root_ssh_key.pub"
61 scp_command = "scp -i %(identity)s %(filename)s root@%(host)s:%(dest)s" % locals()
62 (status, output) = commands(scp_command)
64 raise Exception, output