Exemplo n.º 1
0
 def GetTicket(self, api, xrn, creds, rspec, users, options):
     slice_hrn, type = urn_to_hrn(xrn)
     # get the netspecs contained within the clients rspec
     aggregate_rspecs = {}
     tree= etree.parse(StringIO(rspec))
     elements = tree.findall('./network')
     for element in elements:
         aggregate_hrn = element.values()[0]
         aggregate_rspecs[aggregate_hrn] = rspec 
 
     # get the callers hrn
     valid_cred = api.auth.checkCredentials(creds, 'getticket', slice_hrn)[0]
     caller_hrn = Credential(string=valid_cred).get_gid_caller().get_hrn()
 
     # attempt to use delegated credential first
     cred = api.getDelegatedCredential(creds)
     if not cred:
         cred = api.getCredential() 
     threads = ThreadManager()
     for (aggregate, aggregate_rspec) in aggregate_rspecs.iteritems():
         # xxx sounds like using call_id here would be safer
         # prevent infinite loop. Dont send request back to caller
         # unless the caller is the aggregate's SM
         if caller_hrn == aggregate and aggregate != api.hrn:
             continue
         
         interface = api.aggregates[aggregate]
         server = api.server_proxy(interface, cred)
         threads.run(server.GetTicket, xrn, [cred], aggregate_rspec, users, options)
 
     results = threads.get_results()
     
     # gather information from each ticket 
     rspec = None
     initscripts = []
     slivers = [] 
     object_gid = None  
     for result in results:
         agg_ticket = SfaTicket(string=result)
         attrs = agg_ticket.get_attributes()
         if not object_gid:
             object_gid = agg_ticket.get_gid_object()
         if not rspec:
             rspec = RSpec(agg_ticket.get_rspec())
         else:
             rspec.version.merge(agg_ticket.get_rspec())
         initscripts.extend(attrs.get('initscripts', [])) 
         slivers.extend(attrs.get('slivers', [])) 
     
     # merge info
     attributes = {'initscripts': initscripts,
                  'slivers': slivers}
     
     # create a new ticket
     ticket = SfaTicket(subject = slice_hrn)
     ticket.set_gid_caller(api.auth.client_gid)
     ticket.set_issuer(key=api.key, subject=api.hrn)
     ticket.set_gid_object(object_gid)
     ticket.set_pubkey(object_gid.get_pubkey())
     #new_ticket.set_parent(api.auth.hierarchy.get_auth_ticket(auth_hrn))
     ticket.set_attributes(attributes)
     ticket.set_rspec(rspec.toxml())
     ticket.encode()
     ticket.sign()          
     return ticket.save_to_string(save_parents=True)