1 ### $Id: reset_slice.py 15428 2009-10-23 15:28:03Z tmack $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfacomponent/methods/reset_slice.py $
4 from sfa.util.faults import *
5 from sfa.util.misc import *
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
9 class redeem_ticket(Method):
11 Reset the specified slice
13 @param cred credential string specifying the rights of the caller
15 @return 1 is successful, faults otherwise
18 interfaces = ['component']
21 Parameter(str, "Credential string representation of SFA credential"),
22 Parameter(str, "Ticket string representation of SFA ticket"),
23 Mixed(Parameter(str, "Request hash"),
24 Parameter(None, "Request hash not specified"))
27 returns = [Parameter(int, "1 if successful")]
29 def call(self, cred, ticket, request_hash=None):
30 # This cred will be an slice cred, not a user, so we cant use it to
31 # authenticate the caller's request_hash. Let just get the caller's gid
32 # from the cred and authenticate using that
33 client_gid = Credential(string=cred).get_gid_caller()
34 client_gid_str = client_gid.save_to_string(save_parents=True)
35 self.api.auth.authenticateGid(client_gid_str, [cred, hrn], request_hash)
36 self.api.auth.check(cred, 'redeemticket')
38 ticket = SfaTicket(string=ticket)
39 # XX we should verify the ticket, but we need the privste keys to do that
40 # maybe we should just pass the ticket to the authoriative registry to it
41 # verify the ticket for us
44 #self.api.registry.verify_ticket(ticket.save_to_string(save_parents=True))
47 hrn = ticket.attributes['slivers'][0]['hrn']
48 slicename = hrn_to_pl_slicename(hrn)
49 if not self.api.sliver_exists(slicename):
50 raise SliverDoesNotExist(slicename)
52 # convert ticket to format nm is used to
53 nm_ticket = xmlrpclib.dumps((ticket.attributes,), methodresponse=True)
54 self.api.nodemanager.AdminTicket(nm_ticket)