6930f1eb876a753b4dd877c61bf309f2bb19d3f3
[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
12 class Describe(Method):
13     """
14     Retrieve a manifest RSpec describing the resources contained by the 
15     named entities, e.g. a single slice or a set of the slivers in a 
16     slice. This listing and description should be sufficiently 
17     descriptive to allow experimenters to use the resources.    
18     @param credential list
19     @param options dictionary
20     @return dict
21     """
22     interfaces = ['aggregate', 'slicemgr']
23     accepts = [
24         Parameter(type([str]), "List of URNs"),
25         Mixed(Parameter(str, "Credential string"),
26               Parameter(type([str]), "List of credentials")),
27         Parameter(dict, "Options")
28     ]
29     returns = Parameter(str, "List of resources")
30
31     def call(self, urns, creds, options):
32         self.api.logger.info("interface: %s\tmethod-name: %s" %
33                              (self.api.interface, self.name))
34
35         # client must specify a version
36         if not options.get('geni_rspec_version'):
37             if options.get('rspec_version'):
38                 options['geni_rspec_version'] = options['rspec_version']
39             else:
40                 raise SfaInvalidArgument(
41                     'Must specify an rspec version option. geni_rspec_version cannot be null')
42         valid_creds = self.api.auth.checkCredentialsSpeaksFor(
43             creds, 'listnodes', urns,
44             check_sliver_callback=self.api.driver.check_sliver_credentials,
45             options=options)
46
47         # get hrn of the original caller
48         origin_hrn = options.get('origin_hrn', None)
49         if not origin_hrn:
50             origin_hrn = Credential(
51                 cred=valid_creds[0]).get_gid_caller().get_hrn()
52         desc = self.api.manager.Describe(self.api, creds, urns, options)
53
54         # filter rspec through sfatables
55         if self.api.interface in ['aggregate']:
56             chain_name = 'OUTGOING'
57         elif self.api.interface in ['slicemgr']:
58             chain_name = 'FORWARD-OUTGOING'
59         self.api.logger.debug(
60             "ListResources: sfatables on chain %s" % chain_name)
61         desc['geni_rspec'] = run_sfatables(
62             chain_name, '', origin_hrn, desc['geni_rspec'])
63
64         if 'geni_compressed' in options and options['geni_compressed'] == True:
65             desc['geni_rspec'] = zlib.compress(
66                 desc['geni_rspec']).encode('base64')
67
68         return desc