920425629b05b1b92a384a7dc5e12eed6d877350
[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
8 class Delete(Method):
9     """
10     Remove the slice or slivers and free the allocated resources        
11
12     @param xrns human readable name of slice to instantiate (hrn or urn)
13     @param creds 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(
21             type([str]), "Human readable name of slice to delete (hrn or urn)"),
22         Parameter(type([dict]), "Credentials"),
23         Parameter(dict, "options"),
24     ]
25
26     returns = Parameter(int, "1 if successful")
27
28     def call(self, xrns, creds, options):
29         valid_creds = self.api.auth.checkCredentialsSpeaksFor(creds, 'deletesliver', xrns,
30                                                               check_sliver_callback=self.api.driver.check_sliver_credentials,
31                                                               options=options)
32
33         # log the call
34         origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn()
35         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
36                              (self.api.interface, origin_hrn, xrns, self.name))
37
38         return self.api.manager.Delete(self.api, xrns, creds, options)