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.genitable import GeniTable
9 from sfa.util.sfaticket import SfaTicket
10 from sfa.util.slices import Slices
11 from sfatables.runtime import SFATablesRules
13 class get_ticket(Method):
15 Retrieve a ticket. This operation is currently implemented on PLC
16 only (see SFA, engineering decisions); it is not implemented on
19 The ticket is filled in with information from the PLC database. This
20 information includes resources, and attributes such as user keys and
23 @param cred credential string
24 @param name name of the slice to retrieve a ticket for
25 @param rspec resource specification dictionary
27 @return the string representation of a ticket object
30 interfaces = ['registry', 'aggregate', 'slicemgr']
33 Parameter(str, "Credential string"),
34 Parameter(str, "Human readable name of slice to retrive a ticket for (hrn)"),
35 Parameter(str, "Resource specification (rspec)"),
36 Mixed(Parameter(str, "Request hash"),
37 Parameter(None, "Request hash not specified"))
40 returns = Parameter(str, "String represeneation of a ticket object")
42 def call(self, cred, hrn, rspec, request_hash=None):
43 self.api.auth.authenticateCred(cred, [cred, hrn, rspec], request_hash)
44 self.api.auth.check(cred, "getticket")
45 self.api.auth.verify_object_belongs_to_me(hrn)
46 self.api.auth.verify_object_permission(hrn)
50 records = table.findObjects({'hrn': hrn, 'type': 'slice'})
52 raise RecordNotFound(hrn)
54 object_gid = record.get_gid_object()
55 new_ticket = SfaTicket(subject = object_gid.get_subject())
56 new_ticket.set_gid_caller(self.client_gid)
57 new_ticket.set_gid_object(object_gid)
58 new_ticket.set_issuer(key=auth_info.get_pkey_object(), subject=auth_hrn)
59 new_ticket.set_pubkey(object_gid.get_pubkey())
61 # determine aggregate tyep
62 sfa_aggregate_type = Config().get_aggregate_rspec_type()
63 rspec_manager = __import__("sfa.rspecs.aggregates.rspec_manager_"+sfa_aggregate_type, fromlist = ["sfa.rspecs.aggregates"])
65 # Fukter the incoming rspec using sfatables
66 incoming_rules = SFATablesRules('INCOMING')
67 #incoming_rules.set_slice(hrn) # This is a temporary kludge. Eventually, we'd like to fetch the context requested by the match/target
68 contexts = incoming_rules.contexts
69 caller_hrn = Credential(string=caller_cred).get_gid_caller().get_hrn())
70 request_context = rspec_manager.fetch_context(hrn, caller_hrn, contexts)
71 incoming_rules.set_context(request_context)
72 rspec = incoming_rules.apply(requested_rspec)
75 slivers = Slices(self.api).get_slivers(hrn)
77 raise SliverDoesNotExist(hrn)
82 sliver['initscripts'] = initscripts
84 new_ticket.set_attributes(sliver)
85 new_ticket.set_rspec(rspec)
87 new_ticket.set_parent(self.api.auth.hierarchy.get_auth_ticket(auth_hrn))
92 return new_ticket.save_to_string(save_parents=True)