* tried to put some sense in the way things get logged, at least on server-side for now
[sfa.git] / sfa / methods / Register.py
1 ### $Id: register.py 16477 2010-01-05 16:31:37Z thierry $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/register.py $
3
4 from sfa.trust.certificate import Keypair, convert_public_key
5 from sfa.trust.gid import *
6 from sfa.util.faults import *
7 from sfa.util.method import Method
8 from sfa.util.parameter import Parameter, Mixed
9 from sfa.util.record import SfaRecord
10 from sfa.trust.auth import Auth
11 from sfa.trust.gid import create_uuid
12 from sfa.trust.credential import Credential
13
14 class Register(Method):
15     """
16     Register an object with the registry. In addition to being stored in the
17     SFA database, the appropriate records will also be created in the
18     PLC databases
19     
20     @param cred credential string
21     @param record_dict dictionary containing record fields
22     
23     @return gid string representation
24     """
25
26     interfaces = ['registry']
27     
28     accepts = [
29         Parameter(dict, "Record dictionary containing record fields"),
30         Mixed(Parameter(str, "Credential string"),
31               Parameter(type([str]), "List of credentials")),
32         ]
33
34     returns = Parameter(int, "String representation of gid object")
35     
36     def call(self, record, creds):
37         
38         valid_creds = self.api.auth.checkCredentials(creds, 'register')
39
40         #log the call
41         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
42
43         hrn = None
44         if 'hrn' in record:
45             hrn = record['hrn']
46         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
47         
48         manager = self.api.get_interface_manager()
49
50         return manager.register(self.api, record)