removed another bunch of references to geni
[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 SfaRecord
10 from sfa.util.debug import log
11 from sfa.trust.auth import Auth
12 from sfa.trust.gid import create_uuid
13 from sfa.trust.credential import Credential
14
15 class register(Method):
16     """
17     Register an object with the registry. In addition to being stored in the
18     SFA database, the appropriate records will also be created in the
19     PLC databases
20     
21     @param cred credential string
22     @param record_dict dictionary containing record fields
23     
24     @return gid string representation
25     """
26
27     interfaces = ['registry']
28     
29     accepts = [
30         Parameter(str, "Credential string"),
31         Parameter(dict, "Record dictionary containing record fields")
32         ]
33
34     returns = Parameter(int, "String representation of gid object")
35     
36     def call(self, cred, record, origin_hrn=None):
37         user_cred = Credential(string=cred)
38
39         #log the call
40         if not origin_hrn:
41             origin_hrn = user_cred.get_gid_caller().get_hrn()
42         hrn = None
43         if 'hrn' in record:
44             hrn = record['hrn']
45         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
46         
47         # validate the cred
48         self.api.auth.check(cred, "register")
49
50         #send the call to the right manager
51         manager_base = 'sfa.managers'
52         mgr_type = self.api.config.SFA_REGISTRY_TYPE
53         manager_module = manager_base + ".registry_manager_%s" % mgr_type
54         manager = __import__(manager_module, fromlist=[manager_base])
55         return manager.register(self.api, record)