2to3 -f has_key
[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         Parameter(type([str]), "List of URNs"),
24         Mixed(Parameter(str, "Credential string"), 
25               Parameter(type([str]), "List of credentials")),
26         Parameter(dict, "Options")
27         ]
28     returns = Parameter(str, "List of resources")
29
30     def call(self, urns, creds, options):
31         self.api.logger.info("interface: %s\tmethod-name: %s" % (self.api.interface, self.name))
32        
33         # client must specify a version
34         if not options.get('geni_rspec_version'):
35             if options.get('rspec_version'):
36                 options['geni_rspec_version'] = options['rspec_version']
37             else:
38                 raise SfaInvalidArgument('Must specify an rspec version option. geni_rspec_version cannot be null')
39         valid_creds  = self.api.auth.checkCredentialsSpeaksFor(
40             creds, 'listnodes', urns, 
41             check_sliver_callback = self.api.driver.check_sliver_credentials,
42             options=options)
43
44         # get hrn of the original caller 
45         origin_hrn = options.get('origin_hrn', None)
46         if not origin_hrn:
47             origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn()
48         desc = self.api.manager.Describe(self.api, creds, urns, options)
49
50         # filter rspec through sfatables 
51         if self.api.interface in ['aggregate']:
52             chain_name = 'OUTGOING'
53         elif self.api.interface in ['slicemgr']: 
54             chain_name = 'FORWARD-OUTGOING'
55         self.api.logger.debug("ListResources: sfatables on chain %s"%chain_name)
56         desc['geni_rspec'] = run_sfatables(chain_name, '', origin_hrn, desc['geni_rspec']) 
57  
58         if 'geni_compressed' in options and options['geni_compressed'] == True:
59             desc['geni_rspec'] = zlib.compress(desc['geni_rspec']).encode('base64')
60
61         return desc  
62     
63