(most) all functions now take SessionAuth in addition to PasswordAuth
[plcapi.git] / PLC / Methods / GetNodes.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Nodes import Node, Nodes
5 from PLC.Auth import Auth
6
7 class GetNodes(Method):
8     """
9     Return an array of structs containing details about nodes. If
10     node_id_or_hostname_list is specified, only the specified nodes
11     will be queried.
12
13     Some fields may only be viewed by admins.
14     """
15
16     roles = ['admin', 'pi', 'user', 'tech']
17
18     accepts = [
19         Auth(),
20         [Mixed(Node.fields['node_id'],
21                Node.fields['hostname'])],
22         ]
23
24     returns = [Node.fields]
25
26     def call(self, auth, node_id_or_hostname_list = None):
27         # Get node information
28         nodes = Nodes(self.api, node_id_or_hostname_list).values()
29
30         # Remove admin only fields
31         if 'admin' not in self.caller['roles']:
32             for node in nodes:
33                 for field in ['boot_nonce', 'key', 'session', 'root_person_ids']:
34                     if field in node:
35                         del node[field]
36
37         return nodes