more consistency between API method names and corresponding manager implementation
[sfa.git] / sfa / methods / GetTicket.py
1 from sfa.util.xrn import urn_to_hrn
2 from sfa.util.method import Method
3 from sfa.util.parameter import Parameter, Mixed
4 from sfa.util.sfatablesRuntime import run_sfatables
5
6 from sfa.trust.credential import Credential
7
8 class GetTicket(Method):
9     """
10     Retrieve a ticket. This operation is currently implemented on PLC
11     only (see SFA, engineering decisions); it is not implemented on
12     components.
13     
14     The ticket is filled in with information from the PLC database. This
15     information includes resources, and attributes such as user keys and
16     initscripts.
17     
18     @param cred credential string
19     @param name name of the slice to retrieve a ticket for (hrn or urn)
20     @param rspec resource specification dictionary
21     
22     @return the string representation of a ticket object
23     """
24
25     interfaces = ['aggregate', 'slicemgr']
26     
27     accepts = [
28         Parameter(str, "Human readable name of slice to retrive a ticket for (hrn or urn)"),
29         Mixed(Parameter(str, "Credential string"),
30               Parameter(type([str]), "List of credentials")),
31         Parameter(str, "Resource specification (rspec)"),
32         Parameter(type([]), "List of user information")  
33         ]
34
35     returns = Parameter(str, "String representation of a ticket object")
36     
37     def call(self, xrn, creds, rspec, users):
38         hrn, type = urn_to_hrn(xrn)
39         # Find the valid credentials
40         valid_creds = self.api.auth.checkCredentials(creds, 'getticket', hrn)
41         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn() 
42
43         #log the call
44         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
45
46         # filter rspec through sfatables
47         if self.api.interface in ['aggregate']:
48             chain_name = 'OUTGOING'
49         elif self.api.interface in ['slicemgr']:
50             chain_name = 'FORWARD-OUTGOING'
51         rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
52         
53         # remove nodes that are not available at this interface from the rspec
54         return self.api.manager.GetTicket(self.api, xrn, creds, rspec, users)
55