b694bc8a325a915921217bde8ba072cf89bb8960
[sfa.git] / sfa / methods / Resolve.py
1 from sfa.util.faults import *
2 from sfa.util.namespace import *
3 from sfa.util.method import Method
4 from sfa.util.parameter import Parameter
5
6
7 class Resolve(Method):
8     """
9     Lookup a URN and return information about the corresponding object.
10     @param slice_urn (string) URN of slice to renew
11     @param credentials ([string]) of credentials
12     
13     """
14     interfaces = ['registry']
15     accepts = [
16         Parameter(str, "URN"),
17         Parameter(type([str]), "List of credentials"),
18         ]
19     returns = Parameter(bool, "Success or Failure")
20
21     def call(self, xrn, creds):
22         for cred in creds:
23             try:
24                 self.api.auth.check(cred, 'resolve')
25                 found = True
26                 break
27             except:
28                 continue
29             
30         if not found:
31             raise InsufficientRights('Resolve: Credentials either did not verify, were no longer valid, or did not have appropriate privileges')
32         
33
34         manager_base = 'sfa.managers'
35
36         if self.api.interface in ['registry']:
37             mgr_type = self.api.config.SFA_REGISTRY_TYPE
38             manager_module = manager_base + ".registry_manager_%s" % mgr_type
39             manager = __import__(manager_module, fromlist=[manager_base])
40             return manager.Resolve(self.api, xrn, creds)
41                
42         return {}