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