c8216059010e26861b1fb8781461e3a44c0d03ce
[sfa.git] / sfa / methods / register.py
1 ### $Id$
2 ### $URL$
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 GeniRecord
10 from sfa.util.genitable import GeniTable
11 from sfa.util.debug import log
12 from sfa.trust.auth import Auth
13 from sfa.trust.gid import create_uuid
14 from sfa.trust.credential import Credential
15
16 class register(Method):
17     """
18     Register an object with the registry. In addition to being stored in the
19     Geni database, the appropriate records will also be created in the
20     PLC databases
21     
22     @param cred credential string
23     @param record_dict dictionary containing record fields
24     
25     @return gid string representation
26     """
27
28     interfaces = ['registry']
29     
30     accepts = [
31         Parameter(str, "Credential string"),
32         Parameter(dict, "Record dictionary containing record fields")
33         ]
34
35     returns = Parameter(int, "String representation of gid object")
36     
37     def call(self, cred, record, origin_hrn=None):
38         user_cred = Credential(string=cred)
39
40         #log the call
41         if not origin_hrn:
42             origin_hrn = user_cred.get_gid_caller().get_hrn()
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         # validate the cred
49         self.api.auth.check(cred, "register")
50
51         #send the call to the right manager
52         manager_base = 'sfa.managers'
53         mgr_type = self.api.config.SFA_REGISTRY_TYPE
54         manager_module = manager_base + ".registry_manager_%s" % mgr_type
55         manager = __import__(manager_module, fromlist=[manager_base])
56         return manager.register(self.api, record)