group db-related stuff in sfa/storage
[sfa.git] / sfa / methods / DeleteSliver.py
1 from sfa.util.xrn import urn_to_hrn
2 from sfa.util.method import Method
3 from sfa.storage.parameter import Parameter, Mixed
4 from sfa.trust.auth import Auth
5 from sfa.trust.credential import Credential
6
7 class DeleteSliver(Method):
8     """
9     Remove the slice from all nodes and free the allocated resources        
10
11     @param xrn human readable name of slice to instantiate (hrn or urn)
12     @param cred credential string specifying the rights of the caller
13     @return 1 is successful, faults otherwise  
14     """
15
16     interfaces = ['aggregate', 'slicemgr', 'component']
17     
18     accepts = [
19         Parameter(str, "Human readable name of slice to delete (hrn or urn)"),
20         Mixed(Parameter(str, "Credential string"),
21               Parameter(type([str]), "List of credentials")),
22         Parameter(dict, "options"),
23         ]
24
25     returns = Parameter(int, "1 if successful")
26     
27     def call(self, xrn, creds, options={}):
28         (hrn, type) = urn_to_hrn(xrn)
29         valid_creds = self.api.auth.checkCredentials(creds, 'deletesliver', 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.DeleteSliver(self.api, xrn, creds, options)
36  
37         return 1