593de28fa74f7892c2e7587185a393beab69d15c
[sfa.git] / sfa / methods / Delete.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 Delete(Method):
8     """
9     Remove the slice or slivers and free the allocated resources        
10
11     @param xrns human readable name of slice to instantiate (hrn or urn)
12     @param creds 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(type([str]), "Human readable name of slice to delete (hrn or urn)"),
20         Parameter(type([dict]), "Credentials"),
21         Parameter(dict, "options"),
22         ]
23
24     returns = Parameter(int, "1 if successful")
25     
26     def call(self, xrns, creds, options):
27         valid_creds = self.api.auth.checkCredentialsSpeaksFor(creds, 'deletesliver', xrns,
28                                                               check_sliver_callback = self.api.driver.check_sliver_credentials,
29                                                               options=options)
30
31         #log the call
32         origin_hrn = Credential(cred=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, xrns, self.name))
34
35         return self.api.manager.Delete(self.api, xrns, creds, options)