e56793bfb3e459622e2413a04552ec72a923b980
[sfa.git] / sfa / methods / SliverStatus.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 SliverStatus(Method):
7     """
8     Get the status of a sliver
9     
10     @param slice_urn (string) URN of slice to allocate to
11     @param credentials ([string]) of credentials
12     
13     """
14     interfaces = ['geni_am']
15     accepts = [
16         Parameter(str, "Slice URN"),
17         Parameter(type([str]), "List of credentials"),
18         ]
19     returns = Parameter(bool, "Success or Failure")
20
21     def call(self, slice_xrn, creds):
22         hrn, type = urn_to_hrn(slice_xrn)
23
24         self.api.logger.info("interface: %s\ttarget-hrn: %s\tcaller-creds: %s\tmethod-name: %s"%(self.api.interface, hrn, creds, self.name))
25
26         # Validate that at least one of the credentials is good enough
27         found = False
28         for cred in creds:
29             try:
30                 self.api.auth.check(cred, 'sliverstatus')
31                 found = True
32                 break
33             except:
34                 continue
35             
36         if not found:
37             raise InsufficientRights('SliverStatus: Credentials either did not verify, were no longer valid, or did not have appropriate privileges')
38             
39         
40         manager_base = 'sfa.managers'
41
42         if self.api.interface in ['geni_am']:
43             mgr_type = self.api.config.SFA_GENI_AGGREGATE_TYPE
44             manager_module = manager_base + ".geni_am_%s" % mgr_type
45             manager = __import__(manager_module, fromlist=[manager_base])
46             return manager.SliverStatus(self.api, slice_xrn, creds)
47
48         return ''
49