5 from sfa.util.faults import *
6 from sfa.util.misc import *
7 from sfa.util.method import Method
8 from sfa.util.parameter import Parameter, Mixed
9 from sfa.trust.auth import Auth
11 class request_key(Method):
13 Generate a new keypair and gid for requesting caller (component).
14 @return 1 If successful
17 interfaces = ['registry']
21 returns = Parameter(int, "1 if successful, faults otherwise")
24 # verify that the callers's ip address exist in the db and is an inteface
25 # for a node in the db
26 (ip, port) = self.api.remote_addr
27 interfaces = self.api.plshell(self.api.plauth, {'ip': ip}, ['node_id'])i
29 raise NonExistingRecord("no such ip %(ip)s" % locals())
30 nodes = self.api.plshell(self.api.plauth, [interfaces[0]['node_id']], ['node_id', 'hostname'])
32 raise NonExistingRecord("no such node using ip %(ip)s" % locals())
35 # look up the sfa record
37 records = table.find({'type': 'node', 'pointer': node['node_id']})
39 raise raise RecordNotFound("pointer:" + str(node['node_id']))
42 # generate a new keypair and gid
44 pkey = Keypair(create=True)
45 gid_object = self.api.auth.hierarchy.create_gid(record['hrn'], uuid, pkey)
46 gid = gid_object.save_to_string(save_parents=True)
53 # attempt the scp the key
54 # this will only work for planetlab based compoenents
55 (fd, filename) = tempfile.mkstemp()
56 pkey.save_to_file(filename)
57 host = node['hostname']
58 dest="/etc/sfa/%s.key" % record['hrn']
59 identity = "/etc/planetlab/root_ssh_key.pub"
60 os.system("scp -i %(identity)s %(filename)s root@%(host)s:%(dest)s" % locals()