- def get_ticket(self, options, args):
- """
- get a ticket for the specified slice
- """
- server = self.sliceapi()
- # slice urn
- slice_hrn, rspec_path = args[0], args[1]
- slice_urn = hrn_to_urn(slice_hrn, 'slice')
- # creds
- slice_cred = self.slice_credential_string(slice_hrn)
- creds = [slice_cred]
- if options.delegate:
- delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
- creds.append(delegated_cred)
- # rspec
- rspec_file = self.get_rspec_file(rspec_path)
- rspec = open(rspec_file).read()
- # options and call_id when supported
- api_options = {}
- api_options['call_id']=unique_call_id()
- # get ticket at the server
- ticket_string = server.GetTicket(slice_urn, creds, rspec, *self.ois(server,api_options))
- # save
- file = os.path.join(self.options.sfi_dir, get_leaf(slice_hrn) + ".ticket")
- self.logger.info("writing ticket to %s"%file)
- ticket = SfaTicket(string=ticket_string)
- ticket.save_to_file(filename=file, save_parents=True)
-
- def redeem_ticket(self, options, args):
- """
- Connects to nodes in a slice and redeems a ticket
-(slice hrn is retrieved from the ticket)
- """
- 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()
- ticket_string = ticket.save_to_string(save_parents=True)
-
- slice_hrn = ticket.gidObject.get_hrn()
- slice_urn = hrn_to_urn(slice_hrn, 'slice')
- #slice_hrn = ticket.attributes['slivers'][0]['hrn']
- slice_cred = self.slice_credential_string(slice_hrn)
-
- # 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())
- cm_url="http://%s:%s/"%(hostname,CM_PORT)
- server = SfaServerProxy(cm_url, self.private_key, self.my_gid)
- server = self.server_proxy(hostname, CM_PORT, self.private_key,
- timeout=self.options.timeout, verbose=self.options.debug)
- server.RedeemTicket(ticket_string, slice_cred)
- self.logger.info("Success")
- except socket.gaierror:
- self.logger.error("redeem_ticket failed on %s: Component Manager not accepting requests"%hostname)
- except Exception, e:
- self.logger.log_exc(e.message)
- return
-
- def create_gid(self, options, args):