initial checkin
[sfa.git] / sfacomponent / methods / stop_slice.py
1 ### $Id: stop_slice.py 15428 2009-10-23 15:28:03Z tmack $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/stop_slice.py $
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
10 class stop_slice(Method):
11     """
12     Stop the specified slice      
13
14     @param cred credential string specifying the rights of the caller
15     @param hrn human readable name of slice to instantiate
16     @return 1 is successful, faults otherwise  
17     """
18
19     interfaces = ['component']
20     
21     accepts = [
22         Parameter(str, "Credential string"),
23         Parameter(str, "Human readable name of slice to instantiate"),
24         Mixed(Parameter(str, "Request hash"),
25               Parameter(None, "Request hash not specified"))
26         ]
27
28     returns = Parameter(int, "1 if successful")
29     
30     def call(self, cred, hrn, request_hash=None):
31         # This cred will be an slice cred, not a user, so we cant use it to
32         # authenticate the caller's request_hash. Let just get the caller's gid
33         # from the cred and authenticate using that
34         client_gid = Credential(string=cred).get_gid_caller()
35         client_gid_str = client_gid.save_to_string(save_parents=True)
36         self.api.auth.authenticateGid(client_gid_str, [cred, hrn], request_hash)
37         self.api.auth.check(cred, 'stopslice')
38         self.api.nodemanager.Stop(hrn)
39         
40         return 1