d57568fa7d2a24623342feee254a33e01f079664
[sfa.git] / sfa / methods / DeleteSliver.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 class DeleteSliver(Method):
7     """
8     Delete sliver from a slice.   Callers can check on the status of
9     the resources using SliverStatus.
10
11     @param slice_urn (string) URN of slice to allocate to
12     @param credentials ([string]) of credentials
13     
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         # Validate that at least one of the credentials is good enough
28         found = False
29         for cred in creds:
30             try:
31                 self.api.auth.check(cred, 'deleteslice')
32                 found = True
33                 break
34             except:
35                 continue
36             
37         if not found:
38             raise InsufficientRights('DeleteSliver: Credentials either did not verify, were no longer valid, or did not have appropriate privileges')
39             
40         
41         manager_base = 'sfa.managers'
42
43         if self.api.interface in ['geni_am']:
44             mgr_type = self.api.config.SFA_GENI_AGGREGATE_TYPE
45             manager_module = manager_base + ".geni_am_%s" % mgr_type
46             manager = __import__(manager_module, fromlist=[manager_base])
47             return manager.DeleteSliver(self.api, slice_xrn, creds)
48
49         return ''
50