a little nicer wrt pep8
[sfa.git] / sfa / methods / Shutdown.py
1 from sfa.storage.parameter import Parameter
2 from sfa.trust.credential import Credential
3 from sfa.util.method import Method
4 from sfa.util.sfalogging import logger
5
6
7 class Shutdown(Method):
8     """
9     Perform an emergency shut down of a sliver. This operation is intended for administrative use.
10     The sliver is shut down but remains available for further forensics.
11
12     @param slice_urn (string) URN of slice to renew
13     @param credentials ([string]) of credentials
14     """
15     interfaces = ['aggregate']
16     accepts = [
17         Parameter(str, "Slice URN"),
18         Parameter(type([dict]), "Credentials"),
19     ]
20     returns = Parameter(bool, "Success or Failure")
21
22     def call(self, xrn, creds):
23
24         valid_creds = self.api.auth.checkCredentials(
25             creds, 'stopslice', xrn,
26             check_sliver_callback=self.api.driver.check_sliver_credentials)
27         # log the call
28         origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn()
29         logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
30                     (self.api.interface, origin_hrn, xrn, self.name))
31
32         return self.api.manager.Shutdown(self.api, xrn, creds)