add request_hash argumet to more method calls
[sfa.git] / sfa / methods / delete_slice.py
1 ### $Id$
2 ### $URL$
3
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
8 from sfa.trust.auth import Auth
9 from sfa.trust.credential import Credential
10
11 from sfa.plc.slices import Slices
12
13 class delete_slice(Method):
14     """
15     Remove the slice from all nodes.      
16
17     @param cred credential string specifying the rights of the caller
18     @param hrn human readable name specifying the slice to delete
19     @return 1 if successful, faults otherwise  
20     """
21
22     interfaces = ['aggregate', 'slicemgr']
23     
24     accepts = [
25         Parameter(str, "Credential string"),
26         Parameter(str, "Human readable name of slice to delete"),
27         Parameter(str, "Request hash")
28         ]
29
30     returns = Parameter(int, "1 if successful")
31     
32     def call(self, cred, hrn, request_hash, caller_cred=None):
33        
34         if caller_cred==None:
35             caller_cred=cred
36         #log the call
37         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, Credential(string=caller_cred).get_gid_caller().get_hrn(), hrn, self.name))
38
39         # This cred will be an slice cred, not a user, so we cant use it to
40         # authenticate the caller's request_hash. Let just get the caller's gid
41         # from the cred and authenticate using that
42         client_gid = Credential(string=cred).get_gid_caller()
43         client_gid_str = client_gid.save_to_string(save_parents=True)
44         self.api.auth.authenticateGid(client_gid_str, [cred, hrn], request_hash)
45         self.api.auth.check(cred, 'deleteslice')
46         slices = Slices(self.api, caller_cred=caller_cred)
47         slices.delete_slice(hrn)
48         return 1