Exemplo n.º 1
0
Arquivo: sfi.py Projeto: planetlab/sfa
 def redeem_ticket(self, opts, args):
     ticket_file = args[0]
     
     # get slice hrn from the ticket
     # use this to get the right slice credential 
     ticket = SfaTicket(filename=ticket_file)
     ticket.decode()
     slice_hrn = ticket.gidObject.get_hrn()
     slice_urn = hrn_to_urn(slice_hrn, 'slice') 
     #slice_hrn = ticket.attributes['slivers'][0]['hrn']
     user_cred = self.get_user_cred()
     slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
     
     # get a list of node hostnames from the RSpec 
     tree = etree.parse(StringIO(ticket.rspec))
     root = tree.getroot()
     hostnames = root.xpath("./network/site/node/hostname/text()")
     
     # create an xmlrpc connection to the component manager at each of these
     # components and gall redeem_ticket
     connections = {}
     for hostname in hostnames:
         try:
             self.logger.info("Calling redeem_ticket at %(hostname)s " % locals())
             server = self.get_server(hostname, CM_PORT, self.key_file, \
                                      self.cert_file, self.options.debug)
             server.RedeemTicket(ticket.save_to_string(save_parents=True), slice_cred)
             self.logger.info("Success")
         except socket.gaierror:
             self.logger.error("redeem_ticket failed: Component Manager not accepting requests")
         except Exception, e:
             self.logger.log_exc(e.message)
Exemplo n.º 2
0
def redeem_ticket(api, ticket_string):
    ticket = SfaTicket(string=ticket_string)
    ticket.decode()
    hrn = ticket.attributes['slivers'][0]['hrn']
    slicename = PlXrn (hrn).pl_slicename()
    if not api.sliver_exists(slicename):
        raise SliverDoesNotExist(slicename)

    # convert ticket to format nm is used to
    nm_ticket = xmlrpclib.dumps((ticket.attributes,), methodresponse=True)
    api.nodemanager.AdminTicket(nm_ticket)