Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[plcapi.git] / trunk / PLC / Methods / AdmGetSitePowerControlUnits.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.PCUs import PCU, PCUs
5 from PLC.Sites import Site, Sites
6 from PLC.Auth import Auth
7
8 class AdmGetSitePowerControlUnits(Method):
9     """
10     Deprecated. Functionality can be implemented with GetSites and GetPCUs.
11     """
12
13     status = "deprecated"
14
15     roles = ['admin', 'pi', 'tech']
16
17     accepts = [
18         Auth(),
19         Mixed(Site.fields['site_id'],
20               Site.fields['login_base'])
21         ]
22
23     returns = [PCU.fields]
24
25     def call(self, auth, site_id_or_login_base):
26         sites = Sites(self.api, [site_id_or_login_base])
27         if not sites:
28             raise PLCInvalidArgument, "No such site"
29         site = sites[0]
30
31         if 'admin' not in self.caller['roles']:
32             if site['site_id'] not in self.caller['site_ids']:
33                 raise PLCPermissionDenied, "Not allowed to view the PCUs at that site"
34
35         return PCUs(self.api, site['pcu_ids'])