trimmed useless imports, unstarred all imports
[sfa.git] / sfa / methods / Start.py
1 from sfa.util.xrn import urn_to_hrn
2 from sfa.util.method import Method
3 from sfa.util.parameter import Parameter, Mixed
4 from sfa.trust.credential import Credential
5
6 class Start(Method):
7     """
8     Start the specified slice      
9
10     @param xrn human readable name of slice to instantiate (hrn or urn)
11     @param cred credential string specifying the rights of the caller
12     @return 1 is successful, faults otherwise  
13     """
14
15     interfaces = ['aggregate', 'slicemgr', 'component']
16     
17     accepts = [
18         Parameter(str, "Human readable name of slice to start (hrn or urn)"),
19         Mixed(Parameter(str, "Credential string"),
20               Parameter(type([str]), "List of credentials")),
21         ]
22
23     returns = Parameter(int, "1 if successful")
24     
25     def call(self, xrn, creds):
26         hrn, type = urn_to_hrn(xrn)
27         valid_creds = self.api.auth.checkCredentials(creds, 'startslice', hrn)
28
29         #log the call
30         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
31         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
32
33         manager = self.api.get_interface_manager() 
34         manager.start_slice(self.api, xrn, creds)
35  
36         return 1