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