a little nicer wrt pep8
[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.util.sfalogging import logger
4
5 from sfa.storage.parameter import Parameter, Mixed
6 from sfa.trust.auth import Auth
7 from sfa.trust.credential import Credential
8
9
10 class Delete(Method):
11     """
12     Remove the slice or slivers and free the allocated resources
13
14     @param xrns human readable name of slice to instantiate (hrn or urn)
15     @param creds credential string specifying the rights of the caller
16     @return 1 is successful, faults otherwise
17     """
18
19     interfaces = ['aggregate']
20
21     accepts = [
22         Parameter(
23             type([str]), "Human readable name of slice to delete (hrn or urn)"),
24         Parameter(type([dict]), "Credentials"),
25         Parameter(dict, "options"),
26     ]
27
28     returns = Parameter(int, "1 if successful")
29
30     def call(self, xrns, creds, options):
31         valid_creds = self.api.auth.checkCredentialsSpeaksFor(
32             creds, 'deletesliver', xrns,
33             check_sliver_callback=self.api.driver.check_sliver_credentials,
34             options=options)
35
36         # log the call
37         origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn()
38         logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
39                     (self.api.interface, origin_hrn, xrns, self.name))
40
41         return self.api.manager.Delete(self.api, xrns, creds, options)