468783c7e6d0dbc1e3fd999ef8f45929de27167d
[sfa.git] / sfa / methods / get_resources.py
1 ### $Id$
2 ### $URL$
3
4 from sfa.util.faults import *
5 from sfa.util.method import Method
6 from sfa.util.parameter import Parameter, Mixed
7 from sfa.trust.auth import Auth
8 from sfa.util.config import Config
9 from sfa.plc.nodes import Nodes
10 # RSpecManager_pl is not used. This is just to resolve issues with the dynamic __import__ that comes later.
11 import sfa.rspecs.aggregates.rspec_manager_pl
12
13 class get_resources(Method):
14     """
15     Get an resource specification (rspec). The rspec may describe the resources
16     available at an authority or the resources being used by a slice.      
17
18     @param cred credential string specifying the rights of the caller
19     @param hrn human readable name of the slice we are interesed in or None 
20            for an authority.  
21     """
22
23     interfaces = ['aggregate', 'slicemgr']
24     
25     accepts = [
26         Parameter(str, "Credential string"),
27         Mixed(Parameter(str, "Human readable name (hrn)"),
28               Parameter(None, "hrn not specified"))
29         ]
30
31     returns = Parameter(str, "String representatin of an rspec")
32     
33     def call(self, cred, hrn=None):
34         sfa_aggregate_type = Config().get_aggregate_rspec_type()
35
36         self.api.auth.check(cred, 'listnodes')
37         if (sfa_aggregate_type == 'pl'):
38             nodes = Nodes(self.api)
39             if hrn:
40                 rspec = nodes.get_rspec(hrn)
41             else:
42                 nodes.refresh()
43                 rspec = nodes['rspec']
44         else:
45             # To clean up after July 21 - SB    
46             rspec_manager = __import__("sfa.rspecs.aggregates.rspec_manager_"+sfa_aggregate_type, fromlist = ["sfa.rspecs.aggregates"])
47             rspec = rspec_manager.get_rspec(self.api, hrn)
48         
49         return rspec