3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Nodes import Node, Nodes
7 from PLC.Auth import PasswordAuth
9 class GetNodes(Method):
11 Return an array of dictionaries containing details about the
14 If return_fields is specified, only the specified fields will be
15 returned. Only admins may retrieve certain fields. Otherwise, the
16 default set of fields returned is:
20 roles = ['admin', 'pi', 'user', 'tech']
24 [Mixed(Node.fields['node_id'],
25 Node.fields['hostname'])],
28 returns = [Node.fields]
30 def __init__(self, *args, **kwds):
31 Method.__init__(self, *args, **kwds)
32 # Update documentation with list of default fields returned
33 self.__doc__ += os.linesep.join(Node.fields.keys())
35 def call(self, auth, node_id_or_hostname_list = None):
36 # Authenticated function
37 assert self.caller is not None
39 valid_fields = Node.fields.keys()
41 # Remove admin only fields
42 if 'admin' not in self.caller['roles']:
43 for key in ['boot_nonce', 'key', 'session', 'root_person_ids']:
44 valid_fields.remove(key)
46 # Get node information
47 nodes = Nodes(self.api, node_id_or_hostname_list).values()
49 # turn each node into a real dict.
50 nodes = [dict(node.items()) for node in nodes]