merging with geni-api branch
[sfa.git] / sfa / methods / Shutdown.py
1 from sfa.util.faults import *
2 from sfa.util.namespace import *
3 from sfa.util.method import Method
4 from sfa.util.parameter import Parameter
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 = ['geni_am']
16     accepts = [
17         Parameter(str, "Slice URN"),
18         Parameter(type([str]), "List of credentials"),
19         ]
20     returns = Parameter(bool, "Success or Failure")
21
22     def call(self, slice_xrn, creds):
23         hrn, type = urn_to_hrn(slice_xrn)
24
25         self.api.logger.info("interface: %s\ttarget-hrn: %s\tcaller-creds: %s\tmethod-name: %s"%(self.api.interface, hrn, creds, self.name))
26
27         # Find the valid credentials
28         ValidCreds = self.api.auth.checkCredentials(creds, 'shutdown', hrn)
29
30         manager_base = 'sfa.managers'
31
32         if self.api.interface in ['geni_am']:
33             mgr_type = self.api.config.SFA_GENI_AGGREGATE_TYPE
34             manager_module = manager_base + ".geni_am_%s" % mgr_type
35             manager = __import__(manager_module, fromlist=[manager_base])
36             return manager.Shutdown(self.api, slice_xrn, ValidCreds)
37
38         return ''
39