1248431661a9ac88056e1c5b5b64794b65c19f40
[sfa.git] / geni / methods / get_resources.py
1 from geni.util.faults import *
2 from geni.util.excep import *
3 from geni.util.method import Method
4 from geni.util.parameter import Parameter, Mixed
5 from geni.util.auth import Auth
6 from geni.util.nodes import Nodes
7
8 class get_resources(Method):
9     """
10     Get an resource specification (rspec). The rspec may describe the resources
11     available at an authority or the resources being used by a slice.      
12
13     @param cred credential string specifying the rights of the caller
14     @param hrn human readable name of the slice we are interesed in or None 
15            for an authority.  
16     """
17
18     interfaces = ['aggregate', 'slicemgr']
19     
20     accepts = [
21         Parameter(str, "Credential string"),
22         Mixed(Parameter(str, "Human readable name (hrn)"),
23               Parameter(None, "hrn not specified"))
24         ]
25
26     returns = Parameter(str, "String representatin of an rspec")
27     
28     def call(self, cred, hrn=None):
29         
30         self.api.auth.check(cred, 'listnodes')
31         nodes = Nodes(self.api)
32         if hrn:
33             rspec = nodes.get_rspec(hrn)
34         else:
35             nodes.refresh()
36             rspec = nodes['rspec']
37         
38         return rspec