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 PasswordAuth
7 class GetNodes(Method):
9 Return an array of structs containing details about nodes. If
10 node_id_or_hostname_list is specified, only the specified nodes
13 Some fields may only be viewed by admins.
16 roles = ['admin', 'pi', 'user', 'tech']
20 [Mixed(Node.fields['node_id'],
21 Node.fields['hostname'])],
24 returns = [Node.fields]
26 def call(self, auth, node_id_or_hostname_list = None):
27 # Authenticated function
28 assert self.caller is not None
30 valid_fields = Node.fields.keys()
32 # Remove admin only fields
33 if 'admin' not in self.caller['roles']:
34 for key in ['boot_nonce', 'key', 'session', 'root_person_ids']:
35 if key in valid_fields:
36 valid_fields.remove(key)
38 # Get node information
39 nodes = Nodes(self.api, node_id_or_hostname_list).values()
41 # Turn each node into a real dict
42 nodes = [dict(node) for node in nodes]