cb9847a90e322aa51d1633c945e243b949687b97
[plcapi.git] / PLC / Methods / GetSites.py
1 import os
2
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Auth import PasswordAuth
6 from PLC.Sites import Site, Sites
7
8 class GetSites(Method):
9     """
10     Return an array of structs containing details about all sites. If
11     site_id_list is specified, only the specified sites will be
12     queried.
13
14     If return_fields is specified, only the specified fields will be
15     returned, if set. Otherwise, the default set of fields returned is:
16
17     """
18
19     roles = ['admin', 'pi', 'user', 'tech']
20
21     accepts = [
22         PasswordAuth(),
23         [Mixed(Site.fields['site_id'],
24                Site.fields['login_base'])]
25         ]
26
27     returns = [Site.fields]
28
29     event_type = 'Get'
30     object_type = 'Site'
31         
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.fields.keys())
36
37     def call(self, auth, site_id_or_login_base_list = None):
38         
39         # Get site information
40         sites = Sites(self.api, site_id_or_login_base_list)
41
42         # turn each site into a real dict.
43         sites = [dict(site) for site in sites.values()]
44         
45         return sites