implement as wrappers around new functions
[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 PasswordAuth
6
7 class AdmGetSiteNodes(Method):
8     """
9     Deprecated. See GetSites.
10
11     Return a dictionary containing a list of node_ids for each of the
12     sites specified.
13
14     Admins may retrieve details about all nodes on a site by not specifying
15     site_id_or_name or by specifying an empty list. Users and
16     techs may only retrieve details about themselves. PIs may retrieve
17     details about themselves and others at their sites.
18     """
19
20     status = "deprecated"
21
22     roles = ['admin', 'pi', 'user', 'tech']
23
24     accepts = [
25         PasswordAuth(),
26         [Mixed(Site.fields['site_id'],
27                Site.fields['name'])],
28         ]
29
30     returns = { Site.fields['site_id']: Site.fields['node_ids'] }
31
32     def call(self, auth, site_id_or_name_list = None):
33         # Get site information
34         sites = Sites(self.api, site_id_or_name_list).values()  
35         if not sites:
36             raise PLCInvalidArgument, "No such site"
37         
38         # Convert to {str(site_id): [node_id]}
39         site_nodes = {}
40         for site in sites:
41             site_nodes[str(site['site_id'])] = site['node_ids']
42                 
43         return site_nodes