3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Sites import Site, Sites
7 from PLC.Nodes import Node, Nodes
8 from PLC.Auth import PasswordAuth
10 class AdmGetSiteNodes(Method):
12 Return a dictionary containing a list of node_ids for the sites specified.
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.
21 roles = ['admin', 'pi', 'user', 'tech']
25 [Mixed(Site.fields['site_id'],
26 Site.fields['name'])],
27 Parameter([str], 'List of fields to return')
30 returns={Site.fields['site_id']: [Site.all_fields['node_ids']]}
32 def __init__(self, *args, **kwds):
33 Method.__init__(self, *args, **kwds)
34 # Update documentation with list of default fields returned
35 self.__doc__ += os.linesep.join(Site.default_fields.keys())
37 def call(self, auth, site_id_or_name_list = None):
38 # Authenticated function
39 assert self.caller is not None
41 #convert site_id_or_name_list to 'None' if is [] (empty list)
42 if site_id_or_name_list is not None and site_id_or_name_list == []:
43 site_id_or_name_list = None
45 # Get site information
46 sites = Sites(self.api, site_id_or_name_list, ['node_ids']).values()
48 # make sure sites are found
50 raise PLCInvalidArgument, "No such site"
51 elif site_id_or_name_list is None:
53 elif not len(sites) == len(site_id_or_name_list):
54 raise PLCInvalidArgument, "at least one site_id is invalid"
56 #Convert list of sites dictionaries into a dictionary of sites -> sites:[node_ids]
59 #filter out deleted nodes
60 nodes = Nodes(self.api, site['node_ids'])
61 #creat valid node list dictionary
62 site_nodes[str(site['site_id'])] = nodes.keys()