namespace module is gone, plxrn provides PL-specific translations
[sfa.git] / sfa / methods / ListResources.py
1 import sys
2 import zlib
3
4 from sfa.util.faults import *
5 from sfa.util.xrn import urn_to_hrn
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
8 from sfa.trust.credential import Credential
9 from sfa.util.sfatablesRuntime import run_sfatables
10
11 class ListResources(Method):
12     """
13     Returns information about available resources or resources allocated to this slice
14     @param credential list
15     @param options dictionary
16     @return string
17     """
18     interfaces = ['aggregate', 'slicemgr']
19     accepts = [
20         Mixed(Parameter(str, "Credential string"), 
21               Parameter(type([str]), "List of credentials")),
22         Parameter(dict, "Options")
23         ]
24     returns = Parameter(str, "List of resources")
25
26     def call(self, creds, options):
27         self.api.logger.info("interface: %s\tmethod-name: %s" % (self.api.interface, self.name))
28         
29         # get slice's hrn from options    
30         xrn = options.get('geni_slice_urn', '')
31         hrn, _ = urn_to_hrn(xrn)
32
33         # Find the valid credentials
34         valid_creds = self.api.auth.checkCredentials(creds, 'listnodes', hrn)
35
36         # get hrn of the original caller 
37         origin_hrn = options.get('origin_hrn', None)
38         if not origin_hrn:
39             origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
40         # get manager for this interface    
41         manager = self.api.get_interface_manager()
42         rspec = manager.get_rspec(self.api, creds, options)
43
44         # filter rspec through sfatables 
45         if self.api.interface in ['aggregate']:
46             chain_name = 'OUTGOING'
47         elif self.api.interface in ['slicemgr']: 
48             chain_name = 'FORWARD-OUTGOING'
49         filtered_rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec) 
50  
51         if options.has_key('geni_compressed') and options['geni_compressed'] == True:
52             filtered_rspec = zlib.compress(filtered_rspec).encode('base64')
53
54         return filtered_rspec  
55     
56