request hash argument is optional for now
[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         Mixed(Parameter(str, "Request hash"),
28               Parameter(None, "Request hash not specified"))
29         ]
30
31     returns = Parameter(int, "1 if successful")
32     
33     def call(self, cred, hrn, request_hash=None, caller_cred=None):
34        
35         if caller_cred==None:
36             caller_cred=cred
37         #log the call
38         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))
39
40         # This cred will be an slice cred, not a user, so we cant use it to
41         # authenticate the caller's request_hash. Let just get the caller's gid
42         # from the cred and authenticate using that
43         client_gid = Credential(string=cred).get_gid_caller()
44         client_gid_str = client_gid.save_to_string(save_parents=True)
45         self.api.auth.authenticateGid(client_gid_str, [cred, hrn], request_hash)
46         self.api.auth.check(cred, 'deleteslice')
47         slices = Slices(self.api, caller_cred=caller_cred)
48         slices.delete_slice(hrn)
49         return 1