fix typos, syntax errors, name errors
[sfa.git] / sfa / methods / get_ticket.py
1 ### $Id$
2 ### $URL$
3 import time
4 from sfa.util.faults import *
5 from sfa.util.method import Method
6 from sfa.util.parameter import Parameter, Mixed
7 from sfa.trust.auth import Auth
8 from sfa.util.config import Config
9 from sfa.trust.credential import Credential
10 from sfa.util.genitable import GeniTable
11 from sfa.util.sfaticket import SfaTicket
12 from sfa.plc.slices import Slices
13 from sfatables.runtime import SFATablesRules
14
15 class get_ticket(Method):
16     """
17     Retrieve a ticket. This operation is currently implemented on PLC
18     only (see SFA, engineering decisions); it is not implemented on
19     components.
20     
21     The ticket is filled in with information from the PLC database. This
22     information includes resources, and attributes such as user keys and
23     initscripts.
24     
25     @param cred credential string
26     @param name name of the slice to retrieve a ticket for
27     @param rspec resource specification dictionary
28     
29     @return the string representation of a ticket object
30     """
31
32     interfaces = ['aggregate', 'slicemgr']
33     
34     accepts = [
35         Parameter(str, "Credential string"),
36         Parameter(str, "Human readable name of slice to retrive a ticket for (hrn)"),
37         Parameter(str, "Resource specification (rspec)"),
38         Mixed(Parameter(str, "Request hash"),
39               Parameter(None, "Request hash not specified"))
40         ]
41
42     returns = Parameter(str, "String represeneation of a ticket object")
43     
44     def call(self, cred, hrn, rspec, request_hash=None):
45         self.api.auth.authenticateCred(cred, [cred, hrn, rspec], request_hash)
46         self.api.auth.check(cred, "getticket")
47         self.api.auth.verify_object_belongs_to_me(hrn)
48         self.api.auth.verify_object_permission(hrn)
49    
50         # set the right outgoing rules
51         if self.api.interface in ['aggregate']:
52             outgoing_rules = SFATablesRules('OUTGOING')
53         elif self.api.interface in ['slicemgr']:
54             outgoing_rules = SFATablesRules('FORWARD-OUTGOING')
55
56         # Filter the incoming rspec using sfatables
57         incoming_rules = SFATablesRules('INCOMING')
58         #incoming_rules.set_slice(hrn) # This is a temporary kludge. Eventually, we'd like to fetch the context requested by the match/target
59         contexts = incoming_rules.contexts
60         caller_hrn = Credential(string=cred).get_gid_caller().get_hrn()
61         request_context = rspec_manager.fetch_context(hrn, caller_hrn, contexts)
62         incoming_rules.set_context(request_context)
63         rspec = incoming_rules.apply(rspec)
64  
65         # send the call to the right manager
66         manager_base = 'sfa.managers'
67         if self.api.interface in ['aggregate']:
68             mgr_type = self.api.config.SFA_AGGREGATE_TYPE
69             manager_module = manager_base + ".aggregate_manager_%s" % mgr_type
70             manager = __import__(manager_module, fromlist=[manager_base])
71             ticket = manager.get_ticket(self.api, hrn, rspec)
72         elif self.api.interface in ['slicemgr']:
73             mgr_type = self.api.config.SFA_SM_TYPE
74             manager_module = manager_base + ".slice_manager_%s" % mgr_type
75             manager = __import__(manager_module, fromlist=[manager_base])
76             ticket = manager.get_rspec(self.api, hrn, rspec)
77         
78         return ticket
79