Initial checkin
[sfa.git] / sfa / methods / Describe.py
1 import zlib
2
3 from sfa.util.xrn import urn_to_hrn
4 from sfa.util.method import Method
5 from sfa.util.sfatablesRuntime import run_sfatables
6 from sfa.util.faults import SfaInvalidArgument
7 from sfa.trust.credential import Credential
8
9 from sfa.storage.parameter import Parameter, Mixed
10
11 class Describe(Method):
12     """
13     Retrieve a manifest RSpec describing the resources contained by the 
14     named entities, e.g. a single slice or a set of the slivers in a 
15     slice. This listing and description should be sufficiently 
16     descriptive to allow experimenters to use the resources.    
17     @param credential list
18     @param options dictionary
19     @return dict
20     """
21     interfaces = ['aggregate', 'slicemgr']
22     accepts = [
23         Mixed(Parameter(str, "Credential string"), 
24               Parameter(type([str]), "List of credentials")),
25         Parameter(dict, "Options")
26         ]
27     returns = Parameter(str, "List of resources")
28
29     def call(self, creds, options):
30         self.api.logger.info("interface: %s\tmethod-name: %s" % (self.api.interface, self.name))
31        
32         # client must specify a version
33         if not options.get('geni_rspec_version'):
34             if options.get('rspec_version'):
35                 options['geni_rspec_version'] = options['rspec_version']
36             else:
37                 raise SfaInvalidArgument('Must specify an rspec version option. geni_rspec_version cannot be null')
38  
39         # Find the valid credentials
40         valid_creds = self.api.auth.checkCredentials(creds, 'listnodes')
41
42         # get hrn of the original caller 
43         origin_hrn = options.get('origin_hrn', None)
44         if not origin_hrn:
45             origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
46         rspec = self.api.manager.ListResources(self.api, creds, options)
47
48         # filter rspec through sfatables 
49         if self.api.interface in ['aggregate']:
50             chain_name = 'OUTGOING'
51         elif self.api.interface in ['slicemgr']: 
52             chain_name = 'FORWARD-OUTGOING'
53         self.api.logger.debug("ListResources: sfatables on chain %s"%chain_name)
54         filtered_rspec = run_sfatables(chain_name, '', origin_hrn, rspec) 
55  
56         if options.has_key('geni_compressed') and options['geni_compressed'] == True:
57             filtered_rspec = zlib.compress(filtered_rspec).encode('base64')
58
59         return filtered_rspec  
60     
61