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