Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[plcapi.git] / trunk / PLC / Methods / AdmGetSitePIs.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.Persons import Person, Persons
6 from PLC.Auth import Auth
7
8 class AdmGetSitePIs(Method):
9     """
10     Deprecated. Functionality can be implemented with GetSites and
11     GetPersons.
12
13     Return a list of person_ids of the PIs for the site specified.
14     """
15
16     status = "deprecated"
17
18     roles = ['admin']
19
20     accepts = [
21         Auth(),
22         Mixed(Site.fields['site_id'],
23               Site.fields['login_base'])
24         ]
25
26     returns = Site.fields['person_ids']
27
28     def call(self, auth, site_id_or_login_base):
29         # Authenticated function
30         assert self.caller is not None
31
32         # Get site information
33         sites = Sites(self.api, [site_id_or_login_base])
34         if not sites:
35             raise PLCInvalidArgument, "No such site"
36
37         site = sites[0]
38
39         persons = Persons(self.api, site['person_ids'])
40
41         has_pi_role = lambda person: 'pi' in person['roles']
42         pis = filter(has_pi_role, persons)
43
44         return [pi['person_id'] for pi in pis]