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')
37 self.api.auth.check_ticket(ticket)
39 ticket = SfaTicket(string=ticket)
41 hrn = ticket.attributes['slivers'][0]['hrn']
42 slicename = hrn_to_pl_slicename(hrn)
43 if not self.api.sliver_exists(slicename):
44 raise SliverDoesNotExist(slicename)
46 # convert ticket to format nm is used to
47 nm_ticket = xmlrpclib.dumps((ticket.attributes,), methodresponse=True)
48 self.api.nodemanager.AdminTicket(nm_ticket)