b366c80cc0e59a4ab4c980cb81d5ed0ce92e0ac1
[plcapi.git] / PLC / Methods / AdmGetSiteNodes.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Sites import Site, Sites
5 from PLC.Auth import Auth
6
7 class AdmGetSiteNodes(Method):
8     """
9     Deprecated. See GetSites.
10
11     Return a struct containing an array of node_ids for each of the
12     sites specified. Note that the keys of the struct are strings, not
13     integers, because of XML-RPC marshalling limitations.
14
15     Admins may retrieve details about all nodes on a site by not specifying
16     site_id_or_name or by specifying an empty list. Users and
17     techs may only retrieve details about themselves. PIs may retrieve
18     details about themselves and others at their sites.
19     """
20
21     status = "deprecated"
22
23     roles = ['admin', 'pi', 'user', 'tech']
24
25     accepts = [
26         Auth(),
27         [Mixed(Site.fields['site_id'],
28                Site.fields['name'])],
29         ]
30
31     returns = dict
32
33     def call(self, auth, site_id_or_name_list = None):
34         # Get site information
35         sites = Sites(self.api, site_id_or_name_list)   
36         if not sites:
37             raise PLCInvalidArgument, "No such site"
38         
39         # Convert to {str(site_id): [node_id]}
40         site_nodes = {}
41         for site in sites:
42             site_nodes[str(site['site_id'])] = site['node_ids']
43                 
44         return site_nodes